実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
正整数 A,B が与えられます。
A+B の二乗を出力してください。
制約
- 1\leq A,B \leq 2025
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
入力例 1
20 25
出力例 1
2025
(20+25)^2=2025 です。
入力例 2
30 25
出力例 2
3025
入力例 3
45 11
出力例 3
3136
入力例 4
2025 1111
出力例 4
9834496
Score : 100 points
Problem Statement
You are given two positive integers A and B.
Output the square of A + B.
Constraints
- 1 \leq A,B \leq 2025
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer.
Sample Input 1
20 25
Sample Output 1
2025
(20+25)^2=2025.
Sample Input 2
30 25
Sample Output 2
3025
Sample Input 3
45 11
Sample Output 3
3136
Sample Input 4
2025 1111
Sample Output 4
9834496
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
5 枚のカードがあり、それぞれのカードには整数 A,B,C,D,E が書かれています。
この 5 枚組は以下の条件を満たすとき、またそのときに限って、フルハウスであると呼ばれます。
- 同じ数が書かれたカード 3 枚と、別の同じ数が書かれたカード 2 枚からなる。
5 枚組がフルハウスであるか判定してください。
制約
- 1 \leq A,B,C,D,E\leq 13
- A,B,C,D,E 全てが同じ値ではない
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E
出力
フルハウスである場合 Yes を、そうでないとき No を出力せよ。
入力例 1
1 2 1 2 1
出力例 1
Yes
1 が書かれたカード 3 枚と、2 が書かれたカード 2 枚からなるため、これはフルハウスです。
入力例 2
12 12 11 1 2
出力例 2
No
フルハウスの条件を満たしません。
Score : 100 points
Problem Statement
We have five cards with integers A, B, C, D, and E written on them, one on each card.
This set of five cards is called a Full house if and only if the following condition is satisfied:
- the set has three cards with a same number written on them, and two cards with another same number written on them.
Determine whether the set is a Full house.
Constraints
- 1 \leq A,B,C,D,E\leq 13
- Not all of A, B, C, D, and E are the same.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E
Output
If the set is a Full house, print Yes; otherwise, print No.
Sample Input 1
1 2 1 2 1
Sample Output 1
Yes
The set has three cards with 1 written on them and two cards with 2 written on them, so it is a Full house.
Sample Input 2
12 12 11 1 2
Sample Output 2
No
The condition is not satisfied.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
文字列 S, T が与えられます。以下の操作を高々 1 回行うことで、S を T と一致させることができるかを判定してください。
- S の隣り合う 2 文字を選び、入れ替える。
なお、上記の操作を一度も行わないことも可能です。
制約
- S, T はそれぞれ英小文字のみからなる、長さ 2 以上 100 以下の文字列
- S の長さと T の長さは等しい
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
問題文中の操作を高々 1 回行うことで S を T と一致させることができるなら Yes を、できないなら No を出力せよ。
入力例 1
abc acb
出力例 1
Yes
S の 2 文字目と 3 文字目を入れ替えることで、S を T と一致させることができます。
入力例 2
aabb bbaa
出力例 2
No
どのように操作を行っても、S を T と一致させることはできません。
入力例 3
abcde abcde
出力例 3
Yes
S と T は既に一致しています。
Score : 200 points
Problem Statement
You are given two strings S and T. Determine whether it is possible to make S and T equal by doing the following operation at most once:
- choose two adjacent characters in S and swap them.
Note that it is allowed to choose not to do the operation.
Constraints
- Each of S and T is a string of length between 2 and 100 (inclusive) consisting of lowercase English letters.
- S and T have the same length.
Input
Input is given from Standard Input in the following format:
S T
Output
If it is possible to make S and T equal by doing the operation in Problem Statement at most once, print Yes; otherwise, print No.
Sample Input 1
abc acb
Sample Output 1
Yes
You can swap the 2-nd and 3-rd characters of S to make S and T equal.
Sample Input 2
aabb bbaa
Sample Output 2
No
There is no way to do the operation to make S and T equal.
Sample Input 3
abcde abcde
Sample Output 3
Yes
S and T are already equal.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
xy 平面を考えます。x 軸の正の向きを東向き、y 軸の正の向きを北向きとします。
高橋君ははじめ、点 (x, y) = (0, 0) にいて東( x 軸の正の向き)を向いています。
S と R のみからなる長さ N の文字列 T = t_1t_2\ldots t_N が与えられます。
高橋君は i = 1, 2, \ldots, N の順番で下記を行います。
- t_i =
Sならば、高橋君はいま向いている方向に距離 1 だけ進む。 - t_i =
Rならば、高橋君はその場で右に 90 度回転する。その結果、高橋君の向いている方向が下記の通りに変わる。- 回転前の向きが東向き( x 軸の正の向き)ならば、回転後の向きは南向き( y 軸の負の向き)になる。
- 回転前の向きが南向き( y 軸の負の向き)ならば、回転後の向きは西向き( x 軸の負の向き)になる。
- 回転前の向きが西向き( x 軸の負の向き)ならば、回転後の向きは北向き( y 軸の正の向き)になる。
- 回転前の向きが北向き( y 軸の正の向き)ならば、回転後の向きは東向き( x 軸の正の向き)になる。
上記の手順を終えた後に高橋君がいる点の座標を出力してください。
制約
- 1 \leq N \leq 10^5
- N は整数
- T は
SとRのみからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N T
出力
問題文中の手順を終えた後に高橋君がいる点の座標 (x, y) を、下記の形式にしたがって空白区切りで出力せよ。
x y
入力例 1
4 SSRS
出力例 1
2 -1
高橋君ははじめ (0, 0) にいて東を向いています。その後、高橋君は下記の通りに行動します。
- t_1 =
Sであるので、高橋君は東に距離 1 だけ進んだ (1, 0) に移動します。 - t_2 =
Sであるので、高橋君は東に距離 1 だけ進んだ (2, 0) に移動します。 - t_3 =
Rであるので、高橋君は右に 90 度回転し、高橋君は南を向きます。 - t_4 =
Sであるので、高橋君は南に距離 1 だけ進んだ (2, -1) に移動します。
よって、高橋君の最終的な位置である (x, y) = (2, -1) を出力します。
入力例 2
20 SRSRSSRSSSRSRRRRRSRR
出力例 2
0 1
Score : 200 points
Problem Statement
Consider an xy-plane. The positive direction of the x-axis is in the direction of east, and the positive direction of the y-axis is in the direction of north.
Takahashi is initially at point (x, y) = (0, 0) and facing east (in the positive direction of the x-axis).
You are given a string T = t_1t_2\ldots t_N of length N consisting of S and R.
Takahashi will do the following move for each i = 1, 2, \ldots, N in this order.
- If t_i =
S, Takahashi advances in the current direction by distance 1. - If t_i =
R, Takahashi turns 90 degrees clockwise without changing his position. As a result, Takahashi's direction changes as follows.- If he is facing east (in the positive direction of the x-axis) before he turns, he will face south (in the negative direction of the y-axis) after he turns.
- If he is facing south (in the negative direction of the y-axis) before he turns, he will face west (in the negative direction of the x-axis) after he turns.
- If he is facing west (in the negative direction of the x-axis) before he turns, he will face north (in the positive direction of the y-axis) after he turns.
- If he is facing north (in the positive direction of the y-axis) before he turns, he will face east (in the positive direction of the x-axis) after he turns.
Print the coordinates Takahashi is at after all the steps above have been done.
Constraints
- 1 \leq N \leq 10^5
- N is an integer.
- T is a string of length N consisting of
SandR.
Input
Input is given from Standard Input in the following format:
N T
Output
Print the coordinates (x, y) Takahashi is at after all the steps described in the Problem Statement have been completed, in the following format, with a space in between:
x y
Sample Input 1
4 SSRS
Sample Output 1
2 -1
Takahashi is initially at (0, 0) facing east. Then, he moves as follows.
- t_1 =
S, so he advances in the direction of east by distance 1, arriving at (1, 0). - t_2 =
S, so he advances in the direction of east by distance 1, arriving at (2, 0). - t_3 =
R, so he turns 90 degrees clockwise, resulting in facing south. - t_4 =
S, so he advances in the direction of south by distance 1, arriving at (2, -1).
Thus, Takahashi's final position, (x, y) = (2, -1), should be printed.
Sample Input 2
20 SRSRSSRSSSRSRRRRRSRR
Sample Output 2
0 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
文字列 S が与えられます。次の操作を ちょうど 1 回 行った後の文字列としてあり得るものがいくつあるか求めてください。
- S の長さを N とする。 1\leq i<j\leq N をみたす整数の組 (i,j) を選び、S の i 文字目と j 文字目を入れ替える。
なお、この問題の制約下で操作を必ず行うことができることが証明できます。
制約
- S は英小文字からなる長さ 2 以上 10^6 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S に対して問題文中の操作をちょうど 1 回行った後の文字列としてあり得るものの個数を出力せよ。
入力例 1
abc
出力例 1
3
S の長さは 3 であるため、1\leq i<j\leq 3 をみたす整数の組 (i,j) としては、 (1,2), (1,3), (2,3) の 3 通りが考えられます。
- S の 1 文字目と 2 文字目を入れ替えた時、S は
bacとなります。 - S の 1 文字目と 3 文字目を入れ替えた時、S は
cbaとなります。 - S の 2 文字目と 3 文字目を入れ替えた時、S は
acbとなります。
よって、abc に対して操作を行った後の文字列としては、bac, cba, acb の 3 つがあり得るため、3 を出力します。
入力例 2
aaaaa
出力例 2
1
どの 2 つの文字を入れ替えても S は aaaaa のままです。よって、操作後の文字列としてあり得るものは 1 つです。
Points: 350 points
Problem Statement
You are given a string S. Find the number of strings that can result from performing the following operation exactly once.
- Let N be the length of S. Choose a pair of integers (i,j) such that 1\leq i<j\leq N and swap the i-th and j-th characters of S.
It can be proved that you can always perform it under the constraints of this problem.
Constraints
- S is a string of length between 2 and 10^6, inclusive, consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print the number of strings that can result from performing the operation in the problem statement exactly once on S.
Sample Input 1
abc
Sample Output 1
3
The length of S is 3, so 1\leq i<j\leq 3 is satisfied by three pairs of integers (i,j): (1,2), (1,3), and (2,3).
- Swapping the 1-st and 2-nd characters of S results in S being
bac. - Swapping the 1-st and 3-rd characters of S results in S being
cba. - Swapping the 2-nd and 3-rd characters of S results in S being
acb.
Therefore, the operation on abc results in one of the three strings: bac, cba, and acb, so print 3.
Sample Input 2
aaaaa
Sample Output 2
1
Swapping any two characters results in S remaining aaaaa. Thus, only one string can result from the operation.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英小文字からなる 2 つの文字列 S, T が与えられます。 次の操作を好きな回数( 0 回でも良い)行うことで、S を T と一致させることができるかを判定してください。
S において同じ文字が 2 文字連続しているところの間に、その文字と同じ文字を 1 つ挿入する。 すなわち、下記の 3 つの手順からなる操作を行う。
- 現在の S の長さを N とし、S = S_1S_2\ldots S_N とする。
- 1 以上 N-1 以下の整数 i であって、S_i = S_{i+1} を満たすものを 1 つ選択する。(ただし、そのような i が存在しない場合は、何もせずに手順 3.をスキップして操作を終了する。)
- S の i 文字目と i+1 文字目の間に文字 S_i(= S_{i+1}) を 1 つ挿入する。その結果、S は長さ N+1 の文字列 S_1S_2\ldots S_i S_i S_{i+1} \ldots S_N となる。
制約
- S と T はそれぞれ英小文字からなる長さ 2 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
S を T と一致させることができる場合は Yes を、そうでない場合は No を出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
abbaac abbbbaaac
出力例 1
Yes
下記の 3 回の操作によって、S = abbaac を T = abbbbaaac に一致させることができます。
- まず、S の 2 文字目と 3 文字目の間に
bを挿入する。その結果、S =abbbaacとなる。 - 次に、再び S の 2 文字目と 3 文字目の間に
bを挿入する。その結果、S =abbbbaacとなる。 - 最後に、S の 6 文字目と 7 文字目の間に
aを挿入する。その結果、S =abbbbaaacとなる。
よって、Yes を出力します。
入力例 2
xyzz xyyzz
出力例 2
No
どのように操作を行っても、 S = xyzz を T = xyyzz に一致させることはできません。
よって、No を出力します。
Score : 300 points
Problem Statement
You are given two strings S and T. Determine whether it is possible to make S equal T by performing the following operation some number of times (possibly zero).
Between two consecutive equal characters in S, insert a character equal to these characters. That is, take the following three steps.
- Let N be the current length of S, and S = S_1S_2\ldots S_N.
- Choose an integer i between 1 and N-1 (inclusive) such that S_i = S_{i+1}. (If there is no such i, do nothing and terminate the operation now, skipping step 3.)
- Insert a single copy of the character S_i(= S_{i+1}) between the i-th and (i+1)-th characters of S. Now, S is a string of length N+1: S_1S_2\ldots S_i S_i S_{i+1} \ldots S_N.
Constraints
- Each of S and T is a string of length between 2 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S T
Output
If it is possible to make S equal T, print Yes; otherwise, print No.
Note that the judge is case-sensitive.
Sample Input 1
abbaac abbbbaaac
Sample Output 1
Yes
You can make S = abbaac equal T = abbbbaaac by the following three operations.
- First, insert
bbetween the 2-nd and 3-rd characters of S. Now, S =abbbaac. - Next, insert
bagain between the 2-nd and 3-rd characters of S. Now, S =abbbbaac. - Lastly, insert
abetween the 6-th and 7-th characters of S. Now, S =abbbbaaac.
Thus, Yes should be printed.
Sample Input 2
xyzz xyyzz
Sample Output 2
No
No sequence of operations makes S = xyzz equal T = xyyzz.
Thus, No should be printed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 425 点
問題文
N 頂点 M 辺の有向グラフがあります。頂点には 1 から N までの番号が付けられており、i 番目の辺は頂点 U_i から頂点 V_i へ向かう有向辺です。ここで、各頂点の出次数は 1 以上です。
また、各頂点には文字が書かれており、頂点 i に書かれている文字は S_i です。ただし、S_i とは S の i 文字目を指します。
Alice と Bob はこのグラフ上で 1 つの駒を用いて以下のゲームを行います。
-
はじめ、駒は頂点 1 に置かれており、Alice が先手、Bob が後手となって以下の操作を交互に K 回ずつ行う。
- 現在駒が置かれている頂点を u とする。頂点 u から頂点 v に向かう辺が存在するような頂点 v を選び、駒を頂点 v に移動させる。
-
最終的に駒が置かれている頂点を v として、S_v =
Aのとき Alice の勝ち、S_v =Bのとき Bob の勝ちである。
両者が最適に行動したときのゲームの勝者を求めてください。
1 つの入力において T 個のテストケースが与えられます。それぞれについて答えてください。
制約
- 1 \leq T
- 2 \leq N, M \leq 2 \times 10^5
- 1 \leq K \leq 10
- S は
A,Bからなる長さ N の文字列 - 1 \leq U_i, V_i \leq N
- i \neq j のとき (U_i, V_i) \neq (U_j, V_j)
- 各頂点の出次数は 1 以上
- 1 つの入力に含まれるテストケースについて、N の総和は 2 \times 10^5 以下
- 1 つの入力に含まれるテストケースについて、M の総和は 2 \times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
T
\text{case}_1
\text{case}_2
\ldots
\text{case}_T
ここで、\text{case}_i は i 番目のテストケースを表し、各テストケースは以下の形式で与えられる。
N M K S U_1 V_1 U_2 V_2 \vdots U_M V_M
出力
T 行出力せよ。i 行目には、i 番目のテストケースにおいて両者が最適に行動したときに Alice が勝つ場合 Alice を、Bob が勝つ場合 Bob を出力せよ。
入力例 1
3 4 6 2 AABB 1 2 2 3 3 1 3 3 3 4 4 2 4 6 2 ABAB 1 2 2 3 3 1 3 3 3 4 4 2 5 8 3 ABABB 1 2 2 2 2 3 3 1 3 4 4 4 4 5 5 3
出力例 1
Alice Bob Bob
1 番目のテストケースについてゲームの進行の一例を説明します。ただし、この進行において両者は最適に行動しているとは限りません。
- はじめ、駒は頂点 1 に置かれている。
- Alice が頂点 2 に駒を動かす。
- Bob が頂点 3 に駒を動かす。
- Alice が頂点 3 に駒を動かす。
- Bob が頂点 1 に駒を動かす。
このとき、S_1 = A であるため Alice の勝ちとなります。
Score : 425 points
Problem Statement
There is a directed graph with N vertices and M edges. The vertices are numbered from 1 to N, and the i-th edge is a directed edge from vertex U_i to vertex V_i. Here, the out-degree of each vertex is at least 1.
Also, each vertex has a character written on it, and the character written on vertex i is S_i. Here, S_i refers to the i-th character of S.
Alice and Bob play the following game on this graph using one piece:
-
Initially, the piece is placed on vertex 1, and they alternately perform the following operation K times each, with Alice going first and Bob going second.
- Let u be the vertex where the piece is currently placed. Choose a vertex v such that there is an edge from vertex u to vertex v, and move the piece to vertex v.
-
Let v be the vertex where the piece is finally placed. If S_v =
A, Alice wins; if S_v =B, Bob wins.
Find the winner of the game when both players play optimally.
In each input, you are given T test cases. Solve each of them.
Constraints
- 1 \leq T
- 2 \leq N, M \leq 2 \times 10^5
- 1 \leq K \leq 10
- S is a string of length N consisting of
AandB. - 1 \leq U_i, V_i \leq N
- (U_i, V_i) \neq (U_j, V_j) if i \neq j .
- The out-degree of each vertex is at least 1.
- The sum of N over all test cases in a single input is at most 2 \times 10^5.
- The sum of M over all test cases in a single input is at most 2 \times 10^5.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\ldots
\text{case}_T
Here, \text{case}_i represents the i-th test case, and each test case is given in the following format:
N M K S U_1 V_1 U_2 V_2 \vdots U_M V_M
Output
Print T lines. The i-th line should contain Alice if Alice wins when both players play optimally in the i-th test case, and Bob if Bob wins.
Sample Input 1
3 4 6 2 AABB 1 2 2 3 3 1 3 3 3 4 4 2 4 6 2 ABAB 1 2 2 3 3 1 3 3 3 4 4 2 5 8 3 ABABB 1 2 2 2 2 3 3 1 3 4 4 4 4 5 5 3
Sample Output 1
Alice Bob Bob
We will explain an example of how the game proceeds in the first test case. Here, both players do not necessarily play optimally.
- Initially, the piece is placed on vertex 1.
- Alice moves the piece to vertex 2.
- Bob moves the piece to vertex 3.
- Alice moves the piece to vertex 3.
- Bob moves the piece to vertex 1.
At this point, S_1 = A, so Alice wins.
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
二次元平面上に N 個の点があり、i 番目の点は座標 (X_i, Y_i) にあります。どの 2 点も相異なる位置にあり、どの 3 点も同一直線上にないことが保証されます。
これらの点から 4 点を選ぶ組合せのうち、その 4 点を頂点とする多角形として台形がとれるものは何通りありますか?
制約
- 4 \leq N \leq 2\,000
- 0 \leq X_i, Y_i \leq 10^7 (1 \leq i \leq N)
- どの 2 点も相異なる位置にある。
- どの 3 点も同一直線上にない。
- 入力される値は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 \vdots X_N Y_N
出力
答えを 1 行に出力せよ。
入力例 1
5 0 2 0 5 1 0 2 1 2 4
出力例 1
3
与えられた点は、以下の図のような配置になっています。

ここから 4 点を選ぶ組合せのうち、それらを頂点とする台形がとれるものは以下の 3 通りです。
- 1,5,4,3 番目の点。
- 1,3,4,2 番目の点。
- 1,2,5,4 番目の点。
平行四辺形や長方形も台形の一種として扱うことに注意してください。
入力例 2
8 0 1 1 3 2 3 3 1 0 2 1 0 2 0 3 2
出力例 2
22
Score : 475 points
Problem Statement
There are N points on a two-dimensional plane, with the i-th point at coordinates (X_i, Y_i). It is guaranteed that no two points are at the same position, and no three points are collinear.
Among the combinations of four points from these points, how many combinations can form a trapezoid as a polygon with those four points as vertices?
Constraints
- 4 \leq N \leq 2\,000
- 0 \leq X_i, Y_i \leq 10^7 (1 \leq i \leq N)
- No two points are at the same location.
- No three points are collinear.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X_1 Y_1 \vdots X_N Y_N
Output
Print the answer on one line.
Sample Input 1
5 0 2 0 5 1 0 2 1 2 4
Sample Output 1
3
The given points are arranged as shown in the figure below.

Among the combinations of four points, the following three combinations can form a trapezoid as a polygon with those points as vertices:
- The 1st, 5th, 4th, 3rd points.
- The 1st, 3rd, 4th, 2nd points.
- The 1st, 2nd, 5th, 4th points.
Note that parallelograms and rectangles are also treated as trapezoids.
Sample Input 2
8 0 1 1 3 2 3 3 1 0 2 1 0 2 0 3 2
Sample Output 2
22
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
N 頂点の木が与えられます。頂点には 1,2,\ldots ,N の番号がついており、i 番目の辺は頂点 u_i,v_i を結ぶ無向辺です。
各整数 i\,(1 \leq i \leq N) に対して、\sum_{j=1}^{N}dis(i,j) を求めてください。
ただし、dis(i,j) は頂点 i から頂点 j に到達する際にたどる必要のある最小の辺数です。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq u_i < v_i \leq N
- 与えられるグラフは木
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}
出力
N 行出力せよ。
i 行目には \sum_{j=1}^{N}dis(i,j) を出力せよ。
入力例 1
3 1 2 2 3
出力例 1
3 2 3
dis(1,1)+dis(1,2)+dis(1,3)=0+1+2=3、
dis(2,1)+dis(2,2)+dis(2,3)=1+0+1=2、
dis(3,1)+dis(3,2)+dis(3,3)=2+1+0=3、
です。
入力例 2
2 1 2
出力例 2
1 1
入力例 3
6 1 6 1 5 1 3 1 4 1 2
出力例 3
5 9 9 9 9 9
Score : 500 points
Problem Statement
Given is a tree with N vertices. The vertices are numbered 1,2,\ldots ,N, and the i-th edge is an undirected edge connecting Vertices u_i and v_i.
For each integer i\,(1 \leq i \leq N), find \sum_{j=1}^{N}dis(i,j).
Here, dis(i,j) denotes the minimum number of edges that must be traversed to go from Vertex i to Vertex j.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq u_i < v_i \leq N
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}
Output
Print N lines.
The i-th line should contain \sum_{j=1}^{N}dis(i,j).
Sample Input 1
3 1 2 2 3
Sample Output 1
3 2 3
We have:
dis(1,1)+dis(1,2)+dis(1,3)=0+1+2=3,
dis(2,1)+dis(2,2)+dis(2,3)=1+0+1=2,
dis(3,1)+dis(3,2)+dis(3,3)=2+1+0=3.
Sample Input 2
2 1 2
Sample Output 2
1 1
Sample Input 3
6 1 6 1 5 1 3 1 4 1 2
Sample Output 3
5 9 9 9 9 9