#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 300000
int mod=1e9+7;
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
vector<int> v[200005];
int dep[200005];
int num[200005];
struct node{
    vector<node*> v;
    int Size;
    int mydep;
    LL val[3];
};
void dfs(node *n){
  //  printf("%d\n",n->Size);
    n->val[0]=1;
    n->val[1]=0;
    n->val[2]=0;
    if(n->v.empty()){
        n->val[1]=1;
    }
    for(auto it:n->v){
        dfs(it);
        n->val[2]=n->val[2]*(it->val[0]+it->val[1])+n->val[1]*it->val[1];
        n->val[1]=n->val[1]*it->val[0]+n->val[0]*it->val[1];
        n->val[0]*=it->val[0];
        n->val[2]%=mod;
        n->val[1]%=mod;
        n->val[0]%=mod;
    }
    n->val[0]+=n->val[2];
    n->val[0]%=mod;
}
map<int,node*> dfs(int x,int f){
    dep[x]=dep[f]+1;
    num[dep[x]]++;
    map<int,node*> ret;
    for(auto it:v[x]){
        if(it!=f){
            map<int,node*> m=dfs(it,x);
            if(m.size()>ret.size())swap(ret,m);
            for(auto &it2:m){
                if(ret.find(it2.x)!=ret.end()){
                  
                    if(ret[it2.x]->mydep==dep[x]){
                        ret[it2.x]->Size+=it2.y->Size;
                        ret[it2.x]->v.pb(it2.y);
                        
                    }
                    else if(it2.y->mydep==dep[x]){
                        it2.y->Size+=ret[it2.x]->Size;
                        it2.y->v.pb(ret[it2.x]);
                        swap(it2.y,ret[it2.x]);
                    }
                    else{
                       node *n=new node();
                        n->mydep=dep[x];
                        n->Size=it2.y->Size+ret[it2.x]->Size;
                        n->v.pb(ret[it2.x]);
                        n->v.pb(it2.y);
                        ret[it2.x]=n;
                    }
                }
                else{
                    ret[it2.x]=it2.y;
                }
            }
          //  if(x==3)printf("?%d %d\n",ret[2]->Size,ret[2]->v.size());
        }
    }
    node *n=new node();
    n->mydep=dep[x];
    n->Size=1;
    ret[dep[x]]=n;
  //  if(x==1)printf("%d %d\n",ret[2]->Size,ret[2]->v.size());
  //  if(x==3)printf("%d %d\n",ret[2]->Size,ret[2]->v.size());
   // if(x==6)printf("%d %d\n",ret[2]->Size,ret[2]->v.size());
    return ret;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        v[x].pb(i);
    }
    dep[0]=-1;
    auto m=dfs(0,0);
    LL ans=0;
    for(auto it:m){
        //if(num[i]){
        dfs(it.y);
        ans+=it.y->val[1]*f_pow(2,n+1-num[it.x]);
        ans%=mod;
      //  printf("%lld %d %lld\n",ans,num[it.x],it.y->val[1]);
       // }
    }
    printf("%lld\n",ans);
}
/*
5 4
8 1 0 3 0
0 0 1 3 8
1
*/

Measured memory_bytes: 103424