// Slower C++ solution:
#include <bits/stdc++.h>

 

using namespace std;

 

#define INF (1<<29)

#define MAX_V 100010

#define MAX_LOG_V 110

typedef long long ll;

 

vector<int> G[MAX_V];

int root;

int deg[MAX_V];

 

int parent[MAX_LOG_V][MAX_V];  

int depth[MAX_V];

 

void dfs(int v, int p, int d)

{

    parent[0][v] = p;

    depth[v] = d;

    for (int i = 0; i < (int)G[v].size(); i++) { 

    if(G[v][i] != p) {

        dfs(G[v][i], v, d+1);

    }

    }

}

 

void init(int V)

{

    root = 0;

    dfs(root, -1, 0);

    for (int k = 0; k + 1 < MAX_LOG_V; k++) {

    for (int v = 0; v < V; v++) {

        if (parent[k][v] < 0) {

        parent[k+1][v] = -1;

        } else {

        parent[k+1][v] = parent[k][parent[k][v]];

        }

    }

    }

}

 

int lca(int u, int v)

{

    if(depth[u] > depth[v]){

    swap(u, v);

    }

    for (int k = 0; k < MAX_LOG_V; k++) {

    if ((depth[v] - depth[u]) >> k & 1) {

        v = parent[k][v];

    }

    }

    if (u == v) {

        return u;

    }

    for (int k = MAX_LOG_V-1; k >= 0; k--) {

    if (parent[k][u] != parent[k][v]) {

        u = parent[k][u];

        v = parent[k][v];

    }

    }

    return parent[0][u];

}

 

int main()

{

    int n, p;

    cin >> n;

    for (int i = 0; i < n-1; i++) {

        cin >> p; --p;

        G[p].push_back(i+1);

    }

     

    queue<int> Q; Q.push(0);

    vector<ll> d(MAX_V, INF); d[0] = 0;

    vector<int> path; path.push_back(0);

    while (!Q.empty()) {

        int v = Q.front(); Q.pop();

        for (int i = 0; i < (int)G[v].size(); i++) {

            int to = G[v][i];

            if (d[v] + 1 < d[to]) {

                d[to] = d[v] + 1;

                Q.push(to);

                path.push_back(to);

            }

        }

    }

     

    init(n);

    

    ll res = 0;

    for (int i = 1; i < n; i++) {

        int l = lca(path[i-1], path[i]);

        res += d[path[i-1]] + d[path[i]] - 2*d[l];

    }

    cout << res << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.22991506489914x):
#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)

typedef long long ll;



int N;

vector< pair<int, int> > E[101010];



class LCA

{

public:

	int NV;

	int logNV;

	vector<int> D;

	vector<long long> L;

	vector<vector<int> > P;



	LCA(int N)

	{

		NV = N;

		logNV = 0;

		while (NV > (1LL << logNV)) logNV++;

		D = vector<int>(NV);

		L = vector<long long>(NV);

		P = vector<vector<int> >(logNV, vector<int>(NV));

	}



	void init()

	{

		dfs(0, -1, 0, 0);

		build();

	}



	void dfs(int v, int par, int d, long long l)

	{

		D[v] = d;

		P[0][v] = par;

		L[v] = l;



		for (int i = 0; i < (int)E[v].size(); i++) {

			int w = E[v][i].first;

			int lc = E[v][i].second;

			if (w == par) continue;

			dfs(w, v, d + 1, lc + l);

		}

	}



	void build() {

		for (int k = 0; k + 1 < logNV; k++) {

			for (int v = 0; v < NV; v++) {

				if (P[k][v] < 0) P[k + 1][v] = -1;

				else P[k + 1][v] = P[k][P[k][v]];

			}

		}

	}



	int query(int u, int v) {

		if (D[u] > D[v]) swap(u, v);

		for (int k = 0; k < logNV; k++) {

			if ((D[v] - D[u]) >> k & 1)

				v = P[k][v];

		}

		if (u == v) return u;



		for (int k = logNV - 1; k >= 0; k--) {

			if (P[k][u] != P[k][v]) {

				u = P[k][u];

				v = P[k][v];

			}

		}

		return P[0][u];

	}

};



int main()

{

	cin.tie(0);

	ios::sync_with_stdio(false);



	while (cin >> N)

	{

		if (N == 1)

		{

			cout << 0 << endl;

			continue;

		}

		rep(i, 0, N) E[i].clear();

		rep(i, 1, N)

		{

			int p; cin >> p; p--;

			E[p].push_back( make_pair(i, 1) );

			E[i].push_back( make_pair(p, 1) );

		}



		LCA lca(N);

		lca.init();



		ll ans = 0;



		queue<int> que;

		que.push(0);

		int prev = -1;

		while (!que.empty())

		{

			int p = que.front(); que.pop();

			for (auto _p : E[p])

			{

				int pp = _p.first;

				if (lca.L[p] < lca.L[pp]) que.push(pp);

			}



			if (0 <= prev)

			{

				ans += (ll)(lca.L[p] + lca.L[prev] - 2 * lca.L[lca.query(p, prev)]);

			}

			prev = p;

		}

		cout << ans << endl;

	}

}