#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> mp[200001];
vector<long long> dp[3][200001];
int cntd[200001];
void dfs(int k,int d)
{
	++cntd[d];
	int pos=0;
	for (size_t i=0;i<mp[k].size();++i)
	{
		int u=mp[k][i];
		dfs(u,d+1);
		if (int(dp[0][u].size())>int(dp[0][k].size()))
		{
			dp[0][k].swap(dp[0][u]);
			dp[1][k].swap(dp[1][u]);
			dp[2][k].swap(dp[2][u]);
		}
		pos=max(pos,int(dp[0][u].size()));
		for (int p1=int(dp[0][k].size())-1,p2=int(dp[0][u].size())-1;p2>=0;--p1,--p2)
		{
			long long tot=((dp[0][k][p1]+dp[1][k][p1]+dp[2][k][p1])%1000000007)*(dp[0][u][p2]+dp[1][u][p2]+dp[2][u][p2]);
			dp[1][k][p1]=(dp[1][k][p1]*dp[0][u][p2]+dp[0][k][p1]*dp[1][u][p2])%1000000007;
			(dp[0][k][p1]*=dp[0][u][p2])%=1000000007;
			dp[2][k][p1]=(tot-dp[0][k][p1]-dp[1][k][p1])%1000000007;
			if (dp[2][k][p1]<0)
				dp[2][k][p1]+=1000000007;
		}
		dp[2][u]=dp[1][u]=dp[0][u]=vector<long long>();
	}
	for (size_t i=dp[0][k].size()-pos;i<dp[0][k].size();++i)
	{
		(dp[0][k][i]+=dp[2][k][i])%=1000000007;
		dp[2][k][i]=0;
	}
	dp[0][k].push_back(1);
	dp[1][k].push_back(1);
	dp[2][k].push_back(0);
}
int pw2[200001];
int main()
{
	int n;
	scanf("%d",&n);
	pw2[0]=1;
	for (int i=1;i<=n;++i)
	{
		int p;
		scanf("%d",&p);
		mp[p].push_back(i);
		pw2[i]=(pw2[i-1]*2)%1000000007;
	}
	dfs(0,0);
	long long ans=0;
	for (int i=int(dp[1][0].size())-1,j=0;i>=0;--i,++j)
		(ans+=dp[1][0][i]*pw2[n-cntd[j]+1])%=1000000007;
	printf("%lld\n",ans);
	return 0;
}
