#include <bits/stdc++.h>
using namespace std;
int n;
int head[500005], cnt;
int size[500005];
long long f[500005], ans;
struct data {
  int next, to;
  data(int next = 0, int to = 0) : next(next), to(to) {}
} edge[500005 << 1];
int read() {
  char c = getchar();
  int x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
void connect(int u, int v) {
  edge[++cnt] = data(head[u], v);
  head[u] = cnt;
}
void DFS(int u, int pre) {
  size[u] = 1;
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == pre) continue;
    DFS(v, u);
    size[u] += size[v];
  }
  f[u] = 1ll * size[u] * (size[u] - 1) + 2ll * size[u] * (n - size[u]);
  int maxi = 0;
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == pre) continue;
    int r = size[u] - size[v], R = n - size[v];
    ans = max(ans, f[v] + 1ll * R * (R - 1) + 2ll * R * (n - R));
    R -= size[maxi];
    ans = max(ans, f[maxi] + f[v] + 1ll * R * (R - 1) + 2ll * R * (n - R));
    if (f[v] > f[maxi]) maxi = v;
    f[u] = max(f[u], f[v] + 1ll * r * (r - 1) + 2ll * r * (n - r));
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    connect(u, v);
    connect(v, u);
  }
  DFS(1, 0);
  printf("%I64d\n", ans / 2);
}
