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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())

#ifdef LOCAL
#define cerr cout
#else
#endif

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

struct tree {
	int n;
	vector<vector<int>> adj;
	tree(int n) : n(n), adj(n) { }
	void add_edge(int s, int t) {
		adj[s].push_back(t);
		adj[t].push_back(s);
	}
	vector<int> pos, tour, depth, pos_end;
	vector<vector<int>> table;
	int argmin(int i, int j) { return depth[i] < depth[j] ? i : j; }
	void rootify(int r) {
		pos.resize(n);
		pos_end.resize(n);
		function<void (int,int,int)> dfs = [&](int u, int p, int d) {
			pos[u] = depth.size();
			tour.push_back(u);
			depth.push_back(d);
			for (int v: adj[u]) {
				if (v != p) {
					dfs(v, u, d+1);
					pos_end[u] = depth.size();
					tour.push_back(u);
					depth.push_back(d);
				}
			}
		}; dfs(r, r, 0);
		int logn = sizeof(int)*__CHAR_BIT__-1-__builtin_clz(tour.size()); // log2
		table.resize(logn+1, vector<int>(tour.size()));
		iota(all(table[0]), 0);
		for (int h = 0; h < logn; ++h) 
			for (int i = 0; i+(1<<h) < tour.size(); ++i)
				table[h+1][i] = argmin(table[h][i], table[h][i+(1<<h)]);
	}
	int lca(int u, int v) {
		int i = pos[u], j = pos[v]; if (i > j) swap(i, j);
		int h = sizeof(int)*__CHAR_BIT__-1-__builtin_clz(j-i); // = log2
		return i == j ? u : tour[argmin(table[h][i], table[h][j-(1<<h)])];
	}
	int getDepth(int u){
		return depth[pos[u]];
	}
	
	void aux_tree(vector<int> nodes, vector<vector<int> > & adj_aux, vector<int> & start_times){
		// adj_aux stores the children
		// sort(nodes.begin(), nodes.end(), [&](int i, int j){})
		for(int x : nodes) start_times.push_back(pos[x]);
		sort(all(start_times));
		for(int i = 1; i < (int) nodes.size();  i++){
			start_times.push_back(pos[lca(tour[start_times[i]], tour[start_times[i - 1]])]);
		}
		sort(all(start_times));
		start_times.erase(unique(start_times.begin(), start_times.end()), start_times.end());
		adj_aux.resize(start_times.size());
		stack<int> st;
		st.push(0);
		for(int i = 1; i < (int)start_times.size(); i++){
			while(pos_end[tour[start_times[st.top()]]] < start_times[i]){
				st.pop();
			}
			adj_aux[st.top()].push_back(i);
			st.push(i);
		}
	}
	vector<vector<int> > partitionDepths(){
		vector<vector<int>> ret(*max_element(depth.begin(), depth.end()) + 1);
		for(int i = 0; i < n; i++) ret[depth[pos[i]]].push_back(i);
		return ret;
	}
};

const int mod = 1e9 + 7;
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
	int x = 1 % mod;
	while(b){
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a){ return powr(a, mod - 2);}
const int N = 2e5 + 10;
int pw2[N];
int main(){
	pw2[0] = 1;
	for(int i = 1; i < N; i++)	pw2[i] = add(pw2[i - 1], pw2[i - 1]);
	int n;
	sd(n);
	tree T(n + 1);
	for(int i = 1; i <= n; i++){
		int x;
		sd(x);
		T.add_edge(i, x);
	}
	T.rootify(0);
	vector<vector<int>> partition_depths = T.partitionDepths();
	int ans = 0;
	for(auto it : partition_depths) if(!it.empty()){
		vector<vector<int>> adj;
		vector<int> start_times;
		T.aux_tree(it, adj, start_times);
		vector<int> dp(start_times.size()), total(start_times.size());
		for(int i = (int)start_times.size() - 1; i >= 0; i--){
			int num = 0;
			int t = 2;
			int sm = 0;
			int prod = 1;
			for(int v : adj[i]){
				assert(v > i);
				t = mul(t, total[v]);
				sm = add(sm, mul(dp[v], inv(sub(total[v], dp[v]))));
				prod = mul(prod, sub(total[v], dp[v]));
				num++;
			}
			total[i] = t;
			dp[i] = (num == 0) ? 1 : mul(2, mul(sm, prod));
		}
		ans =add(ans, mul(dp[0], pw2[n + 1 - (int)start_times.size()]));
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 72904