QOJ.ac

QOJ

时间限制: 0.5 s 内存限制: 256 MB 总分: 100

#464. Prefix Function / KMP

统计

Given a string $S$, for each $i \in [1, n]$, define $\pi_i$ as the length of the longest border of $S[:i]$. Compute the array $\pi$.

Input

The input consists of a single line containing a string $S$ consisting only of lowercase English letters.

Output

Output a single line containing $|S|$ integers, representing $\pi_1, \pi_2, \dots, \pi_{|S|}$.

Constraints

For all test cases, $1 \leq |S| \leq 2 \cdot 10^6$.

  • Subtask 1 (30 points): $|S| \leq 10^5$
  • Subtask 2 (70 points): No additional constraints

Examples

Input 1

abcababcababcbacbabc

Output 1

0 0 0 1 2 1 2 3 4 5 6 7 8 0 1 0 0 1 2 3

Input 2

See provided files.

Output 2

See provided files.

Input 3

See provided files.

Output 3

See provided files.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.