#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> G[1000010];
long long f[1000010], d[1000010], son[1000010];
void dp(int x, int fa) {
  for (int i = 0; i < G[x].size(); i++) {
    int u = G[x][i];
    if (u == fa) continue;
    dp(u, x);
    son[x] += son[u];
  }
  son[x]++;
  for (int i = 0; i < G[x].size(); i++) {
    int u = G[x][i];
    if (u == fa) continue;
    f[x] += f[u];
  }
  f[x] += son[x];
}
void dfs(int x, int fa) {
  for (int i = 0; i < G[x].size(); i++) {
    int u = G[x][i];
    if (u == fa) continue;
    d[u] = d[x] + n - (son[u] << 1);
    dfs(u, x);
  }
}
int main() {
  scanf("%d", &n);
  int u, v;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dp(1, 0);
  d[1] = f[1];
  dfs(1, 0);
  long long ans = 0, flag;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, d[i]);
  }
  printf("%lld", ans);
  return 0;
}
