#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> e[500000];
long long sz[500000];
long long a[500000];
long long res1;
void dfs(int u, int p) {
  map<long long, vector<long long>> m;
  sz[u] = 1;
  for (int v : e[u]) {
    if (v == p) continue;
    dfs(v, u);
    sz[u] += sz[v];
    m[sz[v]].push_back(a[v]);
  }
  for (int v : e[u]) {
    if (v == p) continue;
    a[u] = max(a[u], a[v] + sz[v] * (sz[u] - sz[v]));
  }
  vector<pair<long long, long long>> v;
  for (auto it = m.begin(); it != m.end(); ++it) {
    sort(it->second.rbegin(), it->second.rend());
    v.emplace_back(it->first, it->second.front());
    if (it->second.size() > 1) v.emplace_back(it->first, it->second[1]);
  }
  if (v.size() == 1) res1 = max(res1, v.back().first + v.back().second);
  for (int i = 0; i < v.size(); ++i)
    for (int j = i + 1; j < v.size(); ++j) {
      res1 = max(res1,
                 v[i].second + v[j].second + v[i].first * v[j].first +
                     (v[i].first + v[j].first) * (n - v[i].first - v[j].first));
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  dfs(0, -1);
  cout << res1 + ((long long)n) * ((long long)n - 1) / 2 << "\n";
}
