영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
시간 제한 1초 · 메모리 제한 512 MB
Problem
We consider a string of n characters, indexed 1,2,…,n. Your task is to calculate all values of the following functions:
- z(i) denotes the maximum length of a substring that begins at position i and is a prefix of the string. In addition, z(1)=0.
- π(i) denotes the maximum length of a substring that ends at position i, is a prefix of the string, and whose length is at most i-1.
Note that the function z 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 n. Each character is between a–z.
Output
Print two lines: first the values of the z function, and then the values of the π function.
Constraints
- 1 ≤ n ≤ 10^6
예제
예제 1
abaabca
0 0 1 2 0 0 1 0 0 1 1 2 0 1