#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
const int LOG_N = 20;
const int mod = 1000000007;
const int inv2 = 500000004;

inline int add( int a, int b ) {
	return a + b >= mod ? a + b - mod : a + b;
}
inline int sub( int a, int b ) {
	return a - b < 0 ? a - b + mod : a - b;
}
inline int mul( int64_t a, int64_t b ) {
	return ( int ) ( a * b % mod );
}

int fa[ LOG_N ][ N ];
int time_in[ N ], time_out[ N ], time_;
vector< int > G[ N ], ord[ N ], vtree[ N ];
void dfs( int, int, int );
int vdfs( int );
int process( int );
inline int lca( int, int );
inline bool anc( int, int );

int main() {
	ios_base::sync_with_stdio( false );
	cin.tie( nullptr );
	int n; cin >> n;
	for ( int i = 1 ; i <= n ; ++ i ) {
		int x; cin >> x;
		G[ x ].push_back( i );
	}
	dfs( 0, 0, 0 );
	for ( int i = 1 ; i < LOG_N ; ++ i )
		for ( int j = 0 ; j <= n ; ++ j )
			fa[ i ][ j ] = fa[ i - 1 ][ fa[ i - 1 ][ j ] ];
	int ans = 0;
	for ( int i = 0 ; i <= n ; ++ i )
		ans = add( ans, process( i ) );
	int base = 1;
	for ( int i = 0 ; i <= n ; ++ i )
		base = add( base, base );
	cout << mul( ans, base ) << '\n';
	return 0;
}

void dfs( int u, int f, int d ) {
	fa[ 0 ][ u ] = f;
	time_in[ u ] = time_++;
	ord[ d ].push_back( u );
	for ( int v : G[ u ] )
		dfs( v, u, d + 1 );
	time_out[ u ] = time_;
}

inline bool anc( int u, int v ) {
	return time_in[ u ] <= time_in[ v ] and time_out[ v ] <= time_out[ u ];
}

inline int lca( int u, int v ) {
	if ( anc( u, v ) ) return u;
	for ( int i = LOG_N - 1 ; i >= 0 ; -- i ) 
		if ( not anc( fa[ i ][ u ], v ) )
			u = fa[ i ][ u ];
	return fa[ 0 ][ u ];
}

void v_add_edge( int u, int v ) {
	vtree[ u ].push_back( v );
}

int process( int d ) {
	static int stk[ N << 1 ], clr[ N << 1 ];
	const auto seq = ord[ d ];
	if ( seq.empty() ) return 0;
	size_t stk_pt = 0; stk[ stk_pt ++ ] = 0;

	auto add_vstk = [ &stk_pt ] ( int x ) {
		if ( x == 0 ) return -1;
		bool flag = false;
		int g = lca( x, stk[ stk_pt - 1 ] );
		if ( g != stk[ stk_pt - 1 ] ) {
			while ( stk_pt >= 2 and anc( g, stk[ stk_pt - 2 ] ) ) {
				v_add_edge( stk[ stk_pt - 2 ], stk[ stk_pt - 1 ] );
				stk_pt--;
			}
			if ( stk[ stk_pt - 1 ] != g ) {
				v_add_edge( g, stk[ -- stk_pt ] );
				stk[ stk_pt ++ ] = g; flag = true;
			}
		}
		stk[ stk_pt ++ ] = x;
		return flag ? g : -1;
	};

	size_t clr_sz = 0;
	clr[ clr_sz ++ ] = 0;
	for ( auto u : seq ) {
		int x = add_vstk( u );
		clr[ clr_sz ++ ] = u;
		if ( x != -1 ) clr[ clr_sz ++ ] = x;
	}
	while ( --stk_pt >= 1 )
		v_add_edge( stk[ stk_pt - 1 ], stk[ stk_pt ] );
	int ans = vdfs( 0 );
	for ( size_t i = 0 ; i < clr_sz ; ++ i )
		vtree[ clr[ i ] ].clear();
	return ans;
}

int vdfs( int u ) {
	if ( vtree[ u ].size() == 0 )
		return inv2;
	vector< int > subv;
	for ( int v : vtree[ u ] )
		subv.push_back( vdfs( v ) );
	vector< int > bus = subv;
	for ( auto& x : bus ) x = sub( 1, x );
	for ( size_t i = 2 ; i <= bus.size() ; ++ i )
		bus[ bus.size() - i ] = mul( bus[ bus.size() - i ], bus[ bus.size() - i + 1 ] );
	int cur = 1, ret = 0;
	for ( size_t i = 1 ; i < subv.size() ; ++ i ) {
		ret = add( ret, mul( mul( cur, subv[ i - 1 ] ), bus[ i ] ) );
		cur = mul( cur, sub( 1, subv[ i - 1 ] ) );
	}
	return add( ret, mul( cur, subv.back() ) );
}

Measured memory_bytes: 54912