#include #include using namespace std; using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; typedef long long ll; typedef pair P; typedef tuple T; templatebool chmax(T& a, const T& b) { if (a < b) { a = b;return true; } else { return false; } } templatebool chmin(T& a, const T& b) { if (a > b) { a = b;return true; } else { return false; } } const int di[] = { -1,0,1,0 }; const int dj[] = { 0,-1,0,1 }; const long long INF = 9223372036854775807; const int inf = 1001001001; int op(int a, int b) { return a + b; } int e() { return 0; } int main(void) { int n; cin >> n; vector> g(n); for (int i = 0; i < n - 1; i++) { int a; cin >> a; g[a].push_back(i + 1); } segtree seg(n); ll ans = 0; auto dfs = [&](auto dfs, int pos)->void { //cout << pos << "\n"; ans += seg.prod(0, pos); seg.set(pos, 1); for (auto x : g[pos]) { dfs(dfs, x); //seg.set(x, 0); } seg.set(pos, 0); }; dfs(dfs, 0); cout << ans << "\n"; } //overflow,out_of_range