#include<queue>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
template<unsigned MOD> struct ModInt {
    static const unsigned static_MOD = MOD;
    unsigned x;
    void undef() { x = (unsigned)-1; }
    bool isnan() const { return x == (unsigned)-1; }
    inline int geti() const { return (int)x; }
    ModInt() { x = 0; }
    ModInt(const ModInt &y) { x = y.x; }
    ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }
    ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }
    ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }
    ModInt operator-() const { return (x ? MOD-x: 0); }

    ModInt inv() const {
	unsigned a = MOD, b = x; int u = 0, v = 1;
	while (b) {
	    int t = a / b;
	    a -= t * b; swap(a, b);
	    u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return ModInt(u);
    }
    ModInt pow(long long y) const {
	ModInt b = *this, r = 1;
	if (y < 0) { b = b.inv(); y = -y; }
	for (; y; y>>=1) {
	    if (y&1) r *= b;
	    b *= b;
	}
	return r;
    }
    friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }
    friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }
    friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }
    friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }
    friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }
    friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }
    friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }
};

const LL MOD = 1000000007;
//const LL MOD = 998244353;
typedef ModInt<MOD> Mint;


const int MAX_V = 200111;
const int LOG_V = 19;
int N;
VI G[MAX_V];
int depth[MAX_V];
int parent[LOG_V][MAX_V];
VI ord; 
int skip[MAX_V];

void build_lca(/* VI G[], int N, */ const int root=0) {
    depth[root] = 0;
    parent[0][root] = root;
    ord.reserve(N);
    ord.push_back(root);
    REP (i_, N) {
	int v = ord[i_];
	EACH (e, G[v]) if (*e != parent[0][v]) {
	    ord.push_back(*e);
	    depth[*e] = depth[v] + 1;
	    parent[0][*e] = v;

	    if (G[v].size() >= 2u) {
		skip[*e] = v;
	    } else {
		skip[*e] = skip[v];
	    }
	}
    }
    REP (t, LOG_V-1) REP (v, N) parent[t+1][v] = parent[t][parent[t][v]];
}

int lca(int x, int y) {
    if (depth[x] < depth[y]) swap(x, y);
    REP (t, LOG_V) if ((depth[x] - depth[y]) & (1 << t)) x = parent[t][x];
    if (x == y) return x;
    for (int t=LOG_V; t--;) {
	if (parent[t][x] != parent[t][y]) {
	    x = parent[t][x];
	    y = parent[t][y];
	}
    }
    return parent[0][x];
}

int mark[MAX_V];
int cnt;
Mint MUL[MAX_V], SUM[MAX_V], MUL_ALL[MAX_V];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) {
	int p;
	scanf("%d", &p);
	G[p].push_back(i+1);
    }
    N++;

    build_lca();

    Mint ans = 0;
    for (int i=0; i<N; ) {
	cnt++;
	int j = i;
	while (j < N && depth[ord[i]] == depth[ord[j]]) j++;

	priority_queue<pair<int, int> > Q; // (depth, v);
	for (int k=i; k<j; k++) {
	    int v = ord[k];
	    Q.emplace(depth[v], v);
	    MUL[v] = SUM[v] = 1;
	    MUL_ALL[v] = 2;
	}
	while (Q.size() > 1u) {
	    int v = Q.top().second;
	    Q.pop();
	    int s = skip[v];
	    Mint p1 = MUL[v] * SUM[v];
	    Mint p0 = MUL_ALL[v] - p1;

	    if (mark[s] != cnt) {
		MUL[s] = 1;
		SUM[s] = 0;
		MUL_ALL[s] = 1;
		mark[s] = cnt;
		Q.emplace(depth[s], s);
	    }
	    MUL[s] *= p0;
	    SUM[s] += p1 / p0;
	    MUL_ALL[s] *= p0 + p1;
	}

	{
	    int v = Q.top().second;
	    ans += MUL[v] * SUM[v] * Mint(2).pow(N - (j-i));
	}

	i = j;
    }

    printf("%d\n", ans.geti());
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 31488