#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};


vector<int> G[1<<17];

const int M_V=100001;
const int logV=21;

int parent[logV][M_V];
int depth[M_V];

void dfs(int v,int p,int d){
    parent[0][v]=p;
    depth[v]=d;
    for(int i=0;i<G[v].size();i++){
        if(G[v][i]!=p) dfs(G[v][i],v,d+1);
    }
}

void init(int V,int root){
    dfs(root,-1,0);
    for(int k=0;k<logV-1;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<logV;k++){
        if((depth[v]-depth[u])>>k&1){
            v=parent[k][v];
        }
    }
    if(u==v) return u;
    for(int k=logV-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;cin >> n;
    for (int i = 1; i < n; i++) {
        int p;cin>>p;p--;
        G[i].pb(p);
        G[p].pb(i);
    }
    init(n,0);
    priority_queue<pair<P,int>> q;
    LL ans = 0;
    int bv = 0;
    q.push(mp(mp(0,0),0));
    map<int,int> ma;
    int cnt = 0;
    while(!q.empty()){
        auto p = q.top();q.pop();
        int d = -p.first.first, par = ma[-p.first.second], v = -p.second;
        ans += depth[v] + depth[bv] - 2*depth[lca(v,bv)];
        ma[cnt] = v;
        for(auto g:G[v]){
            if(g==par) continue;
            q.push(mp(mp(-(d+1),-cnt),-g));
        }
        cnt++;
        bv = v;
    }
    cout << ans << endl;
    return 0;
}


