- Time limit: 1.00 s
- Memory limit: 512 MB
We consider a string of characters, indexed . Your task is to calculate all values of the following functions:
- denotes the maximum length of a substring that begins at position and is a prefix of the string. In addition, .
- denotes the maximum length of a substring that ends at position , is a prefix of the string, and whose length is at most .
Note that the function is used in the Z-algorithm, and the function is used in the KMP algorithm.
Input
The only input line has a string of length . Each character is between a–z.
Output
Print two lines: first the values of the function, and then the values of the function.
Constraints
Example
Input:
abaabca
Output:
0 0 1 2 0 0 1 0 0 1 1 2 0 1