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 <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 200010
vector<int> g[N];
ll d[N], two[N];
int n;

void dfs(int u, int dep){
	d[dep]++;
	for(auto v: g[u]) dfs(v, dep+1);
}

vector<vector<ll>> rec(int u){
	vector<vector<ll>> dp;
	int mx = 0;
	for(auto v: g[u]){
		auto dp2 = rec(v);
		if(dp.size()<dp2.size()) dp.swap(dp2);
		chmax(mx, (int)dp2.size());
		rep(i, dp2.size()){
			auto &a = dp[dp.size()-i-1], &b = dp2[dp2.size()-i-1];
			ll c[3] = {};
			for(int j = 2; j >= 0; j--) rep(k, 3) (c[min(2, j+k)]+=a[j]*b[k])%=mod;
			rep(j, 3) a[j] = c[j];
		}
	}
	for(int i = 0; i < mx; i++){
		auto &x = dp[dp.size()-i-1];
		(x[0]+=x[2])%=mod;
		x[2] = 0;
	}
	dp.emplace_back((vector<ll>){1, 1, 0});
	return dp;
}

int main(){
	cin>>n;
	rep(i, n){
		int p;
		cin>>p;
		g[p].push_back(i+1);
	}
	dfs(0, 0);
	auto dp = rec(0);
	ll res = 0;
	two[0] = 1;
	rep(i, n) (two[i+1]=two[i]*2%mod);
	rep(i, dp.size()) (res+=dp[dp.size()-i-1][1]*two[n+1-d[i]])%=mod;
	cout<<res<<endl;
	/*cerr<<"DEBUG"<<endl;
	rep(i, dp.size()) cerr<<dp[i]<<endl;
	cerr<<endl;
	rep(i, n) cerr<<d[i]<<endl;
	cerr<<endl;*/
	return 0;
}