407703: GYM102878 E Eigen Substring

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Eigen Substringtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

For any string $$$s$$$, we define the substring $$$s\left[l..r\right]$$$ an eigen substring of $$$s$$$ if and only if $$$s\left[l..r\right]$$$ only appears once in $$$s$$$.

You are given a string $$$s$$$. Please calculate the length of the shortest eigen substring for each prefix of $$$s$$$.

The notation $$$s\left[l..r\right]$$$ represents the substring of $$$s$$$ that spans from the $$$l$$$-th character in $$$s$$$ to the $$$r$$$-th character in $$$s$$$, inclusive.

Input

The input contains two lines.

The first line contains an integer $$$n$$$ $$$\left(1 \le n \le 10^6\right)$$$ which is the length of string $$$s$$$.

The second line contains the string $$$s$$$. It's guaranteed that all characters in $$$s$$$ are lowercase English letters.

Output

Your output should contain $$$n$$$ lines. The $$$i$$$-th line of your output should contain one integer which denotes the length of the shortest eigen substring of $$$s\left[1..i\right]$$$.

ExampleInput
5
ababb
Output
1
1
1
2
2
Note

For the example test case:

  • The shortest eigen substring of $$$s\left[1..1\right] = \mathrm{a}$$$ is a;
  • The shortest eigen substrings of $$$s\left[1..2\right] = \mathrm{ab}$$$ are a and b;
  • The shortest eigen substring of $$$s\left[1..3\right] = \mathrm{aba}$$$ is b;
  • The shortest eigen substring of $$$s\left[1..4\right] = \mathrm{abab}$$$ is ba;
  • The shortest eigen substrings of $$$s\left[1..5\right] = \mathrm{ababb}$$$ are ba and bb.

加入题单

算法标签: