// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
class LCA{
	public:
	int N,root,max_log;
	vvi G,parent;
	vi depth;
	LCA(int size){
		N=size;
		G=vvi(size);
		max_log=20;
		depth=vi(size);
		parent=vvi(max_log,vi(size));
	}
	void add_edge(int a,int b){
		G[a].pb(b);
		G[b].pb(a);
	}
	void dfs(int v,int p,int d){
		parent[0][v]=p;
		depth[v]=d;
		rep(i,G[v].size())if(G[v][i]!=p)dfs(G[v][i],v,d+1);
	}
	void init(){
		root=0;
		dfs(root,-1,0);
		for(int k=0;k+1<max_log;k++){//doubling
			for(int v=0;v<N;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);
		rep(k,max_log)if((depth[v]-depth[u])>>k&1)v=parent[k][v];
		if(u==v)return u;
		for(int k=max_log-1;k>=0;k--){
			if(parent[k][u]!=parent[k][v]){
				u=parent[k][u];
				v=parent[k][v];
			}
		}
		return parent[0][u];
	}
};
int n;
vvi G;
vi dig;
void dfs(int a,int b){
	dig[b]=a;
	rep(i,G[b].size())dfs(a+1,G[b][i]);
}
signed main(){
	cin>>n;
	G=vvi(n);
	dig=vi(n);
	LCA lca(n);
	rep(i,n-1){
		int a;cin>>a;
		G[a-1].pb(i+1);
		lca.add_edge(a-1,i+1);
	}
	lca.init();
	dfs(0,0);
	rep(i,n)sort(all(G[i]));
	queue<int>que;
	que.push(0);
	vvi in;
	while(!que.empty()){
		int a=que.front();
		que.pop();
		in.pb({0,a});
		rep(i,G[a].size())que.push(G[a][i]);
	}
	
	int out=0;
	rep(i,n-1)out+=dig[in[i][1]]+dig[in[i+1][1]]-2*dig[lca.lca(in[i][1],in[i+1][1])];
	cout<<out<<endl;
}







