Z-Function String Matching
Implement the Z-function to find all occurrences of a pattern within a text.
Input format
The first line contains the text. The second line contains the pattern (lowercase).
Output format
Print 0-based occurrence indices space-separated, or -1 if none.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
jvtpvzzkuelaqduelaqdwra uelaqdExpected output
8 14Example 2
Input
hnkrwawz hnkrwaExpected output
0