#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || fr_ch>'9') {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while(fr_ch>='0' && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

template< typename T > inline void Max (T &a, T &b) {if(a<b) a=b;}
template< typename T > inline void Min (T &a, T &b) {if(b<a) a=b;}
template< typename T > inline void Swap(T &a, T &b) {T c=a;a=b;b=c;}
template< typename T > inline T Abs(T &a) {if(a<0) return -a; else return a;}

const double pi   = acos(-1.0) ;
const int MOD     = (int)1e9+7 ;
const int INF     = (int)0x3f3f3f3f ;
const LL  LINF    = (LL)INF<<32|INF ;
const int SINF    = (uint)(-1)>>1 ;
const LL  SLINF   = (ULL)(-1)>>1 ;
const double DINF = 1e50 ;
const double eps  = 1e-8 ;
const int maxn    = (int) 2e5+20 ;
const int maxm    = (int) 25000+20 ;
const int maxk    = (int) 1000+20 ;

inline int sig(double x) {return x<-eps?-1:x>eps;}
inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;}
template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;}

//--------------------start--------------------

int n;
vector<int> G[maxn];
vector<int> g[maxn];

int dfn[maxn],dfsp[maxn<<1],dep[maxn],clk;

struct RMQ
{
    int a[20][maxn<<1],lg[maxn<<1],n;

    inline int Mx(int x,int y) {return dep[x] < dep[y] ? x : y ;}

    inline void init(int *b,int _n)
    {
        n=_n;
        for(int i=1;i<=n;i++) a[0][i]=b[i];
        lg[1]=0; for(int i=2;i<=n;i++) lg[i]=lg[i-1]+!(i&(i-1));

        for(int i=1;i<=lg[n];i++)
            for(int j=1;j+(1<<i)-1<=n;j++)
                a[i][j] = Mx(a[i-1][j],a[i-1][j+(1<<(i-1))]);
    }

    inline int rmq(int x,int y)
    {
        if(x>y) Swap(x,y);
        int c = lg[y-x+1] ;
        return Mx(a[c][x],a[c][y-(1<<c)+1]);
    }
}T;

void dfs(int u,int d)
{
    dfsp[++clk]=u; dfn[u]=clk; dep[u]=d; g[d].pb(u);
    for(int i=0;i<G[u].size();i++) dfs(G[u][i],d+1), dfsp[++clk]=u;
}

int po[maxn];

int stk[maxn],dp[maxn][2],top;

inline int mer(int R)
{
    int d0=dep[T.rmq(dfn[stk[R-1]],dfn[stk[R]])], L=R-1;
    while(L>1 && d0 == dep[T.rmq(dfn[stk[L-1]],dfn[stk[L]])]) L--;

    int sum=1, d[2]={0}, tot=1, tmp;

    for(int i=L;i<=R;i++)
    {
        sum=(LL)sum*dp[i][0]%MOD;
        tot=(LL)tot*(dp[i][0]+dp[i][1])%MOD;
    }

    for(int i=L;i<=R;i++)
    {
        tmp=dp[i][1]*(sum*fp(dp[i][0],MOD-2,MOD)%MOD)%MOD;
        d[1]+=tmp; if(d[1]>=MOD) d[1]-=MOD;
    }

    d[0]=tot-d[1];
    if(d[0]<0) d[0]+=MOD;

    stk[L]=stk[R];

    dp[L][0]=d[0];
    dp[L][1]=d[1];

    return L;
}

int gao(vector<int> &vec)
{
    if(vec.size()==0) return 0;
    top=0;
    int pos;
    for(int i=0;i<vec.size();i++)
    {
        int u=vec[i];
        while(top>1 && dep[T.rmq(dfn[stk[top-1]],dfn[stk[top]])] > dep[T.rmq(dfn[stk[top]],dfn[u])])
            top=mer(top);
        stk[++top]=u; dp[top][0]=dp[top][1]=1;
    }
    while(top>1) top=mer(top);
    return (LL)dp[1][1]*po[n+1-vec.size()]%MOD;
}

void work()
{
    read(n);
    for(int i=1;i<=n;i++)
    {
        int p; read(p);
        G[p].pb(i);
    }

    clk=0;
    dfs(0,0);
    T.init(dfsp,clk);

    po[0]=1; for(int i=1;i<=n;i++) {po[i]=po[i-1]<<1; if(po[i]>=MOD) po[i]-=MOD;}

    int ans=0;
    for(int i=0;i<=n;i++)
    {
        ans+=gao(g[i]);
        if(ans>=MOD) ans-=MOD;
    }

    printf("%d\n",ans);
}

//---------------------end---------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 68480