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

template <int MOD_>
struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXN = 3e5;
int N;

vector<int> ch[MAXN];
int st[MAXN];
int en[MAXN];
int depth[MAXN];
int par[MAXN][21];

bool isAnc(int a, int b) {
	return st[a] <= st[b] && en[b] <= en[a];
}

int lca(int a, int b) {
	if (st[a] > st[b]) swap(a, b);
	if (isAnc(a, b)) return a;
	int i = 0;
	while (par[a][i]) i++;
	while (i--) {
		if (par[a][i] && !isAnc(par[a][i], b)) {
			a = par[a][i];
		}
	}
	assert(!isAnc(a, b));
	assert(isAnc(par[a][0], b));
	return par[a][0];
}

vector<int> verts[MAXN];
vector<int> vch[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N; N++;
	for (int i = 2; i <= N; i++) {
		cin >> par[i][0]; par[i][0]++;
		ch[par[i][0]].push_back(i);
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; par[i][j]; j++) {
			par[i][j+1] = par[par[i][j]][j];
		}
	}

	{
		int curInd = 0;
		function<void(int)> dfs = [&](int cur) -> void {
			st[cur] = curInd++;
			for (int nxt : ch[cur]) {
				depth[nxt] = depth[cur] + 1;
				dfs(nxt);
			}
			en[cur] = curInd;
		};
		dfs(1);
	}

	for (int i = 1; i <= N; i++) {
		verts[depth[i]].push_back(i);
	}

	const num i2 = num(1) / 2;

	num ans = 0;
	for (int d = 0; !verts[d].empty(); d++) {
		{
			auto cnds = verts[d];
			if (d != 0) {
				cnds.push_back(1);
			}
			sort(cnds.begin(), cnds.end(), [&](int i, int j) -> bool { 
				return st[i] < st[j]; 
			});
			assert(cnds[0] == 1);

			auto connect = [&](int a, int b) -> void {
				assert(depth[a] < depth[b]);
				vch[a].push_back(b);
			};
			vector<int> stk;
			for (int v : cnds) {
				if (stk.size() > 1) {
					int a = lca(stk.back(), v);
					if (a != stk.back()) {
						while (stk.size() > 1 && st[stk.end()[-2]] >= st[a]) {
							connect(stk.end()[-2], stk.back());
							stk.pop_back();
						}
						if (a != stk.back()) {
							connect(a, stk.back());
							stk.back() = a;
						}
					}
				}
				stk.push_back(v);
			}
			while (stk.size() > 1) {
				connect(stk.end()[-2], stk.back());
				stk.pop_back();
			}
		}

		{
			function<array<num, 2>(int)> dfs = [&](int cur) -> array<num, 2> {
				array<num, 3> tmp = {};
				if (depth[cur] == d) {
					tmp[0] = tmp[1] = i2;
				} else {
					tmp[0] = 1;
				}
				for (int nxt : vch[cur]) {
					auto ndp = dfs(nxt);
					array<num, 3> ntmp = {};
					for (int a = 0; a < 3; a++) {
						for (int b = 0; b < 2; b++) {
							ntmp[min(2, a+b)] += tmp[a] * ndp[b];
						}
					}
					tmp = std::move(ntmp);	
				}
				vch[cur].clear();

				array<num, 2> dp = {tmp[0] + tmp[2], tmp[1]};
				return dp;
			};
			ans += dfs(1)[1];
		}
	}

	for (int i = 1; i <= N; i++) {
		ans *= 2;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 68480