Z-Algorithm String


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
C++, Python

Problem Description

Given a string S and a pattern string P, all strings contain only uppercase and lowercase English letters and Arabic numerals.

The pattern string P appears multiple times as a substring in string S.

Find all starting indices of occurrences of pattern P in string S.

Input Format
Line 1: Integer N, the length of string P.
Line 2: String P.
Line 3: Integer M, the length of string S.
Line 4: String S.

Output Format
A single line containing all starting indices (0-based) of occurrences of P in S, separated by spaces.

Data Range
1 ≤ N ≤ 105
1 ≤ M ≤ 106

Input Sample:

3
aba
5
ababa

Output Sample:

0 2

Comments

There are no comments at the moment.