#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx") 

#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int P[MAXN][18],lvl[MAXN],n,in[MAXN],out[MAXN],TIM,pw[MAXN],vis[MAXN];
vector<int>adj[MAXN],level[MAXN],way[MAXN];
int LCA(int x,int y){
	if(lvl[x]<lvl[y])
		swap(x,y);
	for(int i=17;i>=0;i--)
		if(~P[x][i] and lvl[x]-(1<<i)>=lvl[y])
			x=P[x][i];	
	if(x==y)
		return x;	
	for(int i=17;i>=0;i--)
		if(~P[x][i] and P[x][i]!=P[y][i])
			x=P[x][i],y=P[y][i];
	return P[x][0];
}

void build(){
	for(int j=1;j<=17;j++)
		for(int i=1;i<=n;i++)
			if(~P[i][j-1])
				P[i][j]=P[P[i][j-1]][j-1];
}
void dfs(int nd){
	in[nd]=++TIM;
	tr(it,adj[nd])
		dfs(*it);
	out[nd]=TIM;	
}
int mod(ll x){
	while(x<0)	
		x+=INF;
	return (x%INF);	
}
int dp[MAXN][3],tmp[3];
bool cmp(int x,int y){
	return (in[x]<in[y]);
}
int ata(int x,int y){
	return (in[x]<=in[y] and out[y]<=out[x]);
}
void dfs2(int nd){
	if(way[nd].size()==0){
		dp[nd][0]=1;
		dp[nd][1]=1;
		dp[nd][2]=0;
		return;
	}dfs2(way[nd][0]);
	for(int a=0;a<3;a++)
		dp[nd][a]=dp[way[nd][0]][a];
	for(int h=1;h<int(way[nd].size());h++){
		int to=way[nd][h];	
		dfs2(to);
		for(int a=0;a<3;a++)
			for(int b=0;b<3;b++)
				tmp[min(a+b,2)]=mod(tmp[min(a+b,2)]+mod(dp[nd][a]*1LL*dp[to][b]));
		for(int a=0;a<3;a++)
			dp[nd][a]=tmp[a],tmp[a]=0;
	}
	dp[nd][0]=mod(dp[nd][0]+dp[nd][2]);dp[nd][2]=0;
	//~ cout<<nd<<" "<<dp[nd][0]<<","<<dp[nd][1]<<endl;
}
int main(){
	memset(P,-1,sizeof P);
    //~ freopen("file.in", "r", stdin);
    scanf("%d",&n);level[0].pb(0);
    for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		lvl[i]=lvl[x]+1;
		P[i][0]=x;
		level[lvl[i]].pb(i);
		adj[x].pb(i);
	}	
	dfs(0);
	build();
	pw[0]=1;
	for(int i=1;i<MAXN;i++)
		pw[i]=mod(pw[i-1]*2LL);
	int ans=0;	
	for(int i=n;i>=0;i--){
		if(level[i].size()==0)
			continue;	
		int cof=pw[n-level[i].size()+1];	
		//~ printf("level = %d\n",i);	
		sort(all(level[i]),cmp);
		stack<int>st;
		for(int j=0;j<int(level[i].size())-1;j++){
			int node=LCA(level[i][j],level[i][j+1]);
			if(!vis[node]){
				st.push(node);
				vis[node]=1;
			}
		}
		while(!st.empty()){
			int nd=st.top();
			st.pop();
			vis[nd]=0;
			level[i].pb(nd);
		}
		sort(all(level[i]),cmp);
		st.push(level[i][0]);
		for(int j=1;j<int(level[i].size());j++){
			int nd=level[i][j];
			while(!st.empty() and !ata(st.top(),nd))
				st.pop();
			//~ cout<<st.top()<<"->"<<nd<<endl;	
			way[st.top()].pb(nd);
			st.push(nd);	
		}
		dfs2(level[i][0]);
		ans=mod(ans+mod(dp[level[i][0]][1]*1LL*1LL*cof));	
		//~ cout<<dp[level[i][0]][1]<<endl;
		tr(it,level[i])
			way[*it].clear();
	}	
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 52352