#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e18+1e18;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
ll N;
vvll g;
vll ht;

set<ll> vst;
void newtree(vvll &h,vll &hvar, ll nowht) {
	vvll hpast = h;

	//cout << "hpast" << endl;
	//cout << hpast.size() << endl;
	//rep(i,hpast.size())for (ll j : hpast[i]) { cout << i << j << endl; }
	//cout << hvar.size() << endl;
	//rep(i, hpast.size())cout << hvar[i] <<" ";
	//cout << endl;

	rep(i, hpast.size()) {
		if (hpast[i].size()==0) {
			ll v = hvar[i];
			for (ll w : g[v]) {
				//cout << v << " " << w << endl;
				ll sz = h.size();
				h[i].push_back(sz);
				hvar.push_back(w);
				h.push_back({});
			}
		}
	}

	ll M = h.size();

	//cout << "h" << endl;
	//cout << M << endl;
	//rep(i,M)for (ll j : h[i]) { cout << i << j << endl; }
	//rep(i, M)cout << hvar[i] <<" ";
	//cout << endl;

	vector<bool> use(M, 1);
	for (ll i = M-1; i >= 0; i--) {
		if (h[i].size() == 0) {
			if (ht[hvar[i]] != nowht) { use[i] = 0; }
		}
		else {
			bool b = 0;
			for (ll j : h[i]) {
				b = b | use[j];
			}
			use[i] = b;
		}
	}
	
	//cout << "use" << endl;
	//rep(i, M)cout << use[i] << " ";
	//cout << endl;

	vvll hh(M);
	rep(i,M) {
		if (use[i] == 0) { continue; }
		for (ll j : h[i]) {
			if (use[j] == 1) { hh[i].push_back(j); }
		}
	}

	//cout << "hh" << endl;

	vvll hi(M);
	rep(i, M) {
		if (use[i] == 0) { continue; }
		for (ll j : hh[i]) {
			//cout << i << " " << j << endl;

			ll newj = j;
			while (hh[newj].size() == 1) {
				//cout << newj << endl;
				use[newj] = 0;
				newj = hh[newj][0];
			}
			hi[i].push_back(newj);
		}
	}

	//cout << "hi" << endl;

	vvll reth(1);
	vll rethvar(1, 0);

	vll taio(M, 0);
	rep(i, M) {
		if (use[i] == 0) { continue; }
		for (ll j : hi[i]) {
			ll sz = reth.size();
			reth[taio[i]].push_back(sz);
			taio[j] = sz;
			reth.push_back({});
			rethvar.push_back(hvar[j]);
		}
	}

	h = reth;
	hvar = rethvar;
	return;
}

mint dp(vvll h) {
	ll M = h.size();

	vmint all(M, 0);
	vmint in(M, 0);

	for (ll i = M-1; i >= 0; i--) {
		if (h[i].size() == 0) { all[i] = 2; in[i] = 1; continue; }

		mint c = 1;
		for (ll j : h[i]) {
			c *= (all[j] - in[j]);
		}

		for (ll j : h[i]) {
			in[i] += c / (all[j] - in[j]) * in[j];
		}
		all[i] = 1;
		for (ll j : h[i]) {
			all[i] *= all[j];
		}

		//all[i] *= 2;
		//in[i] *= 2;

	}

	//cout << "dp" << endl;
	//rep(i, M)cout << all[i] << in[i] << endl;

	return in[0];
}

int main() {
	cin >> N;
	vll p(N + 1);
	repn(i, N)cin >> p[i];

	ht.assign(N + 1, 0);
	ll mxht = 0;
	repn(v, N) {
		ht[v] = ht[p[v]] + 1;
		mxht = max(mxht, ht[v]);
	}

	//cout << mxht << endl;

	vll htc(mxht + 1, 0);
	rep(v, N + 1) {
		htc[ht[v]]++;
	}

	g.resize(N + 1);
	repn(i, N) {
		g[p[i]].push_back(i);
	}

	vvll h(1);
	vll hvar(1, 0);
	mint ans = pw(2,N);

	repn(k, mxht) {
		newtree(h, hvar, k);
		//cout << h.size() << endl;
		//cout << "H" << endl;
		//rep(v, h.size()) {
		//	for (ll w : h[v]) { cout << v << w << endl; }
		//}
		//rep(v, h.size()) { cout << hvar[v] << endl; }
		//cout << endl;
		//cout << htc[k] << endl;
		ans += dp(h) * pw(2,N + 1 - htc[k]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 46532