import sys sys.setrecursionlimit(10000000) MOD = 10 ** 9 + 7 INF = 10 ** 15 N = int(input()) G = [[] for _ in range(N)] deg = [0] * N for _ in range(N - 1): a,b = map(int,input().split()) a -= 1 b -= 1 G[a].append(b) deg[b] += 1 for i in range(N): if deg[i] == 0: root = i break dist = [-1] * N dist[root] = 0 ans = 0 def dfs(i): global ans cnt = 1 for e in G[i]: if dist[e] >= 0: continue dist[e] = dist[i] + 1 cnt += dfs(e) ans += cnt*dist[i] return cnt dfs(root) print(ans)