SHERLOCK AND SECRET CODE

3.2

51 votes
Easy-Medium
Problem

Sherlock, the famous private consulting detective is handling a case where he has got
a diary of villain where all his secrets are written in the form of strings.
There is one main string of length L and N other mini strings of equal length K<=L.
Sherlock knows this fact that villain derives a code in numerical form by using these mini strings and main string.

Sherlock also knows that villain takes the mini strings one by one and find its occurences in the main string. He do so for all the mini strings and takes all the occurences(i.e. index in main string from which particular mini string starts) and combines them in sorted order (with space) and hence derives the secret code.
Help Sherlock in finding the secret code.

INPUT:-
The first line contains the main string (you can calculate its length as L and second line contains N denoting the no. of mini strings. The next N lines contains mini strings of equal length K (you can calculate the length of any mini strings and for all mini strings it will be same)

Note:- All the characters in the strings are lowercase characters from a-z and ignore those mini strings that do not occur in main string and if all mini string do not occur then simply print "-1" without quotes. INDEXING IS 0 BASED.

OUTPUT:-
The only line contains the sorted combined form of the code derived. (See the sample explanation).You also have to print informations regarding repeated mini strings.

CONSTRAINTS:-
L<=10^5
K<=10
N<=1000

Sample Input
sampleinputoutput
5
samp
inpt
inpu
outp
utop
Sample Output
0 6 11
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the given case the main string is "sampleinputoutput".
and given N as 5, means no of mini strings are 5 and all are of length 4, now
mini string "samp" occurs at 0 in main string
mini string "inpt" do not occur at any place in main string so ignore it
mini string "inpu" occur at 6
mini string "outp" occur at 11
mini string "utop" do not occur at any position so ignore it
so number so found are 0,6,11 sorting and combining we get 0 6 11 which is the required answer

Contributers:
Editor Image

?