#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 2;
int n, root = 1;
struct Edge {
  int to, nxt;
};
Edge edge[maxn << 1];
int cnt, head[maxn];
void addedge(int u, int v) {
  cnt++;
  edge[cnt].to = v;
  edge[cnt].nxt = head[u];
  head[u] = cnt;
}
int siz[maxn];
void dfs(int u, int fa) {
  siz[u] = 1;
  for (int i = head[u]; ~i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
}
int pos;
long long dp[maxn];
void DP(int u, int fa) {
  if (dp[u] > dp[pos]) pos = u;
  for (int i = head[u]; ~i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fa) continue;
    dp[v] = dp[u] + 1LL * (siz[u] - siz[v]) * siz[v];
    DP(v, u);
  }
}
void init() {
  cnt = 0;
  memset(head, -1, sizeof(head));
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  dfs(root, -1);
  dp[root] = 1LL * n * (n - 1) >> 1;
  DP(root, -1);
  dfs(pos, -1);
  dp[pos] = 1LL * n * (n - 1) >> 1;
  DP(pos, -1);
  printf("%I64d", dp[pos]);
  return 0;
}
