#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

ll po2[400050];

vector <int> son[200050];
int dep[200050];
int par[200050][20];
vector <int> Vl[200050];
void DFS(int n) {
	Vl[dep[n]].push_back(n);
	for (auto it : son[n]) {
		par[it][0] = n;
		dep[it] = dep[n] + 1;
		for (int i = 1; i < 20; i++) par[it][i] = par[par[it][i - 1]][i - 1];
		DFS(it);
	}
}
int lca(int a, int b) {
	if (dep[a] > dep[b]) swap(a, b);
	int c = dep[b] - dep[a];
	for (int i = 0; i < 20; i++) if (c & (1 << i)) b = par[b][i];
	if (a == b) return a;
	for (int i = 19; i >= 0; i--) {
		if (par[a][i] != par[b][i]) {
			a = par[a][i];
			b = par[b][i];
		}
	}
	return par[a][0];
}
vector <int> son2[400050];
ll dp[400050][2];
int r[200050];
int root(int x) {
	return (x == r[x]) ? x : (r[x] = root(r[x]));
}
vector <pii> Vu;

ll u1[200050];
ll u2[200050];
void DFS2(int n) {
	if (son2[n].empty()) {
		dp[n][0] = 1, dp[n][1] = 1;
		return;
	}
	
	for (auto it : son2[n]) DFS2(it);

	u1[0] = 1;
	for (int i = 1; i <= son2[n].size(); i++) u1[i] = u1[i - 1] * dp[son2[n][i - 1]][0] % MOD;
	u2[son2[n].size() + 1] = 1;
	for (int i = son2[n].size(); i >= 1; i--) u2[i] = u2[i + 1] * dp[son2[n][i - 1]][0] % MOD;

	for (int i = 0; i < son2[n].size(); i++) {
		ll v = u1[i] * u2[i + 2] % MOD;
		v *= dp[son2[n][i]][1];
		dp[n][1] = (dp[n][1] + v) % MOD;
	}
	dp[n][0] = 1;
	for (auto it : son2[n]) dp[n][0] = (dp[n][0] * (dp[it][0] + dp[it][1])) % MOD;
	dp[n][0] = (dp[n][0] - dp[n][1] + MOD) % MOD;
}
int main() {
	int N, i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		int t;
		scanf("%d", &t);
		son[t].push_back(i);
	}
	for (i = 0; i < 20; i++) par[0][i] = 0;
	DFS(0);

	po2[0] = 1;
	for (i = 1; i <= 400000; i++) po2[i] = po2[i - 1] * 2 % MOD;

	ll ans = 0;
	for (i = 0;; i++) {
		if (Vl[i].empty()) break;

		Vu.clear();
		int nc = Vl[i].size();
		for (j = 0; j + 1 < Vl[i].size(); j++) {
			int t = lca(Vl[i][j], Vl[i][j + 1]);
			Vu.emplace_back(t, j);
		}
		sort(all(Vu), [](pii a, pii b) {
			if (dep[a.first] != dep[b.first]) return dep[a.first] > dep[b.first];
			else if (a.first != b.first) return a.first > b.first;
			else return a.second < b.second;
		});
		for (j = 0; j < 2*Vl[i].size(); j++) r[j] = j;

		int st = 0;
		int ro = 0;
		for (j = 0; j < Vu.size(); j++) {
			if (j + 1 == Vu.size() || Vu[j + 1].first != Vu[st].first) {
				int prv = -1;
				vector <int> Vx;
				for (int k = st; k <= j; k++) {
					int t1 = root(Vu[k].second);
					int t2 = root(Vu[k].second + 1);
					Vx.push_back(t1);
					Vx.push_back(t2);
				}
				sort(all(Vx));
				Vx.erase(unique(all(Vx)), Vx.end());
				for (auto it : Vx) {
					r[it] = nc;
					son2[nc].push_back(it);
				}
				ro = nc;
				nc++;

				st = j + 1;
			}
		}
		DFS2(ro);
		ans += po2[N + 1 - Vl[i].size()] * dp[ro][1] % MOD;
		ans %= MOD;

		for (j = 0; j <= nc; j++) {
			son2[j].clear();
			dp[j][0] = dp[j][1] = 0;
		}
		//printf("%lld\n", ans);
	}
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 64384