8/27/2021 Newton School
Newton School PL
back
Save and Run Hidden Test
Newton's Grand Contest 2021 - Hail Hydra (Public Contest: August 2021) by Pranav 01:42:25
Run Cases
Lad
Hail Hydra (Public Contest: August 2021)
standard input/output: 2s/128000 kB
After freeing himself from the clutches of HYDRA, Bucky is now finally a free man. And now he decided that he must destroy HYDRA so that no one else has to suffer. To
destroy HYDRA, he must first find the secret passcode to enter their safehouse.
Bucky has already managed to get hold of a secret list of patterns, and the threshold N, a positive integer. The passcode is a string for which the summation of the number of
occurrences of all the patterns in the string is greater than the threshold N. If there are multiple such strings, the answer is the lexicographically smallest string.
Formally, you are given an integer N and a list of patterns of size K, where each pattern is a string consisting of lowercase English alphabets. Let's call these strings P1, P2, P3 ...
PK. Also, define Occurrence(S, P) where S and P are two strings, as the number of substrings of S equal to P.
You need to find the smallest string S, such that N ≤ ∑ Occurrence(S, Pi). If there are multiple such strings, output the lexicographically smallest string S.
Here the patterns need not be unique so that a pattern might appear multiple times, and the summation would count separately for each pattern.
Input
The first line contains two integers N and K.
Then K lines follow, where the ith line contains the ith pattern, Pi.
Constraints:
1 ≤ N ≤ 100
1 ≤ ∑|Pi| ≤ 1000
Output
Output the string of the smallest length, satisfying the constraints as mentioned above.
If there are multiple such strings, output the lexicographically smallest one.
Example
Sample Input:
5 6
b
bb
bb
bb
a
aa
Sample Output:
bb
Code Reset Python (3.8.1) Custom Input
1
1 # Your code here
STDOUT STDERR COMPILE OUTPUT MESSAGE
1
Test Cases Previous Submissions
Test case 0 Hidden test case Status Test Cases Passed
Test case 1
Help
Test case 2
https://my.newtonschool.co/playground/code/ont3ps6hkjs1/ 1/2
8/27/2021 Newton School
Test case 3
Test case 4
Test case 5
Test case 6
Test case 7
Test case 8
Test case 9
Test case 10
Test case 11
Test case 12
Test case 13
Test case 14
Test case 15
Test case 16
Test case 17
Test case 18
© 2021 Incanus Technologies Pvt Ltd
For any queries, you can reach us at Follow us on
All rights reserved. (Terms)
[email protected]https://my.newtonschool.co/playground/code/ont3ps6hkjs1/ 2/2