Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
長さ N の数列 A = (A_1, A_2, \dots, A_N) が与えられます。
あなたは次の操作をちょうど K 回行います。
- A の先頭の要素を取り除き、A の末尾に 0 を挿入する。
操作を行った後の A の要素をすべて出力してください。
制約
- 1 \leq N \leq 100
- 1 \leq K \leq 100
- 1 \leq A_i \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
操作を行った後の A の要素を空白区切りで 1 行に出力せよ。
入力例 1
3 2 2 7 8
出力例 1
8 0 0
操作を行う前は A = (2, 7, 8) です。
操作を 1 回行った時点では A = (7, 8, 0) です。
操作を 2 回行った時点では A = (8, 0, 0) です。
よって (8, 0, 0) が答えです。
入力例 2
3 4 9 9 9
出力例 2
0 0 0
入力例 3
9 5 1 2 3 4 5 6 7 8 9
出力例 3
6 7 8 9 0 0 0 0 0
Score : 100 points
Problem Statement
You are given a sequence A = (A_1, A_2, \dots, A_N) of length N.
You perform the following operation exactly K times:
- remove the initial element of A and append a 0 to the tail of A.
Print all the elements of A after the operations.
Constraints
- 1 \leq N \leq 100
- 1 \leq K \leq 100
- 1 \leq A_i \leq 100
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_N
Output
Print the elements of A after the operations in one line, separated by spaces.
Sample Input 1
3 2 2 7 8
Sample Output 1
8 0 0
Before the operations, A = (2, 7, 8).
After performing the operation once, A = (7, 8, 0).
After performing the operation twice, A = (8, 0, 0).
Thus, (8, 0, 0) is the answer.
Sample Input 2
3 4 9 9 9
Sample Output 2
0 0 0
Sample Input 3
9 5 1 2 3 4 5 6 7 8 9
Sample Output 3
6 7 8 9 0 0 0 0 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君は
2025 年 5 月 17 日 A 時 B 分締切のレポートを、
2025 年 5 月 17 日 C 時 D 分に提出しました。
ここで、「A 時 B 分」と「C 時 D 分」は異なる時刻であることが保証されます。
高橋君が締切前にレポートを提出しているならば Yes を、そうでないならば No を出力してください。
制約
- 0 \leq A,C \leq 23
- 0 \leq B,D \leq 59
- (A,B)\neq(C,D)
- A,B,C,D は整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D
出力
高橋君が締切前にレポートを提出しているならば Yes を、そうでないならば No を出力せよ。
入力例 1
22 40 22 30
出力例 1
Yes
レポートの締切は 22 時 40 分であり、高橋君は 22 時 30 分に提出しているため、締切前にレポートを提出しています。
よって、Yes を出力します。
入力例 2
22 40 22 45
出力例 2
No
レポートの締切は 22 時 40 分であり、高橋君は 22 時 45 分に提出しているため、締切後にレポートを提出しています。
よって、No を出力します。
入力例 3
12 0 11 30
出力例 3
Yes
Score : 100 points
Problem Statement
Takahashi had a report whose deadline was B minutes past A o'clock on May 17, 2025. He submitted it at D minutes past C o'clock on May 17, 2025.
It is guaranteed that "B minutes past A o'clock" and "D minutes past C o'clock" are different times.
Output Yes if Takahashi submitted the report before the deadline, and No otherwise.
Constraints
- 0 \leq A, C \leq 23
- 0 \leq B, D \leq 59
- (A, B) \neq (C, D)
- A, B, C, and D are integers.
Input
The input is given from Standard Input in the following format:
A B C D
Output
If Takahashi submitted the report before the deadline, output Yes; otherwise, output No.
Sample Input 1
22 40 22 30
Sample Output 1
Yes
The deadline is 22:40, and he submitted at 22:30, so he submitted before the deadline.
Hence, output Yes.
Sample Input 2
22 40 22 45
Sample Output 2
No
The deadline is 22:40, and he submitted at 22:45, so he submitted after the deadline.
Hence, output No.
Sample Input 3
12 0 11 30
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君には、穴 1,2,\dots,N に 1 本ずつ、全部で N 本の歯が生えています。
歯医者の青木君は、これらの歯と穴に対して、 Q 回の治療を行います。
i 回目の治療では、穴 T_i を治療します。治療内容は次の通りです。
- 穴 T_i に歯が生えている場合、穴 T_i から歯を抜く。
- そうでない ( 穴 T_i に歯が生えていない) 場合、穴 T_i に歯を生やす。
全ての治療が終わった後、高橋君に生えている歯の本数は何本ですか?
制約
- 入力は全て整数
- 1 \le N,Q \le 1000
- 1 \le T_i \le N
入力
入力は以下の形式で標準入力から与えられる。
N Q T_1 T_2 \dots T_Q
出力
答えを整数として出力せよ。
入力例 1
30 6 2 9 18 27 18 9
出力例 1
28
高橋君には最初 30 本の歯が生えており、青木君は 6 回の治療を行います。
- 1 回目の治療では穴 2 を治療します。 穴 2 に歯が生えているため、歯を抜きます。
- 2 回目の治療では穴 9 を治療します。 穴 9 に歯が生えているため、歯を抜きます。
- 3 回目の治療では穴 18 を治療します。 穴 18 に歯が生えているため、歯を抜きます。
- 4 回目の治療では穴 27 を治療します。 穴 27 に歯が生えているため、歯を抜きます。
- 5 回目の治療では穴 18 を治療します。 穴 18 に歯が生えていないため、歯を生やします。
- 6 回目の治療では穴 9 を治療します。 穴 9 に歯が生えていないため、歯を生やします。
最終的な歯の本数は 28 本です。
入力例 2
1 7 1 1 1 1 1 1 1
出力例 2
0
入力例 3
9 20 9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8
出力例 3
5
Score: 200 points
Problem Statement
Takahashi has N teeth, one in each of the holes numbered 1, 2, \dots, N.
Dentist Aoki will perform Q treatments on these teeth and holes.
In the i-th treatment, hole T_i is treated as follows:
- If there is a tooth in hole T_i, remove the tooth from hole T_i.
- If there is no tooth in hole T_i (i.e., the hole is empty), grow a tooth in hole T_i.
After all treatments are completed, how many teeth does Takahashi have?
Constraints
- All input values are integers.
- 1 \le N, Q \le 1000
- 1 \le T_i \le N
Input
The input is given from Standard Input in the following format:
N Q T_1 T_2 \dots T_Q
Output
Print the number of teeth as an integer.
Sample Input 1
30 6 2 9 18 27 18 9
Sample Output 1
28
Initially, Takahashi has 30 teeth, and Aoki performs six treatments.
- In the first treatment, hole 2 is treated. There is a tooth in hole 2, so it is removed.
- In the second treatment, hole 9 is treated. There is a tooth in hole 9, so it is removed.
- In the third treatment, hole 18 is treated. There is a tooth in hole 18, so it is removed.
- In the fourth treatment, hole 27 is treated. There is a tooth in hole 27, so it is removed.
- In the fifth treatment, hole 18 is treated. There is no tooth in hole 18, so a tooth is grown.
- In the sixth treatment, hole 9 is treated. There is no tooth in hole 9, so a tooth is grown.
The final count of teeth is 28.
Sample Input 2
1 7 1 1 1 1 1 1 1
Sample Output 2
0
Sample Input 3
9 20 9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
x 軸の正の向きが右、y 軸の正の向きが上であるような xy 座標平面において、点 (a,b) を原点を中心として反時計回りに d 度回転させた点を求めてください。
制約
- -1000 \leq a,b \leq 1000
- 1 \leq d \leq 360
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
a b d
出力
求めるべき点を (a',b') とするとき、 a' と b' をこの順に空白区切りで出力せよ。
なお、各出力について、解との絶対誤差または相対誤差が 10^{−6} 以下であれば正解として扱われる。
入力例 1
2 2 180
出力例 1
-2 -2
(2,2) を原点を中心として反時計回りに 180 度回転させた点は、(2,2) を原点について対称な位置に移動させた点であり、(-2,-2) となります。
入力例 2
5 0 120
出力例 2
-2.49999999999999911182 4.33012701892219364908
(5,0) を原点を中心として反時計回りに 120 度回転させた点は (-\frac {5}{2} , \frac {5\sqrt{3}}{2}) です。
この例での出力はこれらの値と厳密には一致しませんが、誤差が十分に小さいため正解として扱われます。
入力例 3
0 0 11
出力例 3
0.00000000000000000000 0.00000000000000000000
(a,b) が原点(回転の中心)なので回転させても座標が変わりません。
入力例 4
15 5 360
出力例 4
15.00000000000000177636 4.99999999999999555911
360 度回転させたので座標が変わりません。
入力例 5
-505 191 278
出力例 5
118.85878514480690171240 526.66743699786547949770
Score : 200 points
Problem Statement
In an xy-coordinate plane whose x-axis is oriented to the right and whose y-axis is oriented upwards, rotate a point (a, b) around the origin d degrees counterclockwise and find the new coordinates of the point.
Constraints
- -1000 \leq a,b \leq 1000
- 1 \leq d \leq 360
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
a b d
Output
Let the new coordinates of the point be (a', b'). Print a' and b' in this order, with a space in between.
Your output will be considered correct when, for each value printed, the absolute or relative error from the answer is at most 10^{-6}.
Sample Input 1
2 2 180
Sample Output 1
-2 -2
When (2, 2) is rotated around the origin 180 degrees counterclockwise, it becomes the symmetric point of (2, 2) with respect to the origin, which is (-2, -2).
Sample Input 2
5 0 120
Sample Output 2
-2.49999999999999911182 4.33012701892219364908
When (5, 0) is rotated around the origin 120 degrees counterclockwise, it becomes (-\frac {5}{2} , \frac {5\sqrt{3}}{2}).
This sample output does not precisely match these values, but the errors are small enough to be considered correct.
Sample Input 3
0 0 11
Sample Output 3
0.00000000000000000000 0.00000000000000000000
Since (a, b) is the origin (the center of rotation), a rotation does not change its coordinates.
Sample Input 4
15 5 360
Sample Output 4
15.00000000000000177636 4.99999999999999555911
A 360-degree rotation does not change the coordinates of a point.
Sample Input 5
-505 191 278
Sample Output 5
118.85878514480690171240 526.66743699786547949770
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
2 つの文字列 A,B に対して、A の末尾に B を連結した文字列を A+B と表します。
N 個の文字列 S_1,\ldots,S_N が与えられます。i=1,\ldots,N の順に、次の指示に従って加工して出力してください。
- S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が存在しないならば、S_i を出力する。
- S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が X 個 (X>0) 存在するならば、X を文字列として扱って S_i+
(+X+)を出力する。
制約
- 1 \leq N \leq 2\times 10^5
- S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
問題文中の指示にしたがって、N 行出力せよ。
入力例 1
5 newfile newfile newfolder newfile newfolder
出力例 1
newfile newfile(1) newfolder newfile(2) newfolder(1)
入力例 2
11 a a a a a a a a a a a
出力例 2
a a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9) a(10)
Score : 300 points
Problem Statement
For two strings A and B, let A+B denote the concatenation of A and B in this order.
You are given N strings S_1,\ldots,S_N. Modify and print them as follows, in the order i=1, \ldots, N:
- if none of S_1,\ldots,S_{i-1} is equal to S_i, print S_i;
- if X (X>0) of S_1,\ldots,S_{i-1} are equal to S_i, print S_i+
(+X+), treating X as a string.
Constraints
- 1 \leq N \leq 2\times 10^5
- S_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print N lines as specified in the Problem Statement.
Sample Input 1
5 newfile newfile newfolder newfile newfolder
Sample Output 1
newfile newfile(1) newfolder newfile(2) newfolder(1)
Sample Input 2
11 a a a a a a a a a a a
Sample Output 2
a a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9) a(10)
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 人の生徒が 4 日間にわたる試験を受けています。
それぞれの日に行われる試験は 300 点満点です。すなわち、4 日間を通した試験の満点は 1200 点です。
現在 3 日目までの試験が終わり、これから 4 日目の試験が行われようとしています。i \, (1 \leq i \leq N) 番目の生徒は j \, (1 \leq j \leq 3) 日目の試験で P_{i, j} 点獲得しました。
それぞれの生徒について、4 日目の試験後に上位 K 位以内に入っていることがあり得るかどうか判定してください。
ただし、4 日目の試験後の生徒の順位は、その生徒よりも 4 日間の合計点が高い生徒の人数に 1 を加えた値として定めます。
制約
- 1 \leq K \leq N \leq 10^5
- 0 \leq P_{i, j} \leq 300 \, (1 \leq i \leq N, 1 \leq j \leq 3)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N K
P_{1,1} P_{1,2} P_{1,3}
\vdots
P_{N,1} P_{N,2} P_{N,3}
出力
N 行出力せよ。i \, (1 \leq i \leq N) 行目には、i 番目の生徒が 4 日目の試験後に上位 K 位以内に入っていることがあり得るならば Yes と、そうでないならば No と出力せよ。
入力例 1
3 1 178 205 132 112 220 96 36 64 20
出力例 1
Yes Yes No
4 日目に全員が 100 点を取ると、1 番目の生徒が 1 位になります。 4 日目に 2 番目の生徒が 100 点を取り、それ以外の生徒が 0 点を取ると、2 番目の生徒が 1 位になります。 3 番目の生徒が 1 位になることはあり得ません。
入力例 2
2 1 300 300 300 200 200 200
出力例 2
Yes Yes
入力例 3
4 2 127 235 78 192 134 298 28 56 42 96 120 250
出力例 3
Yes Yes No Yes
Score : 300 points
Problem Statement
N students are taking a 4-day exam.
There is a 300-point test on each day, for a total of 1200 points.
The first three days of the exam are already over, and the fourth day is now about to begin. The i-th student (1 \leq i \leq N) got P_{i, j} points on the j-th day (1 \leq j \leq 3).
For each student, determine whether it is possible that he/she is ranked in the top K after the fourth day.
Here, the rank of a student after the fourth day is defined as the number of students whose total scores over the four days are higher than that of the student, plus 1.
Constraints
- 1 \leq K \leq N \leq 10^5
- 0 \leq P_{i, j} \leq 300 \, (1 \leq i \leq N, 1 \leq j \leq 3)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
P_{1,1} P_{1,2} P_{1,3}
\vdots
P_{N,1} P_{N,2} P_{N,3}
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain Yes if it is possible that the i-th student is ranked in the top K after the fourth day, and No otherwise.
Sample Input 1
3 1 178 205 132 112 220 96 36 64 20
Sample Output 1
Yes Yes No
If every student scores 100 on the fourth day, the 1-st student will rank 1-st.
If the 2-nd student scores 100 and the other students score 0 on the fourth day, the 2-nd student will rank 1-st.
The 3-rd student will never rank 1-st.
Sample Input 2
2 1 300 300 300 200 200 200
Sample Output 2
Yes Yes
Sample Input 3
4 2 127 235 78 192 134 298 28 56 42 96 120 250
Sample Output 3
Yes Yes No Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
円周上に N 個の点が等間隔に並んでおり、時計回りに 1,2,\ldots,N と番号がつけられています。
M 本の相異なる直線があり、i 本目の直線は異なる 2 つの点、点 A_i と点 B_i を通る直線です。(1 \leq i \leq M)
以下の 2 つの条件をともに満たすような整数の組 (i,j) の個数を求めてください。
- 1 \leq i < j \leq M
- i 本目の直線と j 本目の直線は交わる
制約
- 2 \leq N \leq 10^6
- 1 \leq M \leq 3 \times 10^{5}
- 1 \leq A_i < B_i \leq N (1 \leq i \leq M)
- (A_i,B_i) \neq (A_j,B_j) (i \neq j)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
出力
答えを出力せよ。
入力例 1
8 3 1 5 1 8 2 4
出力例 1
2
次の図のように円周上に 8 個の点と 3 本の直線があります。

1 本目の直線と 2 本目の直線は交わります。1 本目の直線と 3 本目の直線は交わりません。2 本目の直線と 3 本目の直線は交わります。(i,j)=(1,2),(2,3) の 2 つの組が条件を満たすため、2 を出力します。
入力例 2
5 10 2 5 1 5 1 2 2 4 2 3 1 3 1 4 3 5 3 4 4 5
出力例 2
40
Score : 400 points
Problem Statement
There are N equally spaced points on a circle labeled clockwise as 1,2,\ldots,N.
There are M distinct lines, where the i-th line passes through two distinct points A_i and B_i (1 \leq i \leq M).
Find the number of pairs (i,j) satisfying:
- 1 \le i < j \le M, and
- the i-th and j-th lines intersect.
Constraints
- 2 \leq N \leq 10^6
- 1 \leq M \leq 3 \times 10^{5}
- 1 \leq A_i < B_i \leq N (1 \leq i \leq M)
- (A_i,B_i) \neq (A_j,B_j) (i \neq j)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
Output
Print the answer.
Sample Input 1
8 3 1 5 1 8 2 4
Sample Output 1
2
As shown in the diagram below, there are eight points and three lines on the circle.

The 1st and 2nd lines intersect. The 1st and 3rd lines do not intersect. The 2nd and 3rd lines intersect. Since the pairs (i,j)=(1,2),(2,3) satisfy the conditions, print 2.
Sample Input 2
5 10 2 5 1 5 1 2 2 4 2 3 1 3 1 4 3 5 3 4 4 5
Sample Output 2
40
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
長さ 2N の非負整数列 A = (A_1, \dots, A_{2N}) が与えられます。
長さ 2N の括弧列 s のスコアを、以下で得られる値として定義します。
- s の i 文字目が
)であるようなすべての整数 i について A_i の値を 0 に変えた場合の、A の要素の総和。
長さ 2N の正しい括弧列のスコアとしてありうる最大値を求めてください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
正しい括弧列とは
正しい括弧列とは、() である部分文字列を削除することを 0 回以上繰り返して空文字列にできる文字列を指します。
制約
- 1 \leq T \leq 500
- 1 \leq N \leq 2 \times 10^5
- 各入力ファイルについて、すべてのテストケースの N の総和は 2 \times 10^5 以下である。
- 0 \leq A_i \leq 10^9 (1 \leq i \leq 2N)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
T
\textrm{case}_1
\textrm{case}_2
\vdots
\textrm{case}_T
\textrm{case}_i は i 番目のテストケースを表す。各テストケースは以下の形式で与えられる。
N
A_1
A_2
\vdots
A_{2N}
出力
T 行出力せよ。i 行目 (1 \leq i \leq T) には i 番目のテストケースに対する答えを出力せよ。
入力例 1
2 3 400 500 200 100 300 600 6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 1
1200 6000000000
1 番目のテストケースにおいて、正しい括弧列として (())() を選ぶと、そのスコアは 400+500+0+0+300+0=1200 となります。
1200 よりも高いスコアを得るような正しい括弧列は存在しないので、1 番目のテストケースの答えとして 1200 を出力します。
この入出力例における 2 番目のテストケースのように、答えが 32 bit 整数におさまらないことがあることに注意してください。
Score : 450 points
Problem Statement
You are given a sequence of non-negative integers A = (A_1,\dots,A_{2N}) of length 2N.
Define the score of a parenthesis sequence s of length 2N as follows:
- For every position i where the i-th character of s is
), set A_i to 0, then take the sum of all elements of A.
Find the maximum possible score of a correct parenthesis sequence of length 2N.
You are given T test cases; solve each.
What is a correct parenthesis sequence?
A correct parenthesis sequence is a string that can be reduced to the empty string by repeatedly removing substrings equal to().
Constraints
- 1 \le T \le 500
- 1 \le N \le 2 \times 10^{5}
- For each input file, the sum of N over all test cases is at most 2 \times 10^{5}.
- 0 \le A_i \le 10^{9} (1 \le i \le 2N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\textrm{case}_1
\textrm{case}_2
\vdots
\textrm{case}_T
\textrm{case}_i represents the i-th test case. Each test case is given in the following format:
N
A_1
A_2
\vdots
A_{2N}
Output
Output T lines. The i-th line (1 \le i \le T) should contain the answer for the i-th test case.
Sample Input 1
2 3 400 500 200 100 300 600 6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 1
1200 6000000000
In the first test case, choosing the correct parenthesis string (())() gives a score of 400+500+0+0+300+0=1200.
No correct parenthesis string yields a higher score, so the answer is 1200.
Note that, as in the second test case of this sample, the answer may exceed the 32-bit integer range.
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
2 つの文字列 X,Y に対して、その類似度 f(X,Y) を、X と Y を先頭から見て一致している文字数とします。
例えば abc と axbc の類似度は 1 、aaa と aaaa の類似度は 3 です。
長さ N の文字列 S が与えられます。S の i 文字目以降からなる文字列を S_i とします。k=1,\ldots,N のそれぞれについて、f(S_k,S_1)+f(S_k,S_2)+\ldots+f(S_k,S_N) を求めてください。
制約
- 1 \leq N \leq 10^6
- S は英小文字のみからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
N 行出力せよ。
i 行目には k=i の問題の答えを出力せよ。
入力例 1
3 abb
出力例 1
3 3 2
S_1,S_2,S_3 はそれぞれ abb, bb, b です。
- k=1 のとき f(S_1,S_1)+f(S_1,S_2)+f(S_1,S_3)=3+0+0=3
- k=2 のとき f(S_2,S_1)+f(S_2,S_2)+f(S_2,S_3)=0+2+1=3
- k=3 のとき f(S_3,S_1)+f(S_3,S_2)+f(S_3,S_3)=0+1+1=2
入力例 2
11 mississippi
出力例 2
11 16 14 12 13 11 9 7 4 3 4
Score : 500 points
Problem Statement
Let the similarity f(X,Y) between two strings X and Y be the length of their longest common prefix.
For example, the similarity between abc and axbc is 1, and the similarity between aaa and aaaa is 3.
You are given a string S of length N. Let S_i be the suffix of S beginning with the i-th character of S. For each k=1,\ldots,N, find f(S_k,S_1)+f(S_k,S_2)+\ldots+f(S_k,S_N).
Constraints
- 1 \leq N \leq 10^6
- S is a string of length N consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N S
Output
Print N lines.
The i-th line should contain the answer for k=i.
Sample Input 1
3 abb
Sample Output 1
3 3 2
S_1 is abb, S_2 is bb, and S_3 is b.
- For k=1: f(S_1,S_1)+f(S_1,S_2)+f(S_1,S_3)=3+0+0=3.
- For k=2: f(S_2,S_1)+f(S_2,S_2)+f(S_2,S_3)=0+2+1=3.
- For k=3: f(S_3,S_1)+f(S_3,S_2)+f(S_3,S_3)=0+1+1=2.
Sample Input 2
11 mississippi
Sample Output 2
11 16 14 12 13 11 9 7 4 3 4