Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

G. The Winds of Winter

time limit per test

2 secondsmemory limit per test

512 megabytesinput

standard inputoutput

standard outputGiven a rooted tree with *n* nodes. The Night King removes exactly one node from the tree and all the edges associated with it. Doing this splits the tree and forms a forest. The node which is removed is not a part of the forest.

The root of a tree in the forest is the node in that tree which does not have a parent. We define the strength of the forest as the size of largest tree in forest.

Jon Snow wants to minimize the strength of the forest. To do this he can perform the following operation at most once.

He removes the edge between a node and its parent and inserts a new edge between this node and any other node in forest such that the total number of trees in forest remain same.

For each node *v* you need to find the minimum value of strength of the forest formed when node *v* is removed.

Input

The first line of the input contains an integer *n* (1 ≤ *n* ≤ 10^{5}) — the number of vertices in the tree. Each of the next *n* lines contains a pair of vertex indices *u*_{i} and *v*_{i} (1 ≤ *u*_{i}, *v*_{i} ≤ *n*) where *u*_{i} is the parent of *v*_{i}. If *u*_{i} = 0 then *v*_{i} is the root.

Output

Print *n* line each containing a single integer. The *i*-th of them should be equal to minimum value of strength of forest formed when *i*-th node is removed and Jon Snow performs the operation described above at most once.

Examples

Input

10

0 1

1 2

1 3

1 4

2 5

2 6

3 7

4 8

4 9

5 10

Output

3

4

5

5

5

9

9

9

9

9

Input

2

2 1

0 2

Output

1

1

Note

The tree for first test case is depicted below. When you remove the first node, the tree splits to form the following forest. The strength of this forest is 4. Jon Snow now changes the parent of vertex 10 from 5 to 3. The strength of forest now becomes 3.

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/24/2019 02:37:02 (d2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|