#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=1<<18,MAX_LOG=20,INF=1<<29;
int N;
int dis[MAX],to[MAX],par[MAX_LOG][MAX];
ll dp[MAX][2];
vector<int> G[MAX];
vector<int> depth[MAX];

void DFS(int u,int p,int d){
    depth[d].push_back(u);
    dis[u]=d;
    par[0][u]=p;
    for(int to:G[u]){
        if(to==p) continue;
        DFS(to,u,d+1);
    }
}

void init(){
    for(int k=0;k+1<MAX_LOG;k++){
        for(int i=0;i<=N;i++){
            if(par[k][i]<0) par[k+1][i]=-1;
            else par[k+1][i]=par[k][par[k][i]];
        }
    }
}

int lca(int u,int v){
    if(dis[u]>dis[v]) swap(u,v);
    for(int i=0;i<20;i++){
        if(((dis[v]-dis[u])>>i)&1) v=par[i][v];
    }
    if(u==v) return u;
    
    for(int i=19;i>=0;i--){
        if(par[i][u]!=par[i][v]){
            u = par[i][u];
            v = par[i][v];
        }
    }
    return par[0][u];
}

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    
    for(int i=1;i<=N;i++){
        int a;cin>>a;
        G[a].push_back(i);
    }
    
    DFS(0,-1,0);
    
    init();
    
    ll ans=0;
    ll base=rui(2,mod-2);
    
    for(int i=0;i<=N;i++){
        dp[i][0]=1;
        to[i]=i;
    }
    
    for(int d=0;d<=N;d++){
        if(si(depth[d])==0) continue;
        if(si(depth[d])==1){
            ans+=base;
            ans%=mod;
            continue;
        }
        set<int> reset;
        
        vector<pair<int,int>> S;
        for(int i=0;i+1<si(depth[d]);i++){
            dp[depth[d][i]][0]=mod+1-base;
            dp[depth[d][i]][1]=base;
            to[depth[d][i]]=depth[d][i];
            reset.insert(depth[d][i]);
            
            dp[depth[d][i+1]][0]=mod+1-base;
            dp[depth[d][i+1]][1]=base;
            to[depth[d][i+1]]=depth[d][i+1];
            reset.insert(depth[d][i+1]);
            
            int u=lca(depth[d][i],depth[d][i+1]);
            dp[u][0]=1;
            dp[u][1]=0;
            to[u]=u;
            reset.insert(u);
            S.push_back(mp(dis[u],i));
        }
        sort(all(S),[](auto a,auto b){
            if(a.fi==b.fi) return a.se<b.se;
            return a.fi>b.fi;
        });
        
        for(int i=0;i<si(S);i++){
            while(to[depth[d][S[i].se]]!=depth[d][S[i].se]) depth[d][S[i].se]=to[depth[d][S[i].se]];
            while(to[depth[d][S[i].se+1]]!=depth[d][S[i].se+1]) depth[d][S[i].se+1]=to[depth[d][S[i].se+1]];
            int a=to[depth[d][S[i].se]],b=to[depth[d][S[i].se+1]];
            int u=lca(a,b);
            //cout<<d<<" "<<a<<" "<<b<<" "<<u<<endl;
            if(dp[u][0]==1){
                dp[u][0]=dp[a][0];
                dp[u][1]=dp[a][1];
            }
            
            dp[u][1]=dp[u][0]*dp[b][1]%mod+dp[u][1]*dp[b][0]%mod;
            dp[u][1]%=mod;
            
            dp[u][0]*=dp[b][0];
            dp[u][0]%=mod;
            
            if(i==si(S)-1) ans+=dp[u][1];
            else{
                int aa=to[depth[d][S[i+1].se]],bb=to[depth[d][S[i+1].se+1]];
                int uu=lca(aa,bb);
                
                if(u!=uu){
                    dp[u][0]=mod+1-dp[u][1];
                }
            }
            
            to[depth[d][S[i].se]]=u;
            to[depth[d][S[i].se+1]]=u;
            to[a]=u;
            to[b]=u;
        }
        
        for(auto u:reset){
            dp[u][0]=1;
            dp[u][1]=0;
            to[u]=u;
        }
        
        ans%=mod;
    }
    
    ans%=mod;
    
    for(int i=0;i<=N;i++){
        ans*=2;
        ans%=mod;
    }
    
    cout<<ans<<endl;
    
}



Measured memory_bytes: 64128