// Slower C++ solution:
#include <cstdio>

#include <iostream>

#include <algorithm>

#include <cmath>

#include <queue>

#include <cstdlib>

#include <cstring>

#include <vector>

#include <set>

#include <map>

using namespace std;

#define ll long long

#define maxn 100005

vector<int> tree[maxn];

vector<int> query[maxn];

int father[maxn];

int depth[maxn];

ll ans = 0;

int findSet(int x)//路径??

{

	if (x == father[x])

		return x;

	else

		return father[x] = findSet(father[x]);

}

void unionSet(int x, int y)//把y并到x中去

{

	int fx = findSet(x);

	int fy = findSet(y);

	if (fy == fx)

		return;

	father[fy] = fx;

}

void bfs()

{

	queue<int> Q;

	Q.push(1);

	int last = 0;

	int t;

	while (!Q.empty())

	{

		t = Q.front();

		if (last != 0)

		{

			query[last].push_back(t);

		}

		last = t;

		Q.pop();

		for (unsigned int i = 0; i < tree[t].size(); ++i)

		{

			Q.push(tree[t][i]);

		}

	}

}

void Tarjan_LCA(int u)

{

	father[u] = u;

	int t;

	for (unsigned int i = 0; i < tree[u].size(); ++i)

	{

		t = tree[u][i];

		depth[t] = depth[u] + 1;

		Tarjan_LCA(t);

		unionSet(u, t);

	}

	for (unsigned int i = 0; i < query[u].size(); ++i)

	{

		t = query[u][i];

		if (father[t] != 0)

		{

			//printf("sum %d %d\n", u, t);

			ans += (ll)depth[u] + (ll)depth[t] - 2 * (ll)depth[findSet(t)];

		}

		else

		{

			query[t].push_back(u);

		}

	}

}

int main()

{

	//freopen("input.txt", "r", stdin);

	//freopen("output.txt", "w", stdout);

	int n;

	scanf("%d", &n);

	int tmp;

	for (int i = 2; i <= n; ++i)

	{

		scanf("%d", &tmp);

		tree[tmp].push_back(i);

	}

	bfs();

	/*for (int i = 1; i <= n; ++i)

	{

		for (unsigned int j = 0; j < query[i].size(); ++j)

			printf("%d ", query[i][j]);

		printf("\n");

	}*/

	Tarjan_LCA(1);

	/*for (int i = 1; i <= n; ++i)

		printf("%d ", depth[i]);

	printf("\n");*/

	printf("%lld\n", ans);

	//system("pause");

	//while (1);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.799467620493059x):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <algorithm>

#include <set>

using namespace std;

typedef long long ll;

typedef unsigned long long Ull;

#define MM(a,b) memset(a,b,sizeof(a));

const double eps = 1e-10;

const int  inf =0x7f7f7f7f;

const double pi=acos(-1);

const int maxn=100000+10;

int c[maxn][22],deep[maxn],vis[maxn];

vector<vector<int> > G(maxn);



void dfs(int u,int par)

{

    c[u][0]=par;

    for(int i=1;i<=20;i++) c[u][i]=c[c[u][i-1]][i-1];

    for(int i=0;i<G[u].size();i++)

    {

        int v=G[u][i];

        if(v==par) continue;

        deep[v]=deep[u]+1;

        dfs(v,u);

    }

}



int lca(int u,int v)

{

    if(deep[u]<deep[v]) swap(u,v);

    for(int i=20;i>=0;i--)

      if(deep[c[u][i]]>=deep[v])

          u=c[u][i];

    if(u==v) return u;

    for(int i=20;i>=0;i--)

    if(c[u][i]^c[v][i])

    {

        u=c[u][i];

        v=c[v][i];

    }

    return c[u][0];

}



int dis(int u,int v)

{

    /* printf("u:%d deep[u]:%d\n",u,deep[u]);

     printf("v:%d deep[v]:%d\n",v,deep[v]);

     printf("lca:%d deeplca:%d\n",lca(u,v),deep[lca(u,v)]);

     printf("dis:%d\n",deep[u]+deep[v]-2*deep[lca(u,v)]);

     printf("\n");

     */

     return deep[u]+deep[v]-2*deep[lca(u,v)];

}



int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=1;i<=n;i++) G[i].clear();

        deep[1]=0;

        for(int i=2;i<=n;i++)

        {

            int x;scanf("%d",&x);

            G[x].push_back(i);

        }

        dfs(1,1);

       // for(int i=1;i<=n;i++)

        //   printf("deep:%d %d\n",i,deep[i]);

       //for(int i=1;i<=n;i++)

        //  for(int j=1;j<=n;j++)

         //    printf("ww%d %d %d\n",i,j,dis(i,j));



        int pre=1;ll ans=0;

        queue<int> q;

        q.push(1);

        while(q.size())

        {

            int u=q.front();q.pop();

            for(int i=0;i<G[u].size();i++)

            {

                 int v=G[u][i];

                 ans+=dis(pre,v);

                 pre=v;

                 q.push(v);

            }

        }

        printf("%lld\n",ans);

    }

    return 0;

}