N = int(input()) A = list(map(int,input().split())) A.insert(0,0) G = {i:[] for i in range(1,N+1)} for i in range(1,N): a = A[i]+1 G[a].append(i+1) k = 0 while 2**k0: tot += B[j] j -= j&(-j) return tot cnt = 0 def dfs(i): global cnt cnt += csum(i) update(i,1) for j in G[i]: dfs(j) update(j,-1) dfs(1) print(cnt)