#include <bits/stdc++.h>
using namespace std;
vector<int> tr[200001];
int n, C, mxp[200001];
long long an;
int L;
pair<int, int> far;
bool fc(int v = 1, int p = 0, int d = 1) {
  if (d > far.first) far = make_pair(d, v);
  if (d == L) return true;
  for (int i = 0; i < (int)tr[v].size(); ++i) {
    int u = tr[v][i];
    if (u == p) continue;
    if (fc(u, v, d + 1)) {
      if (d == L + 1 >> 1) C = v;
      return true;
    }
  }
  return false;
}
int go(int v = C, int p = 0) {
  int &mx = mxp[v];
  mx = 1;
  for (int i = 0; i < (int)tr[v].size(); ++i)
    if (tr[v][i] != p) mx = max(mx, 1 + go(tr[v][i], v));
  an += mx + 1;
  return mx;
}
int main() {
  scanf("%d", &n);
  if (n == 2) printf("3\n"), exit(0);
  for (int i = 1; i < (int)n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    tr[a].push_back(b);
    tr[b].push_back(a);
  }
  fc();
  fc(far.second);
  L = far.first;
  fc(far.second);
  go();
  --an;
  vector<int> &v = tr[C];
  pair<int, int> mx = make_pair(0, 0);
  int mx2 = 0;
  for (int i = 0; i < (int)v.size(); ++i) {
    int u = v[i], z = mxp[u];
    if (z > mxp[mx.first])
      mx2 = mx.first, mx = make_pair(u, 1);
    else if (z == mxp[mx.first])
      ++mx.second;
    else if (z > mxp[mx2])
      mx2 = u;
  }
  if (mx2 && mx.second == 1) --an;
  printf("%lld\n", an);
}
