6874.Finding Borders

Time Limit: 1s Memory Limit: 512MB

A border of a string is a prefix that is also a suffix of the string but not the whole string. For example, the borders of abcababcab are ab and abcab .

Your task is to find all border lengths of a given string.

Input Format(From the terminal/stdin)

The only input line has a string of length $n$ consisting of characters a–z.

  • $1 \le n \le 10^6$

Output Format(To the terminal/stdout)

Print all border lengths of the string in increasing order.

Sample Input

Copy
abcababcab
          \n

Sample Output

Copy
2 5
 · \n
Source: CSES, String Algorithms, 1732

Submit

请先 登录

© 2025 FAQs