#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const long long maxn = 5e5 + 10, maxm = 1e3 + 10, lg = 12, mod = 1e9 + 7,
                inf = 1e18;
long long C2(long long x) { return x * (x - 1) / 2; }
long long n, dp[maxn], mnm = inf, sz[maxn];
vector<long long> g[maxn];
void dfs(long long v = 1, long long p = 0) {
  sz[v] = 1;
  map<long long, long long> mn1, mn2;
  for (auto u : g[v])
    if (u != p) {
      dfs(u, v), sz[v] += sz[u];
      mn1[sz[u]] = mn2[sz[u]] = inf;
    }
  dp[v] = C2(sz[v]);
  for (auto u : g[v])
    if (u != p) {
      mnm = min(mnm, dp[u] + C2(n - sz[u]));
      dp[v] = min(dp[v], dp[u] + C2(sz[v] - sz[u]));
      mn2[sz[u]] = min(mn2[sz[u]], dp[u]);
      if (mn2[sz[u]] < mn1[sz[u]]) swap(mn1[sz[u]], mn2[sz[u]]);
    }
  vector<pair<long long, long long> > vv;
  for (auto x : mn1) vv.push_back(x);
  for (auto x : mn2) vv.push_back(x);
  for (int i = 0; i < (long long)(vv.size()); i++)
    for (int j = i + 1; j < (long long)(vv.size()); j++)
      mnm = min(
          mnm, C2(n - vv[i].first - vv[j].first) + vv[i].second + vv[j].second);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    long long v, u;
    cin >> v >> u;
    g[v].push_back(u), g[u].push_back(v);
  }
  dfs();
  cout << C2(n) * 2 - mnm << '\n';
  return 0;
}
