eolymp
bolt
Try our new interface for solving problems
Problems

Chorus

Chorus

You suddenly remember \textbf{part of a chorus} of a song. You wonder which song has it in your list of \textbf{n} song lyrics. \InputFile There are two parts in the input. The first line of the first part of the input is an integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{15}), the number of songs in your database. Then, you will be given \textbf{n} strings in \textbf{n} lines that only contain lowercase alphabets \[\textbf{a}..\textbf{z}\]. Each string is a full lyric of a song without spaces, commas, periods, and any other non lowercase alphabet characters. We have simplified this input format to avoid unnecessary errors. We are using real songs in the test data, so you can expect that the length of the longest song in the list is less than \textbf{1500} characters. Then, you will be given the second part of the input which starts with another integer \textbf{q} (\textbf{1} ≤ \textbf{q} ≤ \textbf{20}) that denotes the number of queries. Then, you will be given \textbf{q} short strings in \textbf{q} lines that only contain lowercase alphabets. Each query string is part of the song lyric, but not necessarily from the chorus. Here we define chorus of a song as "\textbf{the longest substring in that song lyric that appears more than once}". \OutputFile For each query string, output a list of song indices that have that query string in its chorus in one line. Here we define that a query string is found in a chorus if it is a substring of the chorus. If there are more than one song found, separate their indices by a single space. \textit{Note:} There is no space at the end of the output and song number starts from \textbf{0}. If there is no song with such chorus, output "\textbf{-1}" instead (without the quote). We guarantee that the output is unique. \Note To check if your understanding of "chorus" is correct, here are the chorus (without the quotes) of the four songs in the sample input according to our definition of chorus. Song 0, "thisisthechorus" Song 1, "chorusishere" Song 2, "chorus" Song 3, "againitwasdestinysgameforwhenlovefinallycameonirushedinlineonlytofindthatyouweregone" Song 0, 1, and 2 are dummy songs to help you understand this problem. Song 3 is a real song titled "Beautiful Girl", sung by Filipino "Jose Mari Chan". This is the song that inspired this problem.
Time limit 1 second
Memory limit 64 MiB
Input example #1
4
thisisthefirstverseofadummysongthisisthechorusthisisthesecondversethisisthechorus
blablablichorusishereblibliblachorusisherechorusishere
chorusachorusbchoruscchorus
beautifulgirlwhereveryouareiknewwhenisawyouyouhadopenedthedooriknewthatidloveagainafteralonglongwhileidloveagainyousaidhelloanditurnedtogobutsomethinginyoureyesleftmyheartbeatingsoijustknewthatidloveagainafteralonglongwhileidloveagainitwasdestinysgameforwhenlovefinallycameonirushedinlineonlytofindthatyouweregonewheneveryouareifearthatimighthavelostyouforeverlikeasonginthenightnowthativelovedagainafteralonglongwhileivelovedagainitwasdestinysgameforwhenlovefinallycameonirushedinlineonlytofindthatyouweregonebeautifulgirlillsearchonforyoutilallofyourlovelinessinmyarmscometrueyouvemademeloveagainafteralonglongwhileinloveagainandimgladthatitsyouhmmbeautifulgirl
7
first
chorus  
is
here
beautifulgirl
itwasdestinysgame
itwasdestinysgameyouweregone
Output example #1
-1
0 1 2
0 1
1
-1
3
-1