#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int n, sz[N], rt = 1;
vector<int> e[N];
long long ans, f[N];
void dfs(int u, int ff) {
  sz[u] = 1;
  for (auto v : e[u])
    if (v != ff) dfs(v, u), sz[u] += sz[v];
}
void solve(int u, int ff) {
  for (auto v : e[u])
    if (v != ff) f[v] = f[u] + (long long)(sz[u] - sz[v]) * sz[v], solve(v, u);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i < n; i++)
    scanf("%d%d", &x, &y), e[x].push_back(y), e[y].push_back(x);
  dfs(1, 0);
  solve(1, 0);
  for (int i = 2; i <= n; i++)
    if (f[rt] < f[i]) rt = i;
  dfs(rt, 0), f[rt] = (long long)n * (n - 1) / 2, solve(rt, 0);
  for (int i = 1; i <= n; i++)
    if (ans < f[i]) ans = f[i];
  printf("%I64d\n", ans);
  return 0;
}
