#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
long long n;
long long head[N], a[N];
struct node {
  long long v, nex;
} bian[N << 1];
long long cnt;
void add(long long x, long long y) {
  bian[++cnt].v = y;
  bian[cnt].nex = head[x];
  head[x] = cnt;
}
long long siz[N], d[N], f[N], g[N], zong;
void dfs(long long x, long long fa) {
  siz[x] = 1;
  for (long long i = head[x]; i; i = bian[i].nex) {
    long long v = bian[i].v;
    if (v == fa) continue;
    dfs(v, x);
    siz[x] += siz[v];
    f[x] += f[v];
  }
  f[x] += siz[x];
}
long long ans = 0;
void dp(long long x, long long fa) {
  ans = max(ans, f[x] + g[x] + n - siz[x]);
  long long tmp = 0;
  for (long long i = head[x]; i; i = bian[i].nex)
    if (bian[i].v != fa) tmp += f[bian[i].v];
  for (long long i = head[x]; i; i = bian[i].nex) {
    long long v = bian[i].v;
    if (v == fa) continue;
    g[v] += g[x] + tmp - f[v];
    g[v] += n - siz[v];
    dp(v, x);
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    add(x, y), add(y, x);
  }
  dfs(1, 0);
  dp(1, 0);
  cout << ans << endl;
}

### Prompt

Please formulate a CPP solution to the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
long long n;
long long head[N], a[N];
struct node {
  long long v, nex;
} bian[N << 1];
long long cnt;
void add(long long x, long long y) {
  bian[++cnt].v = y;
  bian[cnt].nex = head[x];
  head[x] = cnt;
}
long long siz[N], d[N], f[N], g[N], zong;
void dfs(long long x, long long fa) {
  siz[x] = 1;
  for (long long i = head[x]; i; i = bian[i].nex) {
    long long v = bian[i].v;
    if (v == fa) continue;
    dfs(v, x);
    siz[x] += siz[v];
    f[x] += f[v];
  }
  f[x] += siz[x];
}
long long ans = 0;
void dp(long long x, long long fa) {
  ans = max(ans, f[x] + g[x] + n - siz[x]);
  long long tmp = 0;
  for (long long i = head[x]; i; i = bian[i].nex)
    if (bian[i].v != fa) tmp += f[bian[i].v];
  for (long long i = head[x]; i; i = bian[i].nex) {
    long long v = bian[i].v;
    if (v == fa) continue;
    g[v] += g[x] + tmp - f[v];
    g[v] += n - siz[v];
    dp(v, x);
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    add(x, y), add(y, x);
  }
  dfs(1, 0);
  dp(1, 0);
  cout << ans << endl;
}

```