Sai Bhaskar and Coordinator
All submissions for this problem are available.Sai Bhaskar wants to go for a hackathon. He needs to take permission from his class coordinator for leave. As his coordinator is interested in String problems, his coordinator gave him a problem to solve. Sai Bhaskar can leave if he could solve the problem. Though he was a top coder, he was busy with some other things. So he needs your help to solve the problem. he asks you for help because you are also one of the top coders. The problem is you will be given a string $S$ of length $N$. And $Q$ strings of length $3$. you need to find the string from the $Q$ strings which can be made first from the strings $S$. we can make a string in the following way: For $1<=i<=N$ If $k$th bock of any $Q$j th string can be made from S[i] then fill that kth block of $Q$j th string with $S[i]$. A kth block can be filled if $(k-1)$th is filled. Note: If anyone of the Qjth string cannot be made with given string S then print maddjs. ### Constraints - $1 \leq N \leq 10^5$ - $1 \leq Q \leq 1000$ - $S$ consists of lower case letters. - all $Q$ string consists of lower case letters. - each $Q$ ith string length will be 3. ### Input - First line consists of N and Q. - Second-line consists of String S. - Next, Q lines consist of strings of length 3. ### Output - Print the string which can be made first if possible else print maddjs. ### Sample Input 10 4 abhjilhick hck kch bjh jih ### Sample output bjh ### Explanation $bjh$ can be made first than $hck, jih$ Thougth $bjh$ and $jih$ can made at same time we print $bjh$ because $bjh$ occurs first in list than $jih$. So, we need to print $bjh$.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.