#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const int oo=1<<30;
const LL OO=1e18;

const int N=4e5+100;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

const int mod=1e9+7;
inline int qpow(int x,int y) {
	int ans=1;
	while (y) {
		ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}

int head[N],nxt[N];
int f[N],s[N],son[N];
int tot[N],p[N],dfn[N],up[N],dep[N],pi[N];
int cnt;
inline void dfs1(int k) {
	tot[dep[k]]++;up[k]=1;
	for (int i=head[k];i;i=nxt[i]) {
		dep[i]=dep[k]+1;dfs1(i);
		if (up[i]+1>up[k]) up[k]=up[i]+1,son[k]=i;
	}
}
inline void merge(int x,int y) {
	int o=(p[s[y]]-f[y]+mod)%mod;
	f[x]=(1LL*f[x]*o+1LL*pi[x]*f[y])%mod;
	s[x]+=s[y];pi[x]=1LL*pi[x]*o%mod;
}
inline void dfs2(int k) {
	int t,mx=0;
	f[cnt]=s[cnt]=1;
	dfn[k]=cnt++;
	if (son[k]) dfs2(son[k]);
	for (int i=head[k];i;i=nxt[i])
		if (i!=son[k])
			mx=max(mx,up[i]);
	for (int t=1;t<=mx;t++)
		pi[dfn[k]+t]=(p[s[dfn[k]+t]]-f[dfn[k]+t]+mod)%mod;
	for (int i=head[k];i;i=nxt[i])
		if (i!=son[k]) {
			dfs2(i);
			for (t=0;t<up[i];t++)
				merge(dfn[k]+t+1,dfn[i]+t);
		}
}
int main()
{
	int n=gi(),i,k,ans=0;
	for (i=1;i<=n;i++)
		nxt[i]=head[k=gi()],head[k]=i;
	for (i=p[0]=1;i<=n+1;i++)
		p[i]=(p[i-1]<<1)%mod;
	dfs1(0);
	dfs2(0);
	for (i=0;i<up[0];i++)
		ans=(ans+1LL*f[i]*p[n+1-tot[i]])%mod;
	cout<<ans<<endl;
	return 0;
}
