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

typedef pair<int, int> pii;

const int mod = 1000*1000*1000+7;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}
int po[200010];

int N, ans;
vector<vector<int> > adj;
vector<int> dv[200010];
int par[20][200010], dep[200010];

void dfs(int u) {
    dv[ dep[u] ].push_back(u);

    for(int i = 1; i < 20; i++) {
        int t = par[i - 1][u];
        if(t == -1) break;
        par[i][u] = par[i - 1][t];
    }
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        dep[v] = dep[u] + 1;
        par[0][v] = u;
        dfs(v);
    }
}

int LCA(int a, int b) {
    if(dep[a] < dep[b]) swap(a, b);
    int diff = dep[a] - dep[b];
    for(int i = 0; i < 20; i++) {
        if(diff & (1 << i)) a = par[i][a];
    }
    if(a == b) return a;
    for(int i = 20; i--;) {
        if(par[i][a] != par[i][b]) {
            a = par[i][a];
            b = par[i][b];
        }
    }
    return par[0][a];
}

vector<int> Tadj[200010];
stack<int> stk;

void build(int d) {
    Tadj[0].clear();
    for(int i = 0; i < dv[d].size(); i++) {
        int u = dv[d][i];

        Tadj[u].clear();
    }

    for(int i = 1; i < dv[d].size(); i++) {
        int u = dv[d][i - 1];
        int v = dv[d][i];
        int x = LCA(u, v);

        Tadj[x].clear();
    }

    while(!stk.empty()) stk.pop();
    for(int i = 0; i < dv[d].size(); i++) {
        int x, u, v;
        if(i != dv[d].size() - 1) {
            u = dv[d][i];
            v = dv[d][i + 1];
            x = LCA(u, v);
        }
        else {
            u = dv[d][i];
            x = 0;
        }

        stk.push(u);
        while(dep[ stk.top() ] > dep[x]) {
            int t = stk.top(); stk.pop();
            if(stk.empty() || dep[ stk.top() ] <= dep[x]) {
                Tadj[x].push_back(t);
                break;
            }
            else {
                int q = stk.top();
                Tadj[q].push_back(t);
            }
        }
        if(stk.empty() || stk.top() != x) stk.push(x);
    }
}

int dp[2][200010];

void dfs2(int u) {
    if(Tadj[u].size() == 0) {
        dp[0][u] = 1;
        dp[1][u] = 1;
        return;
    }

    int mul = 1;
    int sum = 0;
    int tot = 1;
    for(int i = 0; i < Tadj[u].size(); i++) {
        int v = Tadj[u][i];
        dfs2(v);
        mul = 1LL * mul * dp[0][v] % mod;
        sum += 1LL * dp[1][v] * inv(dp[0][v]) % mod;
        sum %= mod;
        tot = 1LL * tot * (dp[0][v] + dp[1][v]) % mod;
    }

    dp[1][u] = 1LL * mul * sum % mod;
    dp[0][u] = (tot + mod - dp[1][u]) % mod;
}

void solve(int d) {
    dfs2(0);

    ans += 1LL * dp[1][0] * po[ N + 1 - (int)dv[d].size() ] % mod;
    ans %= mod;
}

int main() {
    po[0] = 1;
    for(int i = 1; i < 200010; i++) {
        po[i] = po[i - 1] * 2 % mod;
    }

    scanf("%d", &N);

    adj.resize(N + 1);
    for(int i = 1; i <= N; i++) {
        int p; scanf("%d", &p);
        adj[p].push_back(i);
    }

    memset(par, -1, sizeof(par));
    memset(dep, 0, sizeof(dep));
    dfs(0);

    ans = 0;
    for(int i = 0; i < 200010; i++) {
        if(dv[i].size() == 0) break;

        build(i);
        solve(i);
    }

    printf("%d", ans);
}


Measured memory_bytes: 51840