#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000 * 2001;
const long long INF = 1e18;
const long long mod = 998244353;
vector<long long> g[maxn], he[maxn];
long long h[maxn], par[maxn], leaf[maxn], dp[maxn];
long long mark[maxn];
void dfs(long long u) {
  he[h[u]].push_back(u);
  mark[u] = 1;
  for (long long i = 0; i < g[u].size(); i++)
    if (mark[g[u][i]] == 0) {
      par[g[u][i]] = u;
      h[g[u][i]] = h[u] + 1;
      dfs(g[u][i]);
    }
}
long long n, m, k;
int main() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  for (long long i = n; i >= 0; i--)
    for (long long j = 0; j < he[i].size(); j++) {
      long long v = he[i][j];
      if ((g[v].size() == 1) && (v != 1))
        leaf[v] = 1;
      else {
        for (long long ii = 0; ii < g[v].size(); ii++)
          if (g[v][ii] != par[v]) leaf[v] += leaf[g[v][ii]];
        leaf[v]++;
      }
    }
  for (long long i = 1; i <= n; i++) dp[1] += leaf[i];
  long long ans = dp[1];
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j < he[i].size(); j++) {
      long long v = he[i][j];
      dp[v] = dp[par[v]] + n - 2 * leaf[v];
      ans = max(ans, dp[v]);
    }
  cout << ans;
}
