#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<iostream>
using namespace std;
#define N 100001
vector<int>ljb[N];
typedef vector<int>::iterator ITER;
typedef long long ll;
queue<int>q;
int n,anss[N];
ll ans;
int fa[N],dep[N],top[N],son[N],siz[N];
void dfs(int U)
{
    siz[U]=1;
    for(ITER it=ljb[U].begin();it!=ljb[U].end();++it)
      {
        dep[*it]=dep[U]+1;
        dfs(*it);
        siz[U]+=siz[*it];
        if(siz[*it]>siz[son[U]])
          son[U]=(*it);
      }
}
void df2(int U)
{
    if(son[U])
      {
        top[son[U]]=top[U];
        df2(son[U]);
      }
    for(ITER it=ljb[U].begin();it!=ljb[U].end();++it)
      if((*it)!=son[U])
        {
          top[*it]=(*it);
          df2(*it);
        }
}
int lca(int U,int V)
{
    while(top[U]!=top[V])
      {
        if(dep[top[U]]<dep[top[V]])
          swap(U,V);
        U=fa[top[U]];
      }
    if(dep[U]>dep[V])
      swap(U,V);
    return U;
}
int calc(int U,int V)
{
    return dep[U]+dep[V]-(dep[lca(U,V)]<<1);
}
int main()
{
	//freopen("g.in","r",stdin);
	int x;
	scanf("%d",&n);
	for(int i=2;i<=n;++i)
	  {
	  	scanf("%d",&x);
	  	fa[i]=x;
	  	ljb[x].push_back(i);
	  }
	top[1]=1;
    dfs(1);
    df2(1);
	q.push(1);
	while(!q.empty())
	  {
	  	int U=q.front();
	  	for(ITER it=ljb[U].begin();it!=ljb[U].end();++it)
	  	  {
	  	  	anss[*it]=calc(q.back(),*it);
	  	  	q.push(*it);
	  	  }
	  	q.pop();
	  }
	for(int i=2;i<=n;++i)
	  ans+=(ll)anss[i];
	cout<<ans<<endl;
	return 0;
}