#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
struct edge
{
	int to;
	int next;
}e[444444],d[444444],t[444444];
int pe=222222,pd=222222,pt=222222;
void insert(edge* e,int &pe,int a,int to)
{
	e[pe]=(edge){to,e[a].next};
	e[a].next=pe++;
}
int fa[222222];
int dep[222222];
int son[222222],top[222222],siz[222222];
int dfn[222222],bac[222222],dfc;
void dfs(int o)
{
	dfn[o]=++dfc;
	int mx=0;
	for(register int p=e[o].next;p;p=e[p].next)
	{
		dfs(e[p].to);
		siz[o]+=siz[e[p].to];
		if(cmax(mx,e[p].to))son[o]=e[p].to;
	}
	bac[o]=dfc;
}
void dfs2(int o)
{
	for(register int p=e[o].next;p;p=e[p].next)
	{
		if(e[p].to==son[o])top[e[p].to]=top[o];
			else top[e[p].to]=e[p].to;
		dfs2(e[p].to);
	}
}
int lca(int x,int y)
{
	while(top[x]!=top[y])
		dep[top[x]]>dep[top[y]]?x=fa[top[x]]:y=fa[top[y]];
	return dep[x]>dep[y]?y:x;
}
#define register
const int M=1000000007;
int f[222222][3];
int st[222222],ts;
int vec[444444],pv;
int vis[222222],pvi;
bool cmp(int x,int y)
{
	return dfn[x]<dfn[y];
}
bool sson(int x,int y)
{
	return dfn[x]<=dfn[y]&&bac[x]>=bac[y];
}
int ex[222222];
void dfs3(int o)
{
	f[o][0]=1;
	f[o][1]=vis[o]==pvi;
	f[o][2]=0;
	for(register int p=t[o].next;p;p=t[p].next)
	{
		dfs3(t[p].to);
		long long g[3]={(long long)f[o][0]*f[t[p].to][0]%M,((long long)f[t[p].to][0]*f[o][1]+(long long)f[t[p].to][1]*f[o][0])%M,((long long)f[t[p].to][0]*f[o][2]+(long long)f[t[p].to][1]*f[o][1]+(long long)f[t[p].to][1]*f[o][2])%M};
		f[o][0]=g[0],f[o][1]=g[1],f[o][2]=g[2];
	}
	f[o][0]=(f[o][0]+f[o][2])%M;
}
int main()
{
	int n=io::F();
	ex[0]=1;
	for(register int i=1;i<=n;++i)ex[i]=(ex[i-1]<<1)%M;
	int mxd=0;
	for(register int i=1;i<=n;++i)fa[i]=io::F(),insert(e,pe,fa[i],i),dep[i]=dep[fa[i]]+1,insert(d,pd,dep[i],i),cmax(mxd,dep[i]);
	dfs(0);
	dfs2(0);
	int ans=1;
	for(register int i=1;i<=n;++i)ans=(ans<<1)%M;
	for(register int i=1;i<=mxd;++i)
	{
		pv=0;
		for(register int p=d[i].next;p;p=d[p].next)
			vec[++pv]=d[p].to;
		++pvi;
		for(register int i=1;i<=pv;++i)vis[vec[i]]=pvi;
		int cnt=pv;
		std::sort(vec+1,vec+pv+1,cmp);
		for(register int i=1,u=pv;i<u;++i)
			vec[++pv]=lca(vec[i],vec[i+1]);
		std::sort(vec+1,vec+pv+1,cmp);
		pv=std::unique(vec+1,vec+pv+1)-vec-1;
		pt=222222;
		for(register int i=0;i<=pv+3;++i)t[vec[i]].next=0;
		ts=0;
		for(register int i=1;i<=pv;++i)
		{
			if(vec[i]==0)continue;
			while(sson(st[ts],vec[i])==0)--ts;
			insert(t,pt,st[ts],vec[i]);
			st[++ts]=vec[i];
		}
		dfs3(0);
		ans=(ans+(long long)ex[n+1-cnt]*f[0][1])%M;
	}
	printf("%d\n",ans);
	return 0;
}




Measured memory_bytes: 29184