#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
vector<int> G[N];
int S[N];
int n;
long long sum, result;
void Dfs1(int v, int p) {
  S[v] = 1;
  for (int s : G[v])
    if (s != p) Dfs1(s, v), S[v] += S[s];
  sum += (long long)S[v];
}
void Dfs2(int v, int p) {
  result = max(result, sum);
  for (int s : G[v])
    if (s != p) {
      long long t = sum;
      sum += n - 2 * S[s];
      S[v] = n - S[s];
      S[s] = n;
      Dfs2(s, v);
      sum = t;
      S[s] = n - S[v];
      S[v] = n;
    }
}
void Read() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
}
void Solve() {
  Dfs1(1, 1);
  Dfs2(1, 1);
  printf("%lld", result);
}
int main() {
  Read();
  Solve();
  return 0;
}
