#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(2e5) + 5;
const int mod = 1e9 + 7;
const int inv = 500000004;
int p2[N];
vi g[N];
deque < pair < pii , int > > D[N];
pair < pii , int > add(pair < pii , int > a,pair < pii , int > b)
{
    return mp(mp(1ll * a.fi.fi * b.fi.fi % mod,(1ll * a.fi.fi * b.fi.se + 1ll * b.fi.fi * a.fi.se) % mod),((1ll * (a.fi.se + a.se) * (b.fi.se + b.se) % mod) + 1ll * a.fi.fi * b.se + 1ll * b.fi.fi * a.se) % mod);
}
int Merge(int & a,int & b)
{
    if (D[a].size() < D[b].size())
        swap(a,b);
    int sz = D[b].size();
    for (int i = 0;i < sz;++i)
        D[a][i] = add(D[a][i],D[b][i]);
    D[b].clear();
    return sz;
}
int cnt[N];
int dfs(int node,int dep)
{
    ++cnt[dep];
    int sz = 0;
    int d = node;
    int SZ = 0;
    for (auto it : g[node])
    {
        int nxt = dfs(it,dep + 1);
        smax(SZ,Merge(d,nxt));
    }
    for (int i = 0;i < SZ;++i)
        D[d][i].fi.fi += D[d][i].se,D[d][i].se = 0;
    D[d].push_front(mp(mp(inv,inv),0));
    return d;
}
int main(void)
{
    srand(time(0));
    int n;
    cin>>n;
    for (int i = 1;i <= n;++i)
    {
        int p;
        cin>>p;
        g[p].pb(i);
    }
    auto d = D[dfs(0,0)];
    int ans = 0;
    while (!d.empty())
        (ans += d.front().fi.se) %= mod,d.pop_front();
    for (int i = 1;i <= n + 1;++i)
        ans = (ans + ans) % mod;
    cout << ans << '\n';
    return 0;
}
