N = int(eval(input()))



ans = 0

for i in range(1, N + 1):

    ans += i * (N + 1 - i)



for i in range(N - 1):

    u, v = list(map(int, input().split()))

    u, v = min(u, v), max(u, v)

    ans -= (N - v + 1) * u



print(ans)

N,*t=list(map(int,open(0).read().split()))

t=iter(t)

print((N*(N+1)*(N+2)//6+sum([-min(a,b)*(N-max(a,b)+1) for a,b in zip(t,t)])))
N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
    ans += i * (N + 1 - i)
for i in range(N - 1):
    u, v = list(map(int, input().split()))
    u, v = min(u, v), max(u, v)
    ans -= (N - v + 1) * u
print(ans)

N, *t = list(map(int, open(0).read().split()))
t = iter(t)
print(
    (
        N * (N + 1) * (N + 2) // 6
        + sum([-min(a, b) * (N - max(a, b) + 1) for a, b in zip(t, t)])
    )
)

-N = int(eval(input())) -ans = 0 -for i in range(1, N + 1): -    ans += i * (N + 1 - i) -for i in range(N - 1): -    u, v = list(map(int, input().split())) -    u, v = min(u, v), max(u, v) -    ans -= (N - v + 1) * u -print(ans) +N, *t = list(map(int, open(0).read().split())) +t = iter(t) +print( +    ( +        N * (N + 1) * (N + 2) // 6 +        + sum([-min(a, b) * (N - max(a, b) + 1) for a, b in zip(t, t)]) +    ) +)