#include<bits/stdc++.h>
#define neko 400010
#define pb push_back
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
#define rf(i,a,b) for(register int i=(a);i>=(b);i=~(-(i)))
#define travel(i,u,v,e,head) for(register int i=head[u],v=e[i].v;i;i=e[i].nex,v=e[i].v)
using namespace std;
struct node
{int v,nex;}e[neko],E[neko];
int n,t,dp[neko][2];
vector<int>vec[neko];
int st[1000010][22];
typedef int arr[neko];
arr head,Head,vir,stk,dfn,out,eln,tag,dep;
typedef long long ll;
ll mod=1e9+7,ans;
namespace IO
{
	const unsigned int bufsize=1<<16,outsize=1<<16;
	static char ch[bufsize],*S=ch,*T=ch;
	inline char getc()
	{return ((S==T)&&(T=(S=ch)+fread(ch,1,bufsize,stdin),S==T)?0:*S++);}
	static char Out[outsize],*nowp=Out;
	inline void flush(){fwrite(Out,1,nowp-Out,stdout);nowp=Out;}
	template<typename T>
	void read(T &x)
	{
		char c=getc();x=0;
		for(;!isdigit(c);c=getc());
		for(;isdigit(c);x=(x<<1)+(x<<3)+(c^'0'),c=getc());
	}
	template<typename T>
	void write(T x,char c='\n')
	{
		if(!x)*nowp++='0';
		static unsigned int stk[50],tp=0;
		for(;x;x/=10)stk[++tp]=x%10;
		for(;tp;*nowp++=stk[tp--]^'0');*nowp++=c;
	}
}
namespace Graph
{
	inline void add(int x,int y)
	{
		e[++t].v=y,e[t].nex=head[x],head[x]=t;
		e[++t].v=x;e[t].nex=head[y];head[y]=t;
	}
}
ll slowpow(ll m,ll n)
{
	ll b=1;
	for(;n;n>>=1,m=m*m%mod)if(n&1)b=b*m%mod;
	return b;
}
namespace Vir_Tree
{
	int dfc=0,elc=0,tp=0,T=0,vn=0;
	static double lg2=log(2);
	ll ADD(ll x,ll y){return (x+=y)>=mod?x-mod:x;}
	ll MUL(ll x,ll y){return (x*=y)>=mod?x%mod:x;}
	void add(int x,int y)
	{
		E[++T].v=y,E[T].nex=Head[x],Head[x]=T;
		E[++T].v=x;E[T].nex=Head[y];Head[y]=T;
	}
	int LCA(int x,int y)
	{
		x=eln[x],y=eln[y];if(x>y)swap(x,y);
		int k=log(y-x+1)/lg2;return dep[st[x][k]]<=dep[st[y-(1<<k)+1][k]]?st[x][k]:st[y-(1<<k)+1][k];
	}
	void initST()
	{
		int lim=log(elc)/lg2;
		f(k,1,lim)
		 f(u,1,elc)
		  st[u][k]=dep[st[u][k-1]]<=dep[st[u+(1<<k-1)][k-1]]?st[u][k-1]:st[u+(1<<k-1)][k-1];
	}
	void dfsinit(int u,int fa)
	{
		dfn[u]=++dfc,st[eln[u]=++elc][0]=u;vec[dep[u]=dep[fa]+1].pb(u);
		travel(i,u,v,e,head)if(v^fa)dfsinit(v,u),st[++elc][0]=u;
		out[u]=++dfc;
	}
	void dfs(int u,int fa)
	{
		ll prod=1;
		travel(i,u,v,E,Head)if(v^fa)dfs(v,u),prod=MUL(prod,dp[v][0]);
		travel(i,u,v,E,Head)if(v^fa)dp[u][1]=ADD(dp[u][1],MUL(dp[v][1],prod*slowpow(dp[v][0],mod-2)%mod));
		dp[u][0]=ADD(1,mod-dp[u][1]);
	}
	bool cmp(int x,int y){return dfn[x]<dfn[y];}
	inline void build()
	{
		sort(vir+1,vir+vn+1,cmp);
		rf(i,vn,2)vir[++vn]=LCA(vir[i],vir[i-1]);vir[++vn]=1;
		sort(vir+1,vir+vn+1,cmp),vn=unique(vir+1,vir+vn+1)-(vir+1);
		f(i,1,vn)
		{
			while(tp&&(out[stk[tp]]<=dfn[vir[i]]))--tp;
			if(tp)add(stk[tp],vir[i]);stk[++tp]=vir[i];
		}
	}
	inline void clear()
	{f(i,1,vn)tag[vir[i]]=Head[vir[i]]=0,dp[vir[i]][0]=dp[vir[i]][1]=0;vn=T=tp=0;}
	inline void solve()
	{
		ll inv2=slowpow(2,mod-2);
		dfsinit(1,0),initST();
		int now=1;
		while(!vec[now].empty())
		{
			for(int x:vec[now])dp[vir[++vn]=x][0]=dp[x][1]=inv2;
			build(),dfs(vir[1],0),ans=ADD(ans,dp[1][1]),clear();
			vec[now].clear(),++now;
		}
	}
}
int main()
{
	using namespace IO;
	using namespace Graph;
	int x;
	read(n);
	f(i,1,n)read(x),add(x+1,i+1);
	return Vir_Tree::solve(),write(ans*slowpow(2,n+1)%mod),flush(),0;
}

Measured memory_bytes: 82688