#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n;
int parent[N];
vector < int > v[N];
deque < pair < int , pair < int , int > > > val[N];
int mx;
void merge(int node , int child){
	for(int i = 0 ; i < val[child].size() ; ++i){
		int azero = val[node][i].first;
		int aone = val[node][i].second.first;
		int atwo = val[node][i].second.second;
		int bzero = val[child][i].first;
		int bone = val[child][i].second.first;
		int btwo = val[child][i].second.second;
		int suma = (1LL * azero + aone + 1LL * atwo) % mod;
		int sumb = (1LL * bzero + bone + 1LL * btwo) % mod;
		val[node][i].first = (1LL * azero * bzero) % mod;
		val[node][i].second.first = (1LL * azero * bone + 1LL * aone * bzero) % mod;
		val[node][i].second.second = (((1LL * suma * sumb - val[node][i].first - val[node][i].second.first) % mod) + mod) % mod;
	}
	mx = max(int(val[child].size()) , mx);
}
void dfs(int node){
	for(int next : v[node]){
		dfs(next);
	}
	int big = -1;
	for(int next : v[node]){
		if(big == -1 || val[next].size() > val[big].size()){
			big = next;
		}
	}
	if(big != -1){
		val[node].swap(val[big]);
	}
	mx = 0;
	for(int next : v[node]){
		if(next != big){
			merge(node , next);
		}
	}
	for(int i = 0 ; i < mx ; ++i){
		val[node][i].first = (val[node][i].first + val[node][i].second.second) % mod;
		val[node][i].second.second = 0;
	}
	val[node].push_front(make_pair(1 , make_pair(1 , 0)));
}
int power[N];
int depth[N];
int cnt[N];
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , &parent[i]);
		v[parent[i]].emplace_back(i);
	}
	dfs(0);
	int ans = 0;
	power[0] = 1;
	for(int i = 1 ; i <= n ; ++i){
		power[i] = (power[i - 1] << 1) % mod;
	}
	depth[0] = 0;
	for(int i = 1 ; i <= n ; ++i){
		depth[i] = depth[parent[i]] + 1;
	}
	for(int i = 0 ; i <= n ; ++i){
		++cnt[depth[i]];
	}
	for(int i = 0 ; cnt[i] ; ++i){
		ans = (ans + 1LL * val[0][i].second.first * power[n + 1 - cnt[i]]) % mod;
	}
	printf("%d\n" , ans);
}