#ABC287E. [ABC287E] Karuta

[ABC287E] Karuta

Score : 500500 points

Problem Statement

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

For two strings xx and yy, LCP(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,,Ni = 1, 2, \dots, N:

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

Constraints

  • 2N5×1052 \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,,N)(i = 1, 2, \dots, N).
  • The sum of lengths of SiS_i is at most 5×1055 \times 10^5.

Input

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

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

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

3
abc
abb
aac
2
2
1

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

11
abracadabra
bracadabra
racadabra
acadabra
cadabra
adabra
dabra
abra
bra
ra
a
4
3
2
1
0
1
0
4
3
2
1