You are in charge of the BubbleReactor. It consists of N BubbleCores connected with N lines of electrical wiring. Each electrical wiring connects two distinct BubbleCores. There are no BubbleCores connected with more than one line of electrical wiring.

Your task is to start the BubbleReactor by starting each BubbleCore. In order for a BubbleCore to be started it needs to be receiving power from a directly connected BubbleCore which is already started. However, you can kick-start one BubbleCore manually without needing power. It is guaranteed that all BubbleCores can be started.

Before the BubbleCore boot up procedure its potential is calculated as the number of BubbleCores it can power on (the number of inactive BubbleCores which are connected to it directly or with any number of inactive BubbleCores in between, itself included)

Start the BubbleReactor so that the sum of all BubbleCores' potentials is maximum.

Input

First line contains one integer N (3 ≤ N ≤ 15.000), the number of BubbleCores.

The following N lines contain two integers U, V (0 ≤ U ≠ V < N) denoting that there exists electrical wiring between BubbleCores U and V.

Output

Single integer, the maximum sum of all BubbleCores' potentials.

Example

Input


10
0 1
0 3
0 4
0 9
1 2
2 3
2 7
4 5
4 6
7 8


Output


51

Note

If we start by kickstarting BubbleCup 8 and then turning on cores 7, 2, 1, 3, 0, 9, 4, 5, 6 in that order we get potentials 10 + 9 + 8 + 7 + 6 + 5 + 1 + 3 + 1 + 1 = 51
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2>
inline bool upmax(T1& a, T2 b) {
  return (a < b ? (a = b, true) : false);
}
template <typename T1, typename T2>
inline bool upmin(T1& a, T2 b) {
  return (b < a ? (a = b, true) : false);
}
const int maxn = (int)1e5 + 100;
const int maxlog = 21;
const int base = 1e9 + 7;
const long double eps = (long double)1e-9;
const long double PI = acos(-1.);
const int inf = 2e9;
const long long llinf = 2e18;
vector<int> g[maxn];
vector<int> st;
int used[maxn];
bool inc[maxn];
vector<int> cyc;
void dfs(int v, int p = -1) {
  used[v] = 2;
  st.push_back(v);
  for (auto to : g[v]) {
    if (to == p) continue;
    if (!used[to]) {
      dfs(to, v);
    } else if (used[to] == 2) {
      for (int i = st.size() - 1; st[i] != to; i--) {
        cyc.push_back(st[i]);
        inc[st[i]] = 1;
      }
      cyc.push_back(to);
      inc[to] = 1;
    }
  }
  st.pop_back();
  used[v] = 1;
}
long long sz[maxn], d[maxn], opt[maxn];
long long sumd[maxn];
int wh[maxn];
int root;
void dfs2(int v, int p = -1) {
  wh[v] = root;
  sumd[root] += d[v];
  sz[root] += 1;
  for (auto to : g[v]) {
    if (to == p) continue;
    if (inc[to]) continue;
    d[to] = d[v] + 1;
    dfs2(to, v);
  }
}
long long res = 0;
void dfs3(int v, int d, int p = -1) {
  res += d;
  for (auto to : g[v]) {
    if (to != p && wh[to] == wh[v]) dfs3(to, d + 1, v);
  }
}
long long dp[maxn][2];
long long pr[maxn];
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0);
  for (int i = 0; i < cyc.size(); i++) {
    root = cyc[i];
    d[root] = 1;
    opt[root] = n;
    dfs2(cyc[i]);
  }
  long long all = 0;
  for (int i = 0; i < n; i++) {
    if (!inc[i]) {
      res = 0;
      dfs3(i, 1);
      res += 1ll * d[i] * (n - sz[wh[i]]);
      upmax(opt[wh[i]], res);
    } else {
      all += sumd[i];
    }
  }
  for (int i = 0; i < cyc.size(); i++) {
    dp[i][0] = all - sumd[cyc[i]] + opt[cyc[i]];
    dp[i][1] = -1;
    pr[i] = sz[cyc[i]];
    pr[i + cyc.size()] = pr[i];
  }
  for (int i = 1; i < cyc.size() * 2; i++) {
    pr[i] += pr[i - 1];
  }
  for (int i = 0; i < cyc.size() - 1; i++) {
    dp[cyc.size()][0] = dp[0][0];
    for (int l = 0; l < cyc.size(); l++) {
      upmax(dp[l][1], max(dp[l][0], dp[l + 1][0]) + n - pr[l + i + 1] +
                          (l ? pr[l - 1] : 0));
    }
    for (int i = 0; i < cyc.size(); i++) {
      dp[i][0] = dp[i][1];
      dp[i][1] = -1;
    }
  }
  long long res = 0;
  for (int i = 0; i < cyc.size(); i++) {
    upmax(res, dp[i][0]);
  }
  cout << res;
  return 0;
}
