#include using namespace std; #define int long long #define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++) #define all(x) (x).begin(),(x).end() #define pb push_back templatebool chmax(T &a,T b){if(abool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;} typedef pair pii; typedef vector vi; typedef vector vvi; const int inf = 1LL<<60; const int mod = 1e9 + 7; const double eps = 1e-9; /*{ }*/ template class BinaryIndexedTree { public: int n; vector bit; BinaryIndexedTree():n(-1){} BinaryIndexedTree(int n_):n(n_),bit(n_+1,0){} BinaryIndexedTree(int n_, T d):n(n_),bit(n_+1,d){} T sum(int i) { T s = 0; while(i > 0){ s += bit[i]; i -= i&-i; } return s; } void add(int i, T x) { if(i == 0) return; while(i <= n){ bit[i] += x; i += i&-i; } } T sum0(int i) { return sum(i+1); } void add0(int i, T x) { add(i+1, x); } T query(int l, int r) { return sum(r-1)-sum(l-1); } T query0(int l, int r) { return sum(r)-sum(l); } }; int n; vi g[200000]; BinaryIndexedTree bit; int ans; void dfs(int v) { ans += bit.query0(0, v); bit.add0(v, 1); for(int to : g[v]){ dfs(to); } bit.add0(v, -1); } signed main() { cin >> n; rep(i, 1, n){ int a; cin >> a; g[a].pb(i); } bit = BinaryIndexedTree(n); dfs(0); cout << ans << endl; return 0; }