#include<cstdio>
#include<vector>
const long long mod = 1e9+7;
std::vector<int>g[200005];
int depth[200005];
std::vector<int>keep[200005];
long long pow2[200005];
long long f[200005][3];
int in[200005], out[200005];
int bit[200005];
int fa[200005][18];
//merge already
int sum[200005];
int queue[200005];
std::vector<int>son[200005];
int timer = -1;

void dfs(int u){
    in[u] = ++timer;
    keep[depth[u]].push_back(u);
    for(int v: g[u]){
        depth[v] = depth[u]+1;
        dfs(v);
    }
    out[u] = timer;
}

void dp(int u,int d){
    if(depth[u]==d) f[u][0] = f[u][1] = 1, f[u][2] = 0;
    else{
        f[u][0] = 1, f[u][1] = f[u][2] = 0;
        for(int v: g[u]){
            dp(v,d);
            long long last0 = f[u][0], last1 = f[u][1], last2 = f[u][2];
            f[u][0] = (f[v][0]+f[v][2])*last0%mod;
            f[u][1] = ((f[v][0]+f[v][2])*last1%mod+f[v][1]*last0%mod)%mod;
            f[u][2] = ((f[v][0]+f[v][1]+f[v][2])*last2%mod+f[v][1]*last1%mod)%mod;
        }
        /*for(int i = 0; i < 3; i++) printf("f[%d][%d] = %lld ",u,i,f[u][i]);
        printf("\n");*/
    }
}

void doDP(int u,int d){
    if(depth[u]==d) f[u][0] = f[u][1] = 1, f[u][2] = 0;
    else{
        f[u][0] = 1, f[u][1] = f[u][2] = 0;
        for(int v: son[u]){
            long long last0 = f[u][0], last1 = f[u][1], last2 = f[u][2];
            f[u][0] = (f[v][0]+f[v][2])*last0%mod;
            f[u][1] = ((f[v][0]+f[v][2])*last1%mod+f[v][1]*last0%mod)%mod;
            f[u][2] = ((f[v][0]+f[v][1]+f[v][2])*last2%mod+f[v][1]*last1%mod)%mod;
        }
        /*for(int i = 0; i < 3; i++) printf("f[%d][%d] = %lld ",u,i,f[u][i]);
        printf("\n");*/
    }
}

void change(int p,int v,int n){
    while(p<=n){
        bit[p] += v;
        p += p&-p;
    }
}

int ask(int p){
    int res = 0;
    while(p!=0){
        res += bit[p];
        p -= p&-p;
    }
    return res;
}

void preWork(int n){
    for(int j = 1; j <= 17; j++){
        for(int i = 1; i <= n; i++){
            int last = fa[i][j-1];
            if(last!=0) fa[i][j] = fa[last][j-1];
            else fa[i][j] = 0;
        }
    }
}

int subtreeSum(int u){
    int l = in[u], r = out[u];
    return ask(r)-ask(l-1);
}

int jump(int u,int uSum){
    for(int i = 17; i >= 0; i--){
        if(fa[u][i]!=0){
            int last = fa[u][i];
            if(subtreeSum(last)==uSum){
                u = last;
            }
        }
    }
    if(fa[u][0]!=0) return fa[u][0];
    else return u;
}

int main(){
    int n;
    scanf("%d",&n);
    n++;
    pow2[0] = 1;
    for(long long i = 1; i <= n+1; i++) pow2[i] = pow2[i-1]*2ll%mod;
    for(int i = 2; i <= n; i++){
        int p;
        scanf("%d",&p);
        p++;
        g[p].push_back(i);
        fa[i][0] = p;
    }
    fa[1][0] = 0, timer = 0, depth[1] = 1; 
    dfs(1);
    preWork(n);
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        int cnt = keep[i].size();
        if(cnt==0) break;
        //dp(1,i);
        int h = 0, t = -1;
        for(int u: keep[i]) change(in[u],1,n), queue[++t] = u, sum[u] = 1;
        while(h<=t){
            int u = queue[h++];
            doDP(u,i);
            if(u!=1){
                int parent = jump(u,sum[u]);
                sum[parent] += sum[u];
                son[parent].push_back(u);
                if(sum[parent]==subtreeSum(parent)) queue[++t] = parent;
            }
        }
        for(int u: keep[i]) change(in[u],-1,n);
        for(int i = 0; i <= t; i++){
            int u = queue[i];
            son[u].clear();
            sum[u] = 0;
        }
        ans += f[1][1]*pow2[n-cnt]%mod; if(ans>=mod) ans -= mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 63344