#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<int> vertexs[300000];
long long powing(long long a, long long b) {
	long long ans = 1;
	while (b != 0) {
		if (b % 2) {
			ans *= a;
			ans %= MAX_MOD;
		}
		a *= a;
		a %= MAX_MOD;
		b /= 2;
	}
	return ans;
}
long long inv(long long now) {
	return powing(now, MAX_MOD - 2LL);
}
vector<tuple<long long, long long, long long>> dp[300000];
void dfs(long long now, long long back) {
	int targes = 0;
	REP(i, vertexs[now].size()) {
		int going = vertexs[now][i];
		if (going == back) continue;
		dfs(going, now);
		if (dp[going].size() > dp[now].size()) {
			swap(dp[going], dp[now]);
			//怪しい
		}
		targes = max(targes, (int)dp[going].size());
		//now should be maximizer
		for (int q = 0; q < dp[going].size(); ++q) {
			//structure merger
			int target_b = dp[going].size() - q - 1;
			int target_a = dp[now].size() - q - 1;
			tuple<long long, long long, long long> next = make_tuple(0, 0, 0);
			get<0>(next) = (((get<0>(dp[now][target_a]) * get<0>(dp[going][target_b]))%MAX_MOD)) % MAX_MOD;
			
			get<1>(next) += (((get<1>(dp[now][target_a]) * get<0>(dp[going][target_b])) % MAX_MOD)) % MAX_MOD;
			get<1>(next) += (((get<0>(dp[now][target_a]) * get<1>(dp[going][target_b])) % MAX_MOD)) % MAX_MOD;
			
			get<2>(next) += (((get<2>(dp[now][target_a]) * get<0>(dp[going][target_b])) % MAX_MOD)) % MAX_MOD;
			get<2>(next) += (((get<1>(dp[now][target_a]) * get<1>(dp[going][target_b])) % MAX_MOD)) % MAX_MOD;
			get<2>(next) += (((get<0>(dp[now][target_a]) * get<2>(dp[going][target_b])) % MAX_MOD)) % MAX_MOD;
			get<2>(next) += (((get<2>(dp[now][target_a]) * get<1>(dp[going][target_b])) % MAX_MOD)) % MAX_MOD;
			get<2>(next) += (((get<1>(dp[now][target_a]) * get<2>(dp[going][target_b])) % MAX_MOD)) % MAX_MOD;
			get<2>(next) += (((get<2>(dp[now][target_a]) * get<2>(dp[going][target_b])) % MAX_MOD)) % MAX_MOD;
			
			get<0>(next) %= MAX_MOD;
			get<1>(next) %= MAX_MOD;
			get<2>(next) %= MAX_MOD;

			dp[now][target_a] = next;
		}
	}
	int hoge = dp[now].size() - 1;
	REP(i, targes) {
		get<0>(dp[now][hoge - i]) += get<2>(dp[now][hoge - i]);
		get<0>(dp[now][hoge - i]) %= MAX_MOD;
		get<2>(dp[now][hoge - i]) = 0;
	}
	dp[now].push_back(make_tuple(inv(2), inv(2), 0));
	return;
}
int main() {
	int n;
	cin >> n;
	REP(i, n) {
		int hoge;
		cin >> hoge;
		vertexs[hoge].push_back(i + 1);
	}
	n++;
	dfs(0,-1);
	long long ans = 0;
	long long nya = powing(2LL, n);
	REP(i, dp[0].size()) {
		ans += nya * get<1>(dp[0][i]);
		ans %= MAX_MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 65264