mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, w): if w <= 0: return 0 x = 0 k = 1 << (self.size.bit_length() - 1) while k: if x + k <= self.size and self.tree[x + k] < w: w -= self.tree[x + k] x += k k >>= 1 return x + 1 # adj[0] must be empty list def EulerTour(adj, root): st = [root] ret = [] seen = [0] * len(adj) par = [0] * len(adj) depth = [0] * len(adj) while st: v = st.pop() if seen[v]: ret.append(v) continue ret.append(v) seen[v] = 1 if par[v] != 0: st.append(par[v]) for u in adj[v]: if seen[u] == 0: st.append(u) par[u] = v depth[u] = depth[v] + 1 return ret, depth N = int(input()) A = list(map(int, input().split())) adj = [[] for _ in range(N+1)] for i in range(N-1): v = i+2 p = A[i] + 1 adj[v].append(p) adj[p].append(v) et, depth = EulerTour(adj,1) bit = Bit(len(et)) cnt = [0] * (N+1) v_idx = [[] for _ in range(N+1)] for i, v in enumerate(et): cnt[v] += 1 v_idx[v].append(i+1) for i, v in enumerate(et): bit.add(i+1, 1 / cnt[v]) ans = 0 for v in range(1, N+1): ans += bit.sum(v_idx[v][-1]) - bit.sum(v_idx[v][0]-1) - 1 for i in v_idx[v]: bit.add(i, -1 / cnt[v]) print(round(ans)) if __name__ == '__main__': main()