#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cstring>
#include<deque>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
//////////////////////

#ifdef _DEBUG
int const N = 41;
#else
int const N = 2e5 + 41;
#endif
int const MOD = 1e9 + 7;
int const INVTWO = (MOD + 1) / 2;

int n, p[N], two[N], ans;
vector<int> e[N];

void add(int &a, int b){
	a += b;
	if(a >= MOD) a -= MOD;
}

int mul(int a, int b){
	return (ll) a * b % MOD;
}

struct State{
	int d[3];
	State(){
		memset(d, 0, sizeof(d));
	}
	State(int a, int b, int c){
		d[0] = a;
		d[1] = b;
		d[2] = c;
	}
	void combine(const State &a){
		int d0[3];
		memset(d0, 0, sizeof(d0));
		fi(0, 3){
			fj(0, 3){
				int no = min(2, (i + j));
				add(d0[no], mul(d[i], a.d[j]));
			}
		}
		fi(0, 3) d[i] = d0[i];
	}
	void relax(){
		add(d[0], d[2]);
		d[2] = 0;
	}
};

void init(){
	two[0] = 1;
	fi(1, N) two[i] = mul(two[i-1], 2);
	fi(1, n+1) e[p[i]].pb(i);
}

deque<State> d[N];
int pos[N];

void dfs(int x){
	pos[x] = x;
	int m = sz(e[x]);
	fi(0, m){
		int y = e[x][i];
		dfs(y);
		if(sz(d[pos[y]]) > sz(d[pos[x]])) pos[x] = pos[y];
	}
	int mx = -1;
	fi(0, m){
		int y = e[x][i];
		if(pos[y] == pos[x]) continue;
		fj(0, sz(d[pos[y]])){
			d[pos[x]][j].combine(d[pos[y]][j]);
		}
		mx = max(mx, sz(d[pos[y]]));
	}
	fi(0, mx) d[pos[x]][i].relax();
	d[pos[x]].push_front(State(INVTWO, INVTWO, 0));
}

void solve(){
	init();
	dfs(0);
	fi(0, sz(d[pos[0]])){
		add(ans, d[pos[0]][i].d[1]);
	}
	ans = mul(ans, two[n+1]);
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(1, n+1) scanf("%d",&p[i]);

	solve();

	printf("%d\n",ans);

	return 0;
}