#ABC213F. [ABC213F] Common Prefixes

[ABC213F] Common Prefixes

Score : 500500 points

Problem Statement

Let the similarity f(X,Y)f(X,Y) between two strings XX and YY be the length of their longest common prefix. For example, the similarity between abc and axbc is 11, and the similarity between aaa and aaaa is 33.

You are given a string SS of length NN. Let SiS_i be the suffix of SS beginning with the ii-th character of SS. For each k=1,,Nk=1,\ldots,N, find f(Sk,S1)+f(Sk,S2)++f(Sk,SN)f(S_k,S_1)+f(S_k,S_2)+\ldots+f(S_k,S_N).

Constraints

  • 1N1061 \leq N \leq 10^6
  • SS is a string of length NN consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

NN

SS

Output

Print NN lines.

The ii-th line should contain the answer for k=ik=i.

3
abb
3
3
2

S1S_1 is abb, S2S_2 is bb, and S3S_3 is b.

  • For k=1k=1: f(S1,S1)+f(S1,S2)+f(S1,S3)=3+0+0=3f(S_1,S_1)+f(S_1,S_2)+f(S_1,S_3)=3+0+0=3.
  • For k=2k=2: f(S2,S1)+f(S2,S2)+f(S2,S3)=0+2+1=3f(S_2,S_1)+f(S_2,S_2)+f(S_2,S_3)=0+2+1=3.
  • For k=3k=3: f(S3,S1)+f(S3,S2)+f(S3,S3)=0+1+1=2f(S_3,S_1)+f(S_3,S_2)+f(S_3,S_3)=0+1+1=2.
11
mississippi
11
16
14
12
13
11
9
7
4
3
4