#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
long long ans = 0, cnt[MAXN], n, dp[MAXN];
vector<int> Mat[MAXN];
long long ch(long long a) { return a * (a - 1) / 2; }
void dfs(int v, int p) {
  vector<pair<int, int> > vc;
  for (int i = 0; i < Mat[v].size(); i++)
    if (Mat[v][i] != p) {
      dfs(Mat[v][i], v);
      vc.push_back({cnt[Mat[v][i]], Mat[v][i]});
      cnt[v] += cnt[Mat[v][i]];
    }
  cnt[v]++;
  dp[v] = 1e15;
  for (int i = 0; i < Mat[v].size(); i++)
    if (Mat[v][i] != p) {
      dp[v] = min(dp[v], ch(cnt[v] - cnt[Mat[v][i]]) + dp[Mat[v][i]]);
      ans = max(ans, ch(n) * 2 - ch(n - cnt[Mat[v][i]]) - dp[Mat[v][i]]);
    }
  dp[v] = min(dp[v], ch(cnt[v]));
  sort(vc.begin(), vc.end());
  reverse(vc.begin(), vc.end());
  if (vc.size() > 1)
    ans = max(ans, ch(n) * 2 - dp[vc[0].second] - dp[vc[1].second] -
                       ch(n - vc[0].first - vc[1].first));
  for (int i = 0; i < vc.size(); i++)
    if (vc[i].first >= n / 200 - 10 || i < 10)
      for (int j = i + 1; j < vc.size(); j++)
        ans = max(ans, ch(n) * 2 - dp[vc[i].second] - dp[vc[j].second] -
                           ch(n - vc[i].first - vc[j].first));
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    Mat[a].push_back(b);
    Mat[b].push_back(a);
  }
  ans = ch(n);
  dfs(1, 1);
  cout << ans;
}
