This page is still under construction.

Parts of this page are still being built. What you see may change.

Longest Substring

Time limit5sMemory limit1024 MB

Summary
For each k from 1 to n, find the longest substring that occurs exactly k times and allows the most non-overlapping occurrences, then print the lengths.
Level

Hard8 of 10

Topics
String matching, Tree
Solved
No attempts yet

Problem

For a string SS of length n≥1n ≥ 1 and a positive integer kk (1≤k≤n1 ≤ k ≤ n), a non-empty substring of SS is called a kk-substring if the substring appears exactly kk times. These kk occurrences may overlap. For example, if S=S = "ababa", the kk-substrings of SS for every k=1,…,5k = 1, \dots , 5 are as follows.

  • There are four 11-substrings in SS: "abab", "ababa", "bab", and "baba", because each appears exactly once. "aba" is not a 11-substring because it appears twice.
  • There are four 22-substrings: "ab", "aba", "b", and "ba". "ab" appears exactly twice without overlapping. The two occurrences of "aba" overlap at the character "a", and it does not appear three times.
  • There is only one 33-substring, "a".
  • There are no 44-substrings or 55-substrings.

For a kk-substring TT of SS, let d(T)d(T) be the maximum number of disjoint occurrences of TT in SS. For example, "ab" can be selected twice without overlapping, so d("ab")=2d("ab") = 2. For the 22-substring "aba", d("aba")=1d("aba") = 1, because two of its occurrences cannot be chosen without overlapping. For the 33-substring "a", d("a")=3d("a") = 3.

Let f(k)f(k) be the length of the longest kk-substring TT among those with the largest d(T)d(T), for 1≤k≤n1 ≤ k ≤ n. For S=S = "ababa", f(1)=5f(1) = 5, f(2)=2f(2) = 2, f(3)=1f(3) = 1, and f(4)=f(5)=0f(4) = f(5) = 0.

Input

The input is a single line containing the string SS of length nn (1≤n≤50 0001 ≤ n ≤ 50\,000), consisting of lowercase English letters.

Output

Print exactly one line with nn nonnegative integers separated by spaces: f(1)f(1) f(2)f(2) …\dots f(n)f(n). If there is no kk-substring for some kk, then f(k)f(k) is 00.

Examples2

  1. Example 1

    Input
    ababa
    
    Expected output
    5 2 1 0 0
    
  2. Example 2

    Input
    aaaaaaaa
    
    Expected output
    8 7 6 5 4 3 2 1