#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
#define LL long long
vector<int>G[MAXN];
int N;
vector<int>dep[MAXN];
bool vis[MAXN];
int maxdepth;
int depth[MAXN],fa[MAXN],cost[MAXN];
int sumcost[MAXN][20],anc[MAXN][20];
int order[MAXN];
queue<int>q;

void bfs() {
    memset(vis,false,sizeof(vis));
    while (!q.empty()) q.pop();
    q.push(1);
    fa[0] = -1;
    depth[1] = 0;
    cost[1] = 0;
    maxdepth = 0;
    vis[1] = true;
    dep[0].push_back(1);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int i = 0 ; i < (int)G[u].size() ; i++) {
            int v = G[u][i];
            if (vis[v]) continue;
            vis[v] = true;
            cost[v] = 1;
            depth[v] = depth[u] + 1;
            maxdepth = max(maxdepth,depth[u] + 1);
            dep[depth[v]].push_back(v);
            fa[v] = u;
            q.push(v);
        }
    }
}

void preprocess()
{
    memset(sumcost,0,sizeof(sumcost));
    for (int i = 1 ; i <= N ; i++)
    {
        anc[i][0] = fa[i];
        sumcost[i][0] = cost[i];
        for (int j = 1 ; (1 << j) <= N ; j++) anc[i][j] = -1;
    }
    for (int j = 1 ; (1 << j) <= N ; j++)
    {
        for (int i = 1 ; i <= N ; i++)
        {
            if (anc[i][j - 1] != -1)
            {
                int a = anc[i][j - 1];
                anc[i][j] = anc[a][j - 1];
                sumcost[i][j] = sumcost[i][j - 1] + sumcost[a][j - 1];
            }
        }
    }
}

int query(int p,int q)
{
    int tmp,log;
    if (depth[p] < depth[q]) swap(p,q);
    for (log = 1 ; (1 << log) <= depth[p] ; log++); log--;
    int ans = 0;
    for (int i = log ; i >= 0 ; i--)
    {
        if (depth[p] - (1 << i) >= depth[q])
        {
            ans += sumcost[p][i];
            p = anc[p][i];
        }
    }
    if (p == q) return ans;
    for (int i = log ; i >= 0 ; i--)
    {
        if (anc[p][i] != -1 && anc[p][i] != anc[q][i])
        {
            ans += sumcost[p][i]; p = anc[p][i];
            ans += sumcost[q][i]; q = anc[q][i];
        }
    }
    ans += cost[p];
    ans += cost[q];
    return ans;
}


int main() {
    scanf("%d",&N);
    for (int i = 2 ; i <= N ; i++) {
        int x;
        scanf("%d",&x);
        G[x].push_back(i);
    }
    bfs();
    for (int i = 0 ; i <= maxdepth ; i++) sort(dep[i].begin(),dep[i].end());
    int cnt = 0;
    order[cnt++] = 1;
    preprocess();
    memset(vis,false,sizeof(vis));  while (!q.empty()) q.pop();
    vis[1] = true;
    q.push(1);
    for (int i = 0 ; i < (int)dep[1].size() ; i++) {q.push(dep[1][i]);}
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int i = 0 ; i < (int)G[u].size() ; i++) {
            int v = G[u][i];
            if (vis[v]) continue;
            vis[v] = true;
            order[cnt++] = v;
            q.push(v);
        }
    }
   // for (int i = 0 ; i < cnt ; i++) printf("%d ",order[i]); puts("");
    LL ans = 0;
    for (int i = 1 ; i < cnt ; i++) ans += query(order[i - 1],order[i]);
    cout << ans << endl;
    return 0;
}