import sys sys.setrecursionlimit(10**7) from functools import lru_cache n = int(input()) li = [0]*n ab = [[] for i in range(n)] exit() for i in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 ab[a].append(b) li[b] = 1 for i in range(n): if li[i] == 0: idx = i break num = [0]*n def dfs(v): if num[v] != 0: return num[v] for i in range(len(ab[v])): num[v] += dfs(ab[v][i]) num[v] += 1 return num[v] dfs(idx) exit() dp = [-1]*n @lru_cache(maxsize=n+1) def dfs2(v): if dp[v] != -1: return dp[v] for i in range(len(ab[v])): dp[v] += dfs2(ab[v][i])+num[ab[v][i]] dp[v] += 1 return dp[v] dfs2(idx) print(sum(dp))