#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#define MOD 1000000007LL

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

ll extgcd(ll a, ll b, ll& x, ll& y){
	ll d=a;
	if(b!=0){
		d=extgcd(b, a%b, y, x);
		y-=(a/b)*x;
	}else{
		x=1, y=0;
	}
	return d;
}
 
ll inv(ll a, ll p){
	ll x, y;
	extgcd(a, p, x, y);
	if(x<0){
		return p-(-x%p);
	}else{
		return x%p;
	}
}

vector<int> v[200001];
int d[200001], dmax;
vector<int> dist[200001];
int pp[200001];

void dfs(int x){
	for(auto y:v[x]){
		if(d[y]<0){
			d[y]=d[x]+1;
			dist[d[y]].push_back(y);
			dmax=max(d[y], dmax);
			dfs(y);
		}
	}
}

int p1;

void dfs2(int x){
	int ct=0;
	for(auto y:v[x]){
		if(d[y]>d[x]) ct++;
	}
	if(ct>1){
		for(auto y:v[x]){
			if(d[y]<d[x]) continue;
			p1=y;
			dfs2(y);
		}
	}
	if(ct==1){
		for(auto y:v[x]){
			if(d[y]<d[x]) continue;
			pp[y]=p1;
			dfs2(y);
		}
	}
}

map<int, vector<int> > g;

void dfs3(int x){
	bool e=0;
	if(g[pp[x]].empty()) e=1;
	g[pp[x]].push_back(x);
	if(e && pp[x]!=0) dfs3(pp[x]);
}

ll dfs4(int x){
	if(g[x].empty()){
		return 500000004;
	}
	ll sum=0, prod=1;
	for(auto y:g[x]){
		ll c=dfs4(y);
		sum+=(c*inv((MOD+1-c)%MOD, MOD)%MOD);
		sum%=MOD;
        prod*=(MOD+1-c);
        prod%=MOD;
	}
	return sum*prod%MOD;
}

int main()
{
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%d", &pp[i]);
		v[i].push_back(pp[i]);
		v[pp[i]].push_back(i);
	}
	fill(d, d+n+1, -1);
	d[0]=0;
	dist[0].push_back(0);
	dfs(0);
	dfs2(0);
	ll p2=1;
	for(int i=0; i<=n; i++){
		p2*=2;
		p2%=MOD;
	}
	ll ans=0;
	for(int t=0; t<=dmax; t++){
		if(t==0){
			ans+=500000004;
			continue;
		}
		g.clear();
		for(auto x:dist[t]){
			dfs3(x);
		}
		ans+=dfs4(0);
		ans%=MOD;
	}
	ans*=p2;
	ans%=MOD;
	printf("%lld\n", ans);
	return 0;
}