All Occurrences of a Pattern
You are given a text s and a pattern p, both strings of lowercase English letters.
Find every starting position in s where p occurs. Occurrences may overlap: if p starts at
position i, the next occurrence may start anywhere at or after position i + 1, not only after
the previous occurrence ends.
Input
The first line contains the text s (1 ≤ |s| ≤ 10^6).
The second line contains the pattern p (1 ≤ |p| ≤ 10^6).
Both strings consist only of lowercase English letters.
Output
Print a single integer k, the number of occurrences of p in s.
On the next line print the k starting positions where p occurs in s, in increasing order,
1-based, separated by single spaces. If k = 0, print an empty line.
Notes
In the first example, p = "ab" occurs in s = "ababab" starting at positions 1, 3 and 5 —
every occurrence of p that fits, including ones that share characters with the previous one.
In the second example, p = "aa" occurs in s = "aaaa" at positions 1, 2 and 3: the occurrences
starting at 1 and 2 overlap in the shared middle a.