#abc377g. G - Edit to Match

G - Edit to Match

Score : 575575 points

问题陈述

你给定了 NN 个字符串 S1,S2,,SNS_1, S_2, \ldots, S_N。每个字符串由小写英文字母组成。

对于每个 k=1,2,,Nk=1, 2, \ldots, N,解决以下问题。

T=SkT=S_k 并考虑执行以下两种类型的操作任意次数,以任意顺序:

  • 支付 11 的成本删除 TT 的最后一个字符。当 TT 不为空时,此操作是可能的。
  • 支付 11 的成本在 TT 的末尾添加任何小写英文字母。

找出使 TT 要么变为空字符串,要么与 S1,S2,,Sk1S_1, S_2, \ldots, S_{k-1} 中的一个匹配所需的最小总成本。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given NN strings S1,S2,,SNS_1,S_2,\ldots,S_N. Each string consists of lowercase English letters.

For each k=1,2,,Nk=1,2,\ldots,N, solve the following problem.

Let T=SkT=S_k and consider performing the following two types of operations any number of times in any order:

  • Pay a cost of 11 to delete the last character of TT. This operation is possible when TT is not empty.
  • Pay a cost of 11 to add any lowercase English letter to the end of TT.

Find the minimum total cost needed to make TT either empty or match one of S1,S2,,Sk1S_1,S_2,\ldots,S_{k-1}.

Constraints

  • 1N2×1051\le N\le 2\times 10^5
  • Each SiS_i is a string of length at least 11 consisting of lowercase English letters.
  • i=1NSi2×105\displaystyle \sum_{i=1}^N |S_i|\le 2\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 line (1iN)(1\le i\le N) should contain the answer for k=ik=i.

Sample Input 1

3
snuke
snuki
snuuk

Sample Output 1

5
2
4

For k=1k=1, you can make TT empty by performing the delete operation five times.

For k=2k=2, you can make TT match S1S_1 by deleting the last character and then adding e to the end.

For k=3k=3, you can make TT match S2S_2 by deleting the last character twice, then adding k to the end, and finally adding i to the end.

Sample Input 2

3
abc
arc
agc

Sample Output 2

3
3
3

Sample Input 3

8
at
atatat
attat
aatatatt
attattat
ttatta
tta
tt

Sample Output 3

2
4
3
8
3
6
3
1