#include using namespace std; template struct BIT { int n; vector dat; BIT(int n=0){ initialize(n); } void initialize(int nin){ n = nin; dat.resize(n, 0); } T sum(int i){ T s = 0; while(i >= 0){ s += dat[i]; i = (i & (i+1)) - 1; } return s; } T sum_between(int i, int j){ return sum(j) - sum(i-1); } void plus(int i, T x){ while(i < n){ dat[i] += x; i |= i+1; } } // a[0]+...+a[ret] >= x int lower_bound(T x){ int ret = -1; int k = 1; while(2*k <= n) k <<= 1; for( ;k>0; k>>=1){ if(ret+k < n && dat[ret+k] < x){ x -= dat[ret+k]; ret += k; } } return ret + 1; } }; vector child[200000]; BIT bit(200000); int64_t ans = 0; void dfs(int i){ ans += bit.sum(i-1); bit.plus(i, 1); for(int j : child[i]) dfs(j); bit.plus(i, -1); } int main(){ int N; cin >> N; for(int i=1; i> a; child[a].push_back(i); } dfs(0); cout << ans << endl; return 0; }