#include <bits/stdc++.h>
using namespace std;
#define int long long
void dfs(int st, vector<int>g[], int sz[], int dp[], int p){
dp[st]=0;
sz[st]=1;
vector<int>sizes;
for(int i : g[st]){
if(i==p)
continue;
dfs(i,g,sz,dp,st);
sz[st]+=sz[i];
dp[st]+=dp[i];
sizes.push_back(sz[i]);
}
int pref=1;
for(int i = 0;i<sizes.size();i++){
//going from st
dp[st]+=sz[st]-pref;
pref+=sizes[i];
//for every edge in i sz[st]-pref gets added
dp[st]+=(sz[st]-pref)*2*(sizes[i]-1);
//returning to st
dp[st]+=sz[st]-pref;
}
}
int ans = 1e18;
void reroot(int st, vector<int>g[], int sz[], int dp[], int p){
ans=min(ans,dp[st]);
for(int i : g[st]){
if(i==p)
continue;
//sorting is actually unnecessary
int ovalst = dp[st];
int ovali = dp[i];
dp[st]-=sz[st]-1;
dp[st]-=dp[i];
dp[st]-=(sz[st]-1-sz[i])*2*(sz[i]-1);
dp[st]-=(sz[st]-1-sz[i]);
dp[i]+=sz[st]-1;
dp[i]+=(sz[i]-1)*2*(sz[st]-sz[i]-1);
dp[i]+=(sz[i]-1);
dp[i]+=dp[st];
int oszst = sz[st];
int oszi = sz[i];
sz[st]-=sz[i];
sz[i]+=sz[st];
reroot(i,g,sz,dp,st);
dp[st]=ovalst;
dp[i]=ovali;
sz[st]=oszst;
sz[i]=oszi;
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int>g[n];
for(int i = 0;i<n-1;i++){
int a,b;
cin >> a >> b;
a--;b--;
g[a].push_back(b);
g[b].push_back(a);
}
int sz[n];
int dp[n];
dfs(0,g,sz,dp,-1);
reroot(0,g,sz,dp,-1);
cout << ans;
return 0;
}