Problem:
Score : 1000 points

Problem Statement

Snuke has a rooted tree with N+1 vertices.
The vertices are numbered 0 through N, and Vertex 0 is the root of the tree.
The parent of Vertex i (1 \leq i \leq N) is Vertex p_i.

Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them.
The play begins with placing one marble on some of the vertices, then proceeds as follows:

If there is a marble on Vertex 0, move the marble into the box.

Move each marble from the vertex to its parent (all at once).

For each vertex occupied by two or more marbles, remove all the marbles from the vertex.

If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play.

There are 2^{N+1} ways to place marbles on some of the vertices.
For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007.

Constraints

1 \leq N < 2 \times 10^{5}

0 \leq p_i < i

Partial Scores

In the test set worth 400 points, N < 2{,}000.

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_{N}

Output

Print the answer.

Sample Input 1

2
0 0

Sample Output 1

8

When we place a marble on both Vertex 1 and 2, there will be multiple marbles on Vertex 0 by step 2. In such a case, these marbles will be removed instead of being moved to the box.

Sample Input 2

5
0 1 1 0 4

Sample Output 2

96

Sample Input 3

31
0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23

Sample Output 3

730395550

Be sure to compute the sum modulo 1,000,000,007.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

vector<int> G[1 << 18];



typedef vector<vector<ll>> vec;

void merge(vec &a, vec &b) {
	if (a.size() < b.size())swap(a, b);
	int len = a.size();
	int l = b.size();
	rep(i, l) {
		per(x, 3) {
			ll memo = a[len - 1 - i][x];
			a[len - 1 - i][x] = 0;
			rep(y, 3) {
				int s = min(x + y, 2);
				a[len - 1 - i][s] += memo * b[l - 1 - i][y] % mod;
				if (a[len - 1 - i][s] >= mod)a[len - 1 - i][s] -= mod;
			}
		}
	}
}

vec dfs(int v) {
	vec ret; 
	int ma = 0;
	//vector<vec> nex;
	rep(j, G[v].size()) {
		int to = G[v][j];
		auto nex=dfs(to);
		ma = max(ma, (int)min(ret.size(), nex.size()));
		merge(ret, nex);
	}
	if (ma) {
		int len = ret.size();
		rep(i, ma) {
			ret[len - 1 - i][0] += ret[len - 1 - i][2];
			if (ret[len - 1 - i][0] >= mod)ret[len - 1 - i][0] -= mod;
			ret[len - 1 - i][2] = 0;
		}
	}
	ret.push_back(vector<ll>{ 1,1,0 });
	return ret;
}

int cnt[1 << 18];
void dfs2(int v,int d) {
	cnt[d]++;
	rep(j, G[v].size()) {
		int to = G[v][j];
		dfs2(to, d + 1);
	}
}
ll t2[1 << 18];
void solve() {
	int n; cin >> n;
	rep1(i, n) {
		int p; cin >> p; G[p].push_back(i);
	}
	dfs2(0, 0);
	t2[0] = 1;
	rep(i, (1 << 18) - 1)t2[i + 1] = t2[i] * 2 % mod;
	vec fin = dfs(0);
	ll ans = 0;
	per(i, (int)fin.size()) {
		int d = (int)fin.size() - 1 - i;
		int u = n + 1 - cnt[d];
		ans += t2[u] * fin[i][1] % mod;
		if (ans >= mod)ans -= mod;
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}