from collections import defaultdict import sys sys.setrecursionlimit(10 ** 6) class FenwickTree: def __init__(self, n): self.data = [0] * (n + 10) def add(self, p, x): assert 0 <= p p += 1 while p < len(self.data): self.data[p] += x p += p & -p def sum(self, p): """区間 [0, p] の和""" assert 0 <= p p += 1 s = 0 while p > 0: s += self.data[p] p -= p & -p return s def rangesum(self, l, r): """区間 [l, r] の和""" assert 0 <= l <= r s = self.sum(r) if l > 0: s -= self.sum(l-1) return s N = int(input()) A = list(map(int, input().split())) adj = defaultdict(list) for i in range(N-1): par = A[i] adj[par].append(i+1) def dfs(v): res = ft.sum(v) ft.add(v, 1) for to in adj[v]: res += dfs(to) ft.add(v, -1) return res ft = FenwickTree(N) ans = dfs(0) print(ans)