/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef int64_t LL;
typedef uint64_t ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
// 0-based
#define MAX_LV 17
VI e[SIZE];
VI gg[SIZE];
int jump[MAX_LV+1][SIZE],lv[SIZE];
void __init(int x,int lt){
    gg[lv[x]].PB(x);
    jump[0][x]=lt;
    REP(i,SZ(e[x])){
        int y=e[x][i];
        if(y!=lt){
            lv[y]=lv[x]+1;
            __init(y,x);
        }
    }
}
int adv(int x,int v){
    for(int i=0;(1<<i)<=v;i++){
        if((v>>i)&1)x=jump[i][x];
    }
    return x;
}
int lca(int x,int y){
    if(lv[x]>lv[y])x=adv(x,lv[x]-lv[y]);
    else y=adv(y,lv[y]-lv[x]);
    if(x==y)return x;
    for(int i=MAX_LV;i>=0;i--)
        if(jump[i][x]!=jump[i][y]){x=jump[i][x];y=jump[i][y];}
    return jump[0][x];
}
int dis(int x,int y){
    int z=lca(x,y);
    return lv[x]+lv[y]-lv[z]*2;
}
void build(int root,int N){
    __init(root,root);
    REPP(i,1,MAX_LV+1){
        REP(x,N)
            jump[i][x]=jump[i-1][jump[i-1][x]];
    }
}
struct Union_Find{
    int d[SIZE],num[SIZE];
    void init(int n){
        REP(i,n)d[i]=i,num[i]=1;
    }
    void clear(const VI& cc){
        REP(i,SZ(cc))d[cc[i]]=cc[i],num[cc[i]]=1;
    }
    int find(int x){return (x!=d[x])?(d[x]=find(d[x])):x;}
    bool is_root(int x){return d[x]==x;}
    bool uu(int x,int y){
        DEBUG("uu",x,y);
        x=find(x);
        y=find(y);
        if(x==y)return 0;
        if(num[x]>num[y])swap(x,y);
        num[y]+=num[x];
        d[x]=y;
        return 1;
    }
}U;
LL dp[SIZE][2];
bool cmp(const PII& x,const PII& y){
    return MP(-lv[x.F],x.S)<MP(-lv[y.F],y.S);
}
LL mypow(LL x,LL y){
    x%=MOD;
    LL res=1%MOD;
    while(y){
        if(y&1)res=res*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return res;
}
LL inv(LL x){
    return mypow(x,MOD-2);
}
int N;
LL build2(const VI& d){
    VPII ker;
    VPII pp;
    if(SZ(d)==1){
        return mypow(2,N);
    }
    REPP(i,1,SZ(d)){
        int z=lca(d[i-1],d[i]);
        pp.PB(MP(z,i));
    }
    REP(i,SZ(d)){
        REP(j,2)dp[d[i]][j]=1;
    }
    sort(ALL(pp),cmp);
    for(int i=0,j;i<SZ(pp);i=j){
        VI now{U.find(d[pp[i].S-1])};
        LL tmp[2]={};
        LL mul=dp[now[0]][0],all=(dp[now[0]][0]+dp[now[0]][1])%MOD;
        for(j=i;j<SZ(pp)&&pp[j].F==pp[i].F;j++){
            now.PB(U.find(d[pp[j].S]));
            mul=mul*dp[now.back()][0]%MOD;
            all=all*(dp[now.back()][0]+dp[now.back()][1])%MOD;
        }
        for(j=i;j<SZ(pp)&&pp[j].F==pp[i].F;j++)
            U.uu(d[pp[j].S-1],d[pp[j].S]);
        
        REP(k,SZ(now)){
            ADD(tmp[1],mul*dp[now[k]][1]%MOD*inv(dp[now[k]][0]));
        }
        int z=U.find(d[pp[i].S]);
        DEBUG("z",z);
        tmp[0]=all;ADD(tmp[0],-tmp[1]);
        REP(k,2)dp[z][k]=tmp[k];
         
    }
    DEBUG("final",d[0],U.find(d[0]));
    return dp[U.find(d[0])][1]*mypow(2,N+1-SZ(d));
}
int new_id;
int main(){
    R(N);
    FOR(i,1,N){
        int y;
        R(y);
        e[y].PB(i);
    }
    build(0,N+1);
    U.init(N+1);
    LL an=0;
    REP(i,SIZE){
        if(SZ(gg[i])){
            ADD(an,build2(gg[i]));
        }
        else break;
    }
    W(an);
    return 0;
}


Measured memory_bytes: 131072