1187_E. Tree Painting_36648
You are given a tree (an undirected connected acyclic graph) consisting of n vertices. You are playing a game on this tree.

Initially all vertices are white. On the first turn of the game you choose one vertex and paint it black. Then on each turn you choose a white vertex adjacent (connected by an edge) to any black vertex and paint it black.

Each time when you choose a vertex (even during the first turn), you gain the number of points equal to the size of the connected component consisting only of white vertices that contains the chosen vertex. The game ends when all vertices are painted black.

Let's see the following example:

<image>

Vertices 1 and 4 are painted black already. If you choose the vertex 2, you will gain 4 points for the connected component consisting of vertices 2, 3, 5 and 6. If you choose the vertex 9, you will gain 3 points for the connected component consisting of vertices 7, 8 and 9.

Your task is to maximize the number of points you gain.

Input

The first line contains an integer n — the number of vertices in the tree (2 ≤ n ≤ 2 ⋅ 10^5).

Each of the next n - 1 lines describes an edge of the tree. Edge i is denoted by two integers u_i and v_i, the indices of vertices it connects (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i).

It is guaranteed that the given edges form a tree.

Output

Print one integer — the maximum number of points you gain if you will play optimally.

Examples

Input


9
1 2
2 3
2 5
2 6
1 4
4 9
9 7
9 8


Output


36


Input


5
1 2
1 3
2 4
2 5


Output


14

Note

The first example tree is shown in the problem statement.
import sys

input = sys.stdin.readline

n = int(input())
G = [[] for _ in range(n)]

for _ in range(n-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

F = [0]*n
stk = [0]
visited = [0]*n

while stk:
    x = stk[-1]
    if not visited[x]:
        visited[x] = 1
        for y in G[x]:
            if not visited[y]:
                stk.append(y)
    else:
        x = stk.pop()
        F[x] = 1
        for y in G[x]:                
            F[x] += F[y]

DP = [0]*n
stk = [0]
visited = [0]*n

while stk:
    x = stk[-1]
    if not visited[x]:
        visited[x] = 1
        for y in G[x]:
            if not visited[y]:
                stk.append(y)
    else:
        x = stk.pop()
        DP[x] = F[x]
        for y in G[x]:
            DP[x] += DP[y]

ans = [0]*n
ans[0] = DP[0]
stk = [0]
Z = DP[0]

while stk:
    x = stk.pop()
    for y in G[x]:
        if not ans[y]:
            ay = ans[x] + n - 2 * F[y]
            ans[y] = ay 
            Z = max(Z,ay)
            stk.append(y)

print(Z)


5
1 2
1 3
2 4
2 5
 9
1 2
2 3
2 5
2 6
1 4
4 9
9 7
9 8
 2
1 2
 6
5 3
5 6
5 1
5 4
5 2
 7
7 5
7 3
7 6
7 4
7 1
7 2
 4
4 3
3 2
2 1
 4
2 1
1 3
3 4
 10
7 10
10 6
6 4
4 5
5 8
8 2
2 1
1 3
3 9
 9
9 4
4 6
6 2
2 1
1 3
3 5
5 8
8 7
 6
5 3
3 6
6 1
1 4
4 2
 5
2 1
2 3
2 4
2 5
 52
1 52
2 52
3 52
4 52
5 52
6 52
7 52
8 52
9 52
10 52
11 52
12 52
13 52
14 52
15 52
16 52
17 52
18 52
19 52
20 52
21 52
22 52
23 52
24 52
25 52
26 52
27 52
28 52
29 52
30 52
31 52
32 52
33 52
34 52
35 52
36 52
37 52
38 52
39 52
40 52
41 52
42 52
43 52
44 52
45 52
46 52
47 52
48 52
49 52
50 52
51 52
 4
1 3
1 4
1 2
 7
1 2
1 3
1 6
1 7
1 4
1 5
 6
1 5
5 4
4 2
2 6
6 3
 8
8 6
8 7
8 2
8 5
8 1
8 4
8 3
 10
5 6
6 7
7 3
7 8
7 4
7 2
7 1
7 10
7 9
 10
3 2
3 7
3 6
3 8
3 1
3 5
3 9
3 4
3 10
 5
1 4
4 2
2 3
3 5
 5
4 5
4 1
1 2
2 3
 8
6 2
2 1
1 8
8 5
5 7
7 3
3 4
 10
5 8
8 4
4 9
9 6
6 1
6 2
6 7
6 3
6 10
 9
3 2
3 1
3 8
3 5
3 6
3 9
3 4
3 7
 4
3 4
3 1
3 2
 8
6 2
6 1
6 8
6 5
6 7
6 3
6 4
 10
5 1
1 6
6 2
2 8
8 3
3 4
4 10
10 9
9 7
 6
4 5
4 1
4 6
4 2
4 3
 10
5 1
5 6
5 2
5 8
5 3
5 4
5 10
5 9
5 7
 10
8 2
8 10
10 3
2 4
3 6
8 1
2 7
10 9
4 5
 9
2 6
6 1
2 8
6 7
1 5
7 3
8 9
5 4
 7
7 6
7 5
7 2
7 1
5 4
5 3
 6
6 5
6 2
2 3
5 4
4 1
 8
6 3
3 7
6 1
1 2
3 5
5 4
2 8
 4
3 4
4 1
1 2
 9
1 6
6 4
4 5
5 9
9 8
8 7
7 3
3 2
 7
2 7
7 6
6 5
5 4
4 1
1 3
 10
4 10
10 5
5 1
1 6
6 8
8 9
9 2
9 3
9 7
 9
1 6
1 4
1 5
1 9
1 8
1 7
1 3
1 2
 7
1 2
2 3
3 6
6 7
7 4
4 5
 8
4 1
1 3
3 6
6 2
2 7
7 5
5 8
 5
1 4
4 3
3 2
2 5
 5
1 4
1 2
1 3
1 5
 4
2 1
2 3
3 4
 9
9 4
4 6
6 2
2 1
1 3
1 5
5 8
8 7
 52
1 52
2 52
3 18
4 52
5 52
6 52
7 52
8 52
9 52
10 52
11 52
12 52
13 52
14 52
15 52
16 52
17 52
18 52
19 52
20 52
21 52
22 52
23 52
24 52
25 52
26 52
27 52
28 52
29 52
30 52
31 52
32 52
33 52
34 52
35 52
36 52
37 52
38 52
39 52
40 52
41 52
42 52
43 52
44 52
45 52
46 52
47 52
48 52
49 52
50 52
51 52
 10
5 8
8 4
4 6
9 6
6 1
6 2
6 7
6 3
6 10
 10
5 1
1 10
6 2
2 8
8 3
3 4
4 10
10 9
9 7
 10
5 1
5 6
4 2
5 8
5 3
5 4
5 10
5 9
5 7
 8
6 3
3 7
6 1
1 2
3 5
6 4
2 8
 9
1 6
6 4
4 5
5 9
9 8
4 7
7 3
3 2
 10
4 10
10 5
5 1
1 6
6 8
8 9
9 2
2 3
9 7
 7
1 2
2 3
3 6
6 7
7 4
1 5
 8
4 2
1 3
3 6
6 2
2 7
7 5
5 8
 5
1 2
1 3
2 4
4 5
 10
4 10
10 5
5 2
1 6
6 8
8 9
9 2
2 3
9 7
 7
1 2
2 6
3 6
6 7
7 4
1 5
 10
4 10
10 8
5 2
1 6
6 8
8 9
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3
5 6
5 1
2 4
5 2
 4
2 3
2 4
1 2
 10
5 8
8 4
4 9
9 6
6 1
5 2
2 7
6 3
6 10
 10
9 1
7 6
5 2
5 8
5 3
5 4
5 10
5 9
5 7
 9
1 2
2 3
1 5
3 6
1 4
4 9
9 7
9 8
 10
5 1
8 4
4 9
9 6
6 1
8 2
2 7
6 3
6 10
 8
4 2
1 3
3 6
6 2
4 7
7 5
1 8
 6
5 3
5 6
5 1
5 4
4 2
 10
7 10
10 6
6 4
4 5
5 8
8 2
2 1
1 3
6 9

14 36 3 15 18 10 10 55 45 21 12 153 9 18 21 21 34 27 15 15 36 45 24 9 21 55 15 27 43 39 21 21 34 10 45 28 52 24 28 36 15 12 10
 42
 202
 40
 51
 34
 32
 39
 53
 28
 33
 15
 47
 26
 41
 45
 18
 46
 30
 19
 27
 49
 50
 52
 14
 9
 35
 43
 36
 44
 10
 15
 33
 34
 46
 39
 18
 42
 15
 10
 30
 26
 42
 14
 45
 28
 34
 14
 18
 9
 52
 35
 40
 50
 36
 18
 53
