int head[MAXN] , to[MAXN << 1] , nex[MAXN << 1] , ecn = 0; voidade( int u , int v ){ to[++ecn] = v , nex[ecn] = head[u] , head[u] = ecn; }
int G[MAXN][18] , GG[MAXN][18]; ll t[MAXN][18] ; // G 2^k , GG 2^{k - 1} , t how many nodes at dep % 2^k = 2^k - 1 int siz[MAXN]; voiddfs( int u , int fa ){ siz[u] = 1; for( int i = head[u] ; i ; i = nex[i] ) { int v = to[i]; if( v == fa ) continue; G[v][0] = u , GG[v][0] = v; for( int k = 1 ; k < 18 ; ++ k ) { if( G[G[v][k-1]][k-1] ) G[v][k] = G[G[v][k-1]][k-1]; if( G[GG[v][k-1]][k-1] ) GG[v][k] = G[GG[v][k-1]][k-1]; elsebreak; } dfs( v , u ); siz[u] += siz[v]; } for( int k = 1 ; k < 18 ; ++ k ) { if( G[u][k] ) t[G[u][k]][k] += t[u][k]; if( GG[u][k] ) ++ t[GG[u][k]][k]; elsebreak; } } ll res = 0; ll T[MAXN]; ll solve( int u , int fa ){ ll R = 0 , ret = 0; for( int i = head[u] ; i ; i = nex[i] ) { int v = to[i]; if( v == fa ) continue; R = 0; ll lst = solve( v , u ); R += lst + siz[v]; R -= T[v]; res += R * ( siz[u] - siz[v] ); ret += R; } return ret; }
signedmain( ){ n = read(); for( int i = 1 , u , v ; i < n ; ++ i ) { u = read() , v = read(); ade( u , v ) , ade( v , u ); } dfs( 1 , 1 ); for( int i = 1 ; i <= n ; ++ i ) for( int k = 1 ; k < 18 ; ++ k ) T[i] += t[i][k]; solve( 1 , 1 ); printf("%lld",res); }