import sys n = int(input()) g = [[] for _ in range(n)] is_child = [0]*n for i in range(n-1): a,b = map(int,sys.stdin.readline().split()) g[a-1].append(b-1) is_child[b-1] = 1 root = is_child.index(0) order = [] st = [root] parent = [-1]*n depth = [1]*n while st: v = st.pop() order.append(v) for c in g[v]: if c != parent[v]: st.append(c) parent[c] = v depth[c] = depth[v] + 1 size = [1]*n for i in order[::-1]: if i==root: break size[parent[i]] += size[i] ans = 0 for i in range(n): if i==root: continue ans += size[i]*depth[parent[i]] print(ans)