#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && (c != '-')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int N = 3e4 + 10;
int n;
vector<int> e[N];
int cnt, p[N], fa[N], vis[N];
bool flag[N];
inline void dfs(int u) {
  vis[u] = 1;
  for (auto v : e[u]) {
    if (v == fa[u]) continue;
    fa[v] = u;
    if (!vis[v])
      dfs(v);
    else {
      for (int now = u; now != v; now = fa[now]) flag[p[++cnt] = now] = 1;
      flag[p[++cnt] = v] = 1;
    }
    if (cnt) break;
  }
}
long long f[N], g[N], siz[N];
inline void dfs(int u, int fa) {
  siz[u] = 1;
  for (auto v : e[u]) {
    if (v == fa || flag[v]) continue;
    dfs(v, u), f[u] += g[v], siz[u] += siz[v];
  }
  g[u] = f[u] + siz[u];
}
long long dp[N], last[N], pre[N], ans;
inline void dfs(int u, int fa, long long sum) {
  ans = max(ans, sum + n + f[u]);
  for (auto v : e[u])
    if (v != fa) dfs(v, u, sum + n - siz[v] + f[u] - g[v]);
}
inline void solve() {
  long long sum = 0;
  for (register int i = (1); i <= (cnt * 2); i++)
    last[i] = siz[p[i]], pre[i] = pre[i - 1] + last[i], sum += f[p[i]];
  for (register int i = (2); i <= (cnt - 1); i++) {
    for (register int l = (1); l <= (cnt * 2 - i + 1); l++) {
      int r = l + i - 1;
      long long tmp = pre[r] - pre[l - 1];
      dp[l] = max(last[l] + tmp, last[l + 1] + tmp);
    }
    for (register int j = (1); j <= (cnt * 2 - i + 1); j++) last[j] = dp[j];
  }
  ans = 0;
  for (register int i = (1); i <= (cnt); i++) {
    ans = max(ans, n + sum / 2 + dp[i + 1]);
    for (auto v : e[p[i]])
      if (!flag[v])
        dfs(v, p[i],
            n - siz[v] + sum / 2 - f[p[i]] + f[p[i]] - g[v] + dp[i + 1]);
  }
  printf("%lld\n", ans);
}
int main() {
  n = read();
  for (register int i = (1); i <= (n); i++) {
    int x = read() + 1, y = read() + 1;
    e[x].push_back(y), e[y].push_back(x);
  }
  dfs(1);
  for (register int i = (1); i <= (cnt); i++) dfs(p[i], 0);
  for (register int i = (1); i <= (cnt); i++) p[cnt + i] = p[i];
  solve();
}
