#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;

const int MaxN = 1000000+64;
int p[MaxN],siz[MaxN],top[MaxN],son[MaxN],dep[MaxN];
int anss[MaxN];
queue<int> que;
vector<int>edg[MaxN];
typedef vector<int>::iterator ITER;
int n;

void DFS(int x);
void DFS2(int x);
int get_dis(int u,int v);
int LCA(int u,int v);

int main(){
	scanf("%d",&n);
	for(int i = 2;i <= n;i++){
		scanf("%d",&p[i]);
		edg[p[i]].push_back(i);
	}
	top[1] = 1;
	DFS(1);
	DFS2(1);
	que.push(1);
	while(!que.empty()){
		int u = que.front();
		for(ITER it = edg[u].begin();it != edg[u].end();++it){
			anss[*it] = get_dis(que.back(),*it);
			que.push(*it);
		}
		que.pop();
	}
	long long ans = 0LL;
	for(int i = 2;i <= n;i++)
		ans += (long long)anss[i];
	printf("%lld\n",ans);
	return 0;
}

void DFS(int x){
	siz[x] = 1;
	for(ITER it = edg[x].begin();it != edg[x].end();++it){
		dep[*it] = dep[x]+1;
		DFS(*it);
		siz[x] += siz[*it];
		if(siz[son[x]] < siz[*it])  son[x] = (*it);
	}
}

void DFS2(int x){
	if(son[x]){
		top[son[x]] = top[x];
		DFS2(son[x]);
	}
	for(ITER it = edg[x].begin();it != edg[x].end();++it){
		if(son[x] != (*it)){
			top[*it] = (*it);
			DFS2(*it);
		}
	}
}

int get_dis(int u,int v){
	return dep[u]+dep[v]-(dep[LCA(u,v)]<<1);
}

int LCA(int u,int v){
	while(top[u] != top[v]){
		if(dep[top[u]] < dep[top[v]] )  swap(u,v);
		u = p[top[u]];
	}
	if(dep[u] > dep[v])  swap(u,v);
	return u;
}