#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

class Lowest_Common_Ancestor {
	int depth[200001];
	int parent[18][200001];
	vector<vector<int>>edge;
	int height = 0;
	int node;
public:
	Lowest_Common_Ancestor(int num) {
		num++;
		node = num;
		while (num) {
			height++;
			num /= 2;
		}
		edge.resize(node);
	}
	void Add_Edge(int a, int b) {
		edge[a].push_back(b);
		edge[b].push_back(a);
		return;
	}
	void Update(int rtnode) {
		queue<int>QQ;
		for (int i = 0; i < node; i++) depth[i] = INT_MAX;
		depth[rtnode] = 0;
		QQ.push(rtnode);
		while (!QQ.empty()) {
			int c = QQ.front();
			for (auto i : edge[c]) {
				if (depth[i] > depth[c] + 1) {
					depth[i] = depth[c] + 1;
					QQ.push(i);
				}
			}
			QQ.pop();
		}
		parent[0][rtnode] = -1;
		for (int i = 1; i < node; i++) {
			for (auto j : edge[i]) {
				if (depth[i] - 1 == depth[j]) {
					parent[0][i] = j;
					break;
				}
			}
		}
		for (int i = 0; i < height - 1; i++) {
			for (int j = 0; j < node; j++) {
				if (parent[i][j] < 0)parent[i + 1][j] = -1;
				else parent[i + 1][j] = parent[i][parent[i][j]];
			}
		}
		return;
	}
	int LCA(int u, int v) {
		if (depth[u] > depth[v])swap(u, v);
		for (int i = 0; i < height; i++) {
			if ((depth[v] - depth[u]) >> i & 1) {
				v = parent[i][v];
				if (depth[v] - depth[u])break;
			}
		}
		if (u == v)return u;
		for (int i = height - 1; i >= 0; i--) {
			if (parent[i][v] != parent[i][u]) {
				u = parent[i][u];
				v = parent[i][v];
			}
		}
		return parent[0][u];
	}
	bool LCA(int u, int v, int up) {
		for (int i = 17; i >= 0; i--) {
			if ((up >> i) & 1) {
				u = parent[i][u];
				v = parent[i][v];
				if (u == v)return true;
			}
		}
		return false;
	}
	int Dist(int u, int v) {
		return depth[u] + depth[v] - depth[LCA(u, v)] * 2;
	}
};

void Search(const vector<vector<int>>&edge, vector<vector<int>>&node, int depth = 0, int num = 0) {
	node[depth].push_back(num);
	for (auto i : edge[num]) {
		Search(edge, node, depth + 1, i);
	}
}

int by[200001];

void Search(const vector<vector<int>>&edge, const vector<int>&node, const vector<int>&depth, unordered_map<long long int, int>&one, Lowest_Common_Ancestor &lca, int l, int r) {
	if (l == r) {
		one[1LL * l*MOD + r] = 1;
		return;
	}
	if (l + 1 == r) {
		one[1LL * l*MOD + r] = 2;
		return;
	}
	int oone = 0;
	int zzero = 1;
	int ttwo = 0;
	int fl = l, fr = r;
	int box = lca.LCA(node[fr], node[fl]);
	int single = 0;
	while (r >= l) {
		L = l;
		R = r + 1;
		while (R - L > 1) {
			int mid = (R + L) / 2;
			if (lca.LCA(node[l], node[mid], depth[node[l]] - depth[box] - 1))L = mid;
			else R = mid;
		}
		int nzero;
		int none;
		int ntwo;
		if (l == L) {
			single++;
			l++;
			continue;
		}
		else {
			Search(edge, node, depth, one, lca, l, L);
			long long int index = 1LL * l*MOD + L;
			int o = one[index];
			int z = (by[L - l + 1] + MOD - o)%MOD;
			nzero = (1LL * zzero * z) % MOD;
			none = (1LL * zzero * o + 1LL * oone * z) % MOD;
			ntwo = (1LL * oone*o + 1LL * ttwo*(o + z)) % MOD;
		}
		zzero = nzero;
		oone = none;
		ttwo = ntwo;
		l = R;
	}
	one[1LL * fl*MOD + fr] = (oone + 1LL * zzero*single) % MOD;
	return;
}

int p[200001];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	by[0] = 1;
	for (int i = 1; i <= 200000; i++) {
		by[i] = by[i - 1] * 2;
		by[i] %= MOD;
	}

	cin >> N;
	N++;
	vector<vector<int>>edge(N);
	Lowest_Common_Ancestor lca(N);
	for (int i = 1; i < N; i++) {
		cin >> p[i];
		edge[p[i]].push_back(i);
		lca.Add_Edge(p[i], i);
	}
	lca.Update(0);
	vector<vector<int>>node(N);
	vector<int>depth(N, MOD);
	Calculate_Depth(edge, depth, 0);
	Search(edge, node);
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		if (node[i].empty())break;
		unordered_map<long long int, int>zero;
		unordered_map<long long int, int>one;
		Search(edge, node[i], depth, one, lca, 0, (int)node[i].size() - 1);
		ans += 1LL*one[node[i].size() - 1] * by[N - node[i].size()];
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 62720