#include <bits/stdc++.h>

using namespace std;
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())
#define ten(n) ((int)1e##n)
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

template<typename ...> static inline int getchar_unlocked(void) { return getchar(); }
template<typename ...> static inline void putchar_unlocked(int c) { putchar(c); }
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void reader(ll& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
int reader(char c[]) { int i, s = 0; for (;;) { mygc(i); if (i != ' '&&i != '\n'&&i != '\r'&&i != '\t'&&i != EOF) break; }c[s++] = i; for (;;) { mygc(i); if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) break; c[s++] = i; }c[s] = '\0'; return s; }
int reader(string& c) { int i; for (;;) { mygc(i); if (i != ' '&&i != '\n'&&i != '\r'&&i != '\t'&&i != EOF) break; }c.push_back(i); for (;;) { mygc(i); if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) break; c.push_back(i); }; return sz(c); }
template <class T, class S> void reader(T& x, S& y) { reader(x); reader(y); }
template <class T, class S, class U> void reader(T& x, S& y, U& z) { reader(x); reader(y); reader(z); }
template <class T, class S, class U, class V> void reader(T& x, S& y, U& z, V & w) { reader(x); reader(y); reader(z); reader(w); }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
void writer(ll x, char c) { int s = 0, m = 0; char f[20]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
void writer(const char c[]) { int i; for (i = 0; c[i] != '\0'; i++)mypc(c[i]); }
void writer(const string& x, char c) { int i; for (i = 0; x[i] != '\0'; i++)mypc(x[i]); mypc(c); }
void writer(const char x[], char c) { int i; for (i = 0; x[i] != '\0'; i++)mypc(x[i]); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }
template<class T, class S> void writerLn(T x, S y) { writer(x, ' '); writer(y, '\n'); }
template<class T, class S, class U> void writerLn(T x, S y, U z) { writer(x, ' '); writer(y, ' '); writer(z, '\n'); }
template<class T> void writerArr(T x[], int n) { if (!n) { mypc('\n'); return; }FOR(i, n - 1)writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerArr(vector<T>& x) { writerArr(x.data(), (int)x.size()); }

template<class T> void chmin(T& a, const T& b) { if (a > b) a = b; }
template<class T> void chmax(T& a, const T& b) { if (a < b) a = b; }

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll mod_pow(ll a, ll n, ll mod) {
	ll ret = 1;
	ll p = a % mod;
	while (n) {
		if (n & 1) ret = ret * p % mod;
		p = p * p % mod;
		n >>= 1;
	}
	return ret;
}
template<class T> T extgcd(T a, T b, T& x, T& y) { for (T u = y = 1, v = x = 0; a;) { T q = b / a; swap(x -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return b; }
template<class T> T mod_inv(T a, T m) { T x, y; extgcd(a, m, x, y); return (m + x % m) % m; }

vector<int> e[ten(5) * 2 + 1];
const int MOD = ten(9) + 7;
ll p2[ten(5) * 3];

struct B {
	int lev;
	ll o, t, all;
};

struct A {
	map<int, B> dp;
};

void merge(B& c, B& b, int lev) {
	if (c.lev != lev) {
		c.lev = lev;
		c.t = 0;
	}
	if (b.lev != lev) {
		b.lev = lev;
		b.t = 0;
	}
	B a = c;
	c.o = a.o * (b.all - b.o - b.t) + b.o * (a.all - a.o - a.t);
	c.o %= MOD;
	c.all = a.all * b.all % MOD;
	c.t = c.all - c.o - (b.all - b.o - b.t) * (a.all - a.o - a.t);
	c.t %= MOD;
}

void merge(A& a, A& b, int level) {
	if (sz(a.dp) < sz(b.dp)) {
		a.dp.swap(b.dp);
	}
	if (sz(b.dp) == 0) return;
	for (auto& val : b.dp) {
		merge(a.dp[val.first], val.second, level);
	}
}

void dfs2(int v, A& ret, int dep) {
	for (auto to : e[v]) {
		A tmp;
		dfs2(to, tmp, dep + 1);
		merge(ret, tmp, v);
	}
	ret.dp[dep] = B{ dep ,1, 0, 2 };
}

void init() {
	p2[0] = 1;
	FOR(i, 2 * ten(5) + 10) {
		p2[i + 1] = p2[i] * 2 % MOD;
	}
}

int solve(int n) {
	A ret;
	dfs2(0, ret, 0);
	ll ans = 0;
	for (auto& b : ret.dp) {
		ll cur = p2[n + 1] * mod_inv<ll>(b.second.all, MOD) % MOD * b.second.o %MOD;
		ans += cur;
	}
	ans = (ans % MOD + MOD) % MOD;
	return ans % MOD;
}

namespace hoge {
	ll modpow(ll r, ll n, ll m = MOD) {
		ll re = 1, d = r%m;
		if (n<0)(n %= m - 1) += m - 1;
		for (; n; n /= 2) {
			if (n & 1)(re *= d) %= m;
			(d *= d) %= m;
		}
		return re;
	}

	template <int mod = MOD> struct modInt {
		int v;
		modInt(int v = 0) :v(v) {}
		modInt operator+(const modInt &n) { return v + n.v<mod ? v + n.v : v + n.v - mod; }
		modInt operator-(const modInt &n) { return v - n.v<0 ? v - n.v + mod : v - n.v; }
		modInt operator*(const modInt &n) { return ll(v)*n.v%mod; }
		modInt operator/(const modInt &n) { return ll(v)*modpow(n.v%mod, -1, mod) % mod; }
		modInt operator+(const ll &n) { return v + n<mod ? v + n : v + n - mod; }
		modInt operator-(const ll &n) { return v - n<0 ? v - n + mod : v - n; }
		modInt operator*(const ll &n) { return ll(v)*(n%mod) % mod; }
		modInt operator/(const ll &n) { return ll(v)*modpow(n%mod, -1, mod) % mod; }
		modInt& operator+=(const modInt &n) { v += n.v; if (v >= mod) v -= mod; return *this; }
		modInt& operator-=(const modInt &n) { v -= n.v; if (v<0) v += mod; return *this; }
		modInt& operator*=(const modInt &n) { v = ll(v)*n.v%mod; return *this; }
		modInt& operator/=(const modInt &n) { v = ll(v)*modpow(n.v, -1, mod) % mod; return *this; }
		modInt& operator+=(const ll &n) { v += n; if (v >= mod) v -= mod; return *this; }
		modInt& operator-=(const ll &n) { v -= n; if (v<0) v += mod; return *this; }
		modInt& operator*=(const ll &n) { v = ll(v)*n%mod; return *this; }
		modInt& operator/=(const ll &n) { v = ll(v)*modpow(n, -1, mod) % mod; return *this; }
	};
	template<int mod> ostream& operator<<(ostream &os, const modInt<mod> &n) { return os << n.v; };
	template<int mod> modInt<mod> operator+(const ll &n, const modInt<mod> &m) { return m.v + n<mod ? m.v + n : m.v + n - mod; }
	template<int mod> modInt<mod> operator-(const ll &n, const modInt<mod> &m) { return n - m.v<0 ? n - m.v + mod : n - m.v; }
	template<int mod> modInt<mod> operator*(const ll &n, const modInt<mod> &m) { return ll(m.v)*(n%mod) % mod; }
	template<int mod> modInt<mod> operator/(const ll &n, const modInt<mod> &m) { return ll(m.v)*modpow(n%mod, -1, mod) % mod; }
	typedef modInt<MOD> mint;
	template <int mod> modInt<mod> modpow(modInt<mod> r, ll n) { modInt<mod> re(1); if (n<0)(n %= mod - 1) += mod - 1; for (; n; n /= 2) { if (n & 1) re *= r; r *= r; } return re; }
	vector<mint> fact, finv, inv;
	mint comb(ll n, ll r) { if (n<r || r<0)return 0; return fact[n] * finv[n - r] * finv[r]; }
	class Doralion {
		void Modinvs(vector<mint> &re, int n) { re.resize(n + 1); re[1] = 1; for (int i = 2; i <= n; ++i)re[i] = re[MOD%i] * (MOD - MOD / i); }
		void Facts(vector<mint> &re, int n) { re.resize(n + 1); re[0] = 1; FOR(i, n)re[i + 1] = re[i] * (i + 1); }
		void Factinvs(vector<mint> &re, const vector<mint> &inv, int n) { re.resize(n + 1); re[0] = 1; FOR(i, n)re[i + 1] = re[i] * inv[i + 1]; }
	public:
		Doralion(int n) { Modinvs(inv, n); Facts(fact, n); Factinvs(finv, inv, n); }
	} doralion(212345);
	template<class T> inline bool MX(T &l, const T &r) { return l<r ? l = r, 1 : 0; }
	template<class T> inline bool MN(T &l, const T &r) { return l>r ? l = r, 1 : 0; }
	int solve(vector<vector<int>> g) {
		const int n = sz(g);
		vector<vector<mint>> zeros(n), ones(n);
		map<int, int> cnt;
		function<void(int, int)> dfs = [&](int v, int d) {
			int mx = 0, ind = v;
			++cnt[d];
			for (int w : g[v]) {
				dfs(w, d + 1);
				if (MX<int>(mx, zeros[w].size())) ind = w;
			}
			swap(zeros[v], zeros[ind]);
			swap(ones[v], ones[ind]);
			int m = 0;
			for (int w : g[v])if (w != ind) MX<int>(m, zeros[w].size());
			FOR(i, m) {
				mint zero = zeros[v][mx - 1 - i];
				mint sum = ones[v][mx - 1 - i] / zeros[v][mx - 1 - i];
				mint al = zeros[v][mx - 1 - i] + ones[v][mx - 1 - i];
				for (int w : g[v])if (w != ind) {
					mint z = 1, o = 0;
					int sz = zeros[w].size();
					if (sz>i) {
						z = zeros[w][sz - 1 - i];
						o = ones[w][sz - 1 - i];
					}
					zero *= z;
					sum += o / z;
					al *= o + z;
				}
				ones[v][mx - 1 - i] = zero*sum;
				zeros[v][mx - 1 - i] = al - ones[v][mx - 1 - i];
			}
			ones[v].push_back(1);
			zeros[v].push_back(1);
			// out(v, ones[v], zeros[v], 1);
		};
		dfs(0, 0);
		mint re = 0;
		FOR(i, ones[0].size()) re += ones[0][i] * modpow(2, n - cnt[ones[0].size() - 1 - i]);

		return re.v;
	}
};

void test() {
	int n = 1000;
	FOR(i, n) {
		e[i].clear();
	}
	vector<vector<int>> g(n + 1);
	FOR(i, n) {
		int p = rand() % (i + 1);
		e[p].push_back(i + 1);
		g[p].push_back(i + 1);
	}

	int ans = solve(n);
	int ans2 = hoge::solve(g);
	if (ans != ans) {
		cout << "?";
		exit(1);
	}
	writerLn(ans);
}

int main() {
	init();

	//while (true) {
	//	test();
	//}

	int n; reader(n);
	vector<vector<int>> g(n + 1);
	FOR(i, n) {
		int p; reader(p);
		e[p].push_back(i + 1);
		g[p].push_back(i + 1);
	}

	int ans = solve(n);
	int ans2 = hoge::solve(g);
	assert(ans == ans2);
	writerLn(ans);


	return 0;
}


Measured memory_bytes: 92276