#include <bits/stdc++.h>
using namespace std;
const int N = 15000;
int n, e;
vector<vector<int> > gt;
vector<set<int> > g;
vector<int> cyc;
void buildTrees() {
  queue<int> q;
  for (int i = 0; i < n; ++i)
    if (g[i].size() == 1) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    int v = *g[u].begin();
    gt[v].push_back(u);
    g[u].erase(v);
    g[v].erase(u);
    if (g[v].size() == 1) q.push(v);
  }
  for (int i = 0; i < n; ++i)
    if (g[i].size() == 2) {
      int u = i, p = -1;
      do {
        cyc.push_back(u);
        for (auto x : g[u])
          if (x != p) {
            p = u;
            u = x;
            break;
          }
      } while (u != i);
      break;
    }
}
int cost[N], sz[N];
void calc(int u) {
  sz[u] = 1;
  for (auto &v : gt[u]) {
    calc(v);
    sz[u] += sz[v];
    cost[u] += cost[v];
  }
  cost[u] += sz[u];
}
int srcCost[N];
int calcSC(int u, int size) {
  int &ret = srcCost[u];
  if (ret != -1) return ret;
  ret = size + 1;
  int all = 0;
  for (auto &v : gt[u]) all += cost[v];
  for (auto &v : gt[u])
    ret = max(ret, all - cost[v] + size + sz[u] - sz[v] +
                       calcSC(v, size + sz[u] - sz[v]));
  return ret;
}
int dp[2][N];
int main() {
  memset(srcCost, -1, sizeof(srcCost));
  scanf("%d", &n);
  g.resize(n);
  gt.resize(n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].insert(y);
    g[y].insert(x);
  }
  buildTrees();
  for (auto &u : cyc) calc(u);
  for (auto &u : cyc) calcSC(u, n - sz[u]);
  int oN = n;
  n = cyc.size();
  vector<int> cs(2 * n + 2);
  for (int i = 0; i <= 2 * n; ++i) cs[i + 1] = sz[cyc[i % n]] + cs[i];
  for (int i = 0; i < n; ++i)
    dp[1][i] = max(cost[cyc[i]] + oN - sz[cyc[i]], srcCost[cyc[i]]);
  for (int len = 2; len <= n; ++len)
    for (int i = 0; i < n; ++i)
      dp[1 & len][i] = max(dp[1 & ~len][i] + oN - (cs[i + len] - cs[i]) +
                               cost[cyc[(i + len - 1) % n]],
                           dp[1 & ~len][(i + 1) % n] + oN -
                               (cs[i + len] - cs[i]) + cost[cyc[i]]);
  cout << *max_element(dp[n & 1], dp[n & 1] + n) << endl;
  return 0;
}
