human
Solve in Python:
Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible improvements he can think of during the day (he now prefers to sleep at night). However, his assistants have found a solution and they now draw an imaginary city on a paper sheet and suggest the mayor can propose its improvements.

Right now he has a map of some imaginary city with $n$ subway stations. Some stations are directly connected with tunnels in such a way that the whole map is a tree (assistants were short on time and enthusiasm). It means that there exists exactly one simple path between each pair of station. We call a path simple if it uses each tunnel no more than once.

One of Sergey Semyonovich's favorite quality objectives is the sum of all pairwise distances between every pair of stations. The distance between two stations is the minimum possible number of tunnels on a path between them.

Sergey Semyonovich decided to add new tunnels to the subway map. In particular, he connected any two stations $u$ and $v$ that were not connected with a direct tunnel but share a common neighbor, i.e. there exists such a station $w$ that the original map has a tunnel between $u$ and $w$ and a tunnel between $w$ and $v$. You are given a task to compute the sum of pairwise distances between all pairs of stations in the new map.

-----Input-----

The first line of the input contains a single integer $n$ ($2 \leq n \leq 200\,000$) — the number of subway stations in the imaginary city drawn by mayor's assistants. Each of the following $n - 1$ lines contains two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \ne v_i$), meaning the station with these indices are connected with a direct tunnel.

It is guaranteed that these $n$ stations and $n - 1$ tunnels form a tree.

-----Output-----

Print one integer that is equal to the sum of distances between all pairs of...
 Give me a Python code to print one integer that is equal to the sum of distances between all pairs of?
assistant
#Here is Python code to print one integer that is equal to the sum of distances between all pairs of.

import sys
import threading
sys.setrecursionlimit(2100000)

def main():
    def counter(graph,vert,memo,pard=None):
        d = 0
        for c in graph[vert]:
            if c!=pard:
                if len(graph[c])==1:
                    memo[c]=0
                else:
                    memo[c]=counter(graph, c, memo, vert)[0]
                d += memo[c]+1
        return((d, memo))

    n=int(input())
    vizinhos=[]

    for _ in range(n):
        vizinhos.append([])

    for _ in range(n-1):
        i, j=map(int, input().split())
        vizinhos[i-1].append(j-1)
        vizinhos[j-1].append(i-1)

    same=1
    layer=[0]
    par=[None]
    j=0
    while layer:
        j+=1
        n_layer=[]
        n_pars=[]
        for i in range(len(layer)):
            for vert in vizinhos[layer[i]]:
                if vert!=par[i]:
                    n_layer.append(vert)
                    n_pars.append(layer[i])
        layer=n_layer
        par=n_pars
        if j%2==0:
            same+=len(layer)
    bipartite = same*(n-same)
    info=counter(vizinhos,0,[None]*n)[1]
    dist=0
    for g in info:
        if g!=None:
           dist += (g+1)*(n-g-1)
    print((dist+bipartite)//2)
 
threading.stack_size(140000000)
main_thread=threading.Thread(target=main)
main_thread.start()
main_thread.join()