#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;
const int N = 2e5;

struct node{
	node *next;
	int total[3];
};

node *root;

node nodes[N + 5];
int pcntr = 0;
inline node* allocc(){
	if(pcntr >= N) assert(0);
	return &nodes[pcntr++];
}

vector<int> lst[N + 5];
int dep[N + 5];
int occ[N + 5];
int po[N + 5];

inline int addmod(ll a, ll b) {
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

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

void dfs(int cur, int h) {
	dep[cur] = 1;
	occ[h]++;
	for(int i = 0;i < lst[cur].size();i++) {
		int to = lst[cur][i];
		dfs(to, h + 1);
		dep[cur] = max(dep[cur], dep[to] + 1);
	}
}

ll arr[3];

node *solve(int cur) {
	node *head = allocc();
	head->next = NULL;
	head->total[0] = head->total[1] = 1;
	head->total[2] = 0;
	int banned = -1;
	int take = 0;
	for(int i = 0;i < lst[cur].size();i++) {
		int to = lst[cur][i];
		if(dep[to] + 1 == dep[cur]) {
			banned = i;
			head->next = solve(to);
			take++;
			break;
		}
	}
	for(int i = 0;i < lst[cur].size();i++) {
		if(i == banned) continue;
		int to = lst[cur][i];
		node *tmp = solve(to);
		node *ct = head->next;
		take++;
		while(tmp != NULL) {
			arr[0] = arr[1] = arr[2] = 0;
			for(int i = 0;i < 3;i++) {
				for(int j = 0;j < 3;j++) {
					int k = min(i + j, 2);
					arr[k] = addmod(arr[k], mulmod(ct->total[i], tmp->total[j]));
				}
			}
			ct->total[0] = arr[0], ct->total[1] = arr[1], ct->total[2] = arr[2];
			if(take == lst[cur].size()) {
				ct->total[0] = addmod(ct->total[0], ct->total[2]);
				ct->total[2] = 0;
			}
			tmp = tmp->next, ct = ct->next;
		}
		if(take == lst[cur].size()) {
			while(ct != NULL) {
				ct->total[0] = addmod(ct->total[0], ct->total[2]);
				ct->total[2] = 0;
				ct = ct->next;
			}
		}
	}
	return head;
}

int main() {
	po[0] = 1;
	for(int i = 1;i <= N;i++) po[i] = mulmod(po[i - 1], 2);
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++) {
		int x;
		scanf("%d",&x);
		lst[x].push_back(i);
	}
	dfs(0, 1);
	root = solve(0);
	int total = 0;
	for(int i = 1; root != NULL;i++, root = root->next) {
		total = addmod(total, mulmod(root->total[1], po[n + 1 - occ[i]]));
	}
	printf("%d\n", total);
}