#abc287e. [abc287_e]Karuta

[abc287_e]Karuta

Problem Statement

You are given NN strings consisting of lowercase English letters. Let SiS_i be the ii-th (i=1,2,dots,N)(i = 1, 2, \\dots, N) of them.

For two strings xx and yy, mathrmLCP(x,y)\\mathrm{LCP}(x, y) is defined to be the maximum integer nn that satisfies all of the following conditions:

  • The lengths of xx and yy are both at least nn.
  • For all integers ii between 11 and nn, inclusive, the ii-th character of xx and that of yy are equal.

Find the following value for all i=1,2,dots,Ni = 1, 2, \\dots, N:

  • $\\displaystyle \\max_{i \\neq j} \\mathrm{LCP}(S_i, S_j)$

Constraints

  • 2leqNleq5times1052 \\leq N \\leq 5 \\times 10^5
  • NN is an integer.
  • SiS_i is a string of length at least 11 consisting of lowercase English letters (i=1,2,dots,N)(i = 1, 2, \\dots, N).
  • The sum of lengths of SiS_i is at most 5times1055 \\times 10^5.

Input

The input is given from Standard Input in the following format:

NN S1S_1 S2S_2 vdots\\vdots SNS_N

Output

Print NN lines. The ii-th (i=1,2,dots,N)(i = 1, 2, \\dots, N) line should contain $\\displaystyle \\max_{i \\neq j} \\mathrm{LCP}(S_i, S_j)$.


Sample Input 1

3
abc
abb
aac

Sample Output 1

2
2
1

$\\mathrm{LCP}(S_1, S_2) = 2, \\mathrm{LCP}(S_1, S_3) = 1$, and mathrmLCP(S2,S3)=1\\mathrm{LCP}(S_2, S_3) = 1.


Sample Input 2

11
abracadabra
bracadabra
racadabra
acadabra
cadabra
adabra
dabra
abra
bra
ra
a

Sample Output 2

4
3
2
1
0
1
0
4
3
2
1