#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const ll N=500005;
vll adj[N],v[N];
ll d[N],f[N],s[N];
ll n;
bool cmp(ll a,ll b)
{
return f[a]<f[b];
}
void dfs(ll x,ll pr)
{
s[x]=1;
for(auto i:adj[x])
if(i!=pr)
dfs(i,x);
for(auto i:adj[x])
if(i!=pr)
s[x]+=s[i];
d[x]=s[x]*s[x];f[x]=d[x];
for(auto i:adj[x])
if(i!=pr)
d[x]=min(d[x],d[i]+(s[x]-s[i])*(s[x]-s[i]));
f[x]+=d[x]-2*n*s[x];
for(auto i:adj[x])
if(i!=pr)
v[x].pb(i);
}
int main()
{
fastio;
#ifdef APNA_IO
start_routine();
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
cin>>n;
for(ll i=1;i<n;i++)
{
ll x,y;cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
}
dfs(1,1);ll ans=0;
for(ll i=1;i<=n;i++)
{
sort(v[i].begin(), v[i].end(),cmp);
if(v[i].size()==0) continue;
if(v[i].size()==1) ans=min(ans,f[i]);
if(v[i].size()>1)
{
ll x=v[i][0],y=v[i][1];
ll val=f[x]+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TwogICAgICAgIHN0YXJ0X3JvdXRpbmUoKTsKICAgICAgICBmcmVvcGVuKCJpbnB1dC50eHQiLCAicnQiLCBzdGRpbik7CiAgICAgICAgZnJlb3Blbigib3V0cHV0LnR4dCIsICJ3dCIsIHN0ZG91dCk7ICAgIAogICAgI2VuZGlmCgogICAgY2luPj5uOwogICAgZm9yKGxsIGk9MTtpPG47aSsrKQogICAgewogICAgICAgIGxsIHgseTtjaW4+Png+Pnk7CiAgICAgICAgYWRqW3hdLnBiKHkpOwogICAgICAgIGFkalt5XS5wYih4KTsKICAgIH0KCiAgICBkZnMoMSwxKTtsbCBhbnM9MDsKICAgIGZvcihsbCBpPTE7aTw9bjtpKyspCiAgICB7CiAgICAgICAgc29ydCh2W2ldLmJlZ2luKCksIHZbaV0uZW5kKCksY21wKTsKCiAgICAgICAgaWYodltpXS5zaXplKCk9PTApIGNvbnRpbnVlOwogICAgICAgIGlmKHZbaV0uc2l6ZSgpPT0xKSBhbnM9bWluKGFucyxmW2ldKTsKICAgICAgICBpZih2W2ldLnNpemUoKT4xKQogICAgICAgIHsKICAgICAgICAgICAgbGwgeD12W2ldWzBdLHk9dltpXVsxXTsKICAgICAgICAgICAgbGwgdmFsPWZbeF0rZlt5XSsyKnNbeF0qc1t5XTsKICAgICAgICAgICAgYW5zPW1pbihhbnMsdmFsKTsKICAgICAgICB9CiAgICB9CgogICAgbGwgdmFsPW4qKG4tMSk7CiAgICBjb3V0PDwodmFsLWFucykvMjsKCiAgICAjaWZkZWYgQVBOQV9JTwogICAgICAgIGVuZF9yb3V0aW5lKCk7ICAKICAgICNlbmRpZgp9CQ==