Problems > All the Borders

All the Borders

Difficulty: 1500 6000 ms 128 MB

strings kmp

A border of S is a string that is both a proper prefix and a proper suffix. Print all border lengths in increasing order (or 0 if there are none).

Input: one line with the string S.

Output: the border lengths ascending, or 0.

Constraints:

  • 1 ≤ |S| ≤ 106
  • lowercase letters

Sample Tests

Input 1
abacaba
Output 1
1 3
Input 2
abc
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.