#include <bits/stdc++.h>
using namespace std;
#define rep(i, from, to) for (int i = from; i < (to); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int, int>> vii;

ll mod_inv(ll a, ll b) {
    return 1<a ? b - mod_inv(b%a,a)*b/a : 1;
}

const ll mmod = 1e9 + 7;
vector<vi> children;

vi dfssort;

void dof(int x) {
    for (auto c : children[x]) {
        dof(c);
    }
    dfssort.push_back(x);
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin >> n;

    children.resize(n+1);


    rep(i,0,n) {
        int p;
        cin >> p;
        children[p].push_back(i+1);
    }


    vi depth(n+1);
    vector<vector<pair<ll,ll>>> st;
    vi indx(n+1);

    vector<ll> twos(n+2);
    twos[0] = 1;
    rep(i,0,n+1) {
        twos[i+1] = 2ll * twos[i];
        twos[i+1] = twos[i+1] % mmod;
    }

    int curindex = 0;

    dof(0);


    for (auto node : dfssort) {
        if (children[node].size() == 0) {
            vector<pair<ll,ll>> tm;
            tm.push_back(make_pair(1,1));
            depth[node] = 1;
            st.push_back(tm);
            indx[node] = curindex;
            curindex++;
            continue;
        }
        vii sortedchildren;
        for (auto c : children[node]) {
            sortedchildren.push_back(make_pair(depth[c], c));
        }
        sort(sortedchildren.rbegin(), sortedchildren.rend());
        int top = sortedchildren[0].second;
        indx[node] = indx[top];
        depth[node] = depth[top] + 1;
        if (sortedchildren.size() > 1) {
            int curdepth = depth[sortedchildren[1].second];
            vi candidates;
            candidates.push_back(top);
            candidates.push_back(sortedchildren[1].second);
            int sortedindex = 2;
            while (curdepth > 0) {
                while (sortedindex < sortedchildren.size() && depth[sortedchildren[sortedindex].second] >= curdepth) {
                    candidates.push_back(sortedchildren[sortedindex].second);
                    sortedindex++;
                }
                ll prod = 1;
                for (auto c : candidates) {
                    int canindx = depth[c] - curdepth;
                    ll zeros = twos[st[indx[c]][canindx].first] - st[indx[c]][canindx].second + mmod;
                    zeros = zeros % mmod;
                    prod = prod * zeros;
                    prod = prod % mmod;
                }
                ll newe = 0;
                ll newn = 0;
                for (auto c : candidates) {
                    int canindx = depth[c] - curdepth;
                    ll zeros = twos[st[indx[c]][canindx].first] - st[indx[c]][canindx].second + mmod;
                    zeros = zeros % mmod;
                    ll wew = st[indx[c]][canindx].second * prod;
                    wew = wew % mmod;
                    wew = wew * mod_inv(zeros, mmod);
                    wew = wew % mmod;
                    newe = wew + newe;
                    newe = newe % mmod;
                    newn = newn + st[indx[c]][canindx].first;
                }
                st[indx[node]][depth[node]-1-curdepth] = make_pair(newn, newe);
                curdepth--;
            }
        }
        st[indx[node]].push_back(make_pair(1,1));
    }

                    
    ll sum = 0;

    rep(dep,0,depth[0]) {
        ll newe = st[indx[0]][dep].second * twos[n+1-st[indx[0]][dep].first];
        newe = newe % mmod;
        sum = sum + newe;
        sum = sum % mmod;
    }

    cout << sum << endl;








    return 0;
}

Measured memory_bytes: 30324