#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const int lim = 100;
long long sz[N], dp[N];
vector<long long> node[N];
long long ans = 0;
void init(long long u, long long p) {
  sz[u] = 1;
  for (auto j : node[u]) {
    if (j == p) continue;
    init(j, u);
    sz[u] += sz[j];
    dp[u] += dp[j];
  }
  dp[u] += sz[u];
}
void ex(long long u, long long v) {
  dp[v] -= dp[u] + sz[u];
  sz[v] -= sz[u];
  dp[u] += dp[v] + sz[v];
  sz[u] += sz[v];
}
void dfs(long long u, long long p) {
  ans = max(ans, dp[u]);
  for (auto j : node[u]) {
    if (j == p) continue;
    ex(j, u);
    dfs(j, u);
    ex(u, j);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  if (fopen("A.inp", "r")) {
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
  }
  long long n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    node[u].push_back(v);
    node[v].push_back(u);
  }
  init(1, 1);
  dfs(1, 1);
  cout << ans;
}
