#include <bits/stdc++.h>
using namespace std;

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int i##_to_ = (t), i = (f); i <= i##_to_; i++)
#define uptil(f, t, i)   for(int i##_to_ = (t), i = (f); i <  i##_to_; i++)
#define downto(f, t, i)  for(int i##_to_ = (t), i = (f); i >= i##_to_; i--)
#define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i >  i##_to_; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 2
#define _LIBCPP_DEBUG2 2
#define ln << endl
#define dbg(x) cerr << #x << " = " << (x) ln
#define db(x) cerr << #x << " = " << (x) sp
#else
#define debug false
#define ln << '\n'
#define db(x) cerr
#define dbg(x) cerr
#endif
#define tb << '\t'
#define sp << ' '

constexpr long MOD = 1000000007;

long inv(long x) {
    signed long n = MOD - 2;
    long ans = 1;
    while(n) {
        if(n & 1) ans = ans * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ans;
}

constexpr int Z = 20;
vector<long> P, sizes, depth, bNmod;
vector<vector<int>> ch;
vector<vector<int>> direct_ch(Z);

pair<int, int> getSizes(int i, long lv) {
    int s = 1, d = 0;
    for(int j : ch[i]) {
        int t, e;
        tie(t, e) = getSizes(j, lv+1);
        s += t;
        d = max(d, e + 1);
    }
    return {sizes[i] = s, depth[i] = d};
}

pair<long, long> pyon(int i, int lv) {
    if(lv == 0) return {1, 1};
    if(lv > depth[i]) { db(lv); dbg(depth[i]); return {0, 0}; }
    if(direct_ch[0][i]) {
        int k = 0;
        while(direct_ch[k+1][i] && lv >= (1 << k+1)) ++k;
        return pyon(direct_ch[k][i], lv - (1 << k));
    }
    vector<long> zoi(ch[i].size());
    vector<long> poi(ch[i].size());
    long a = 1, b = 0, s = 0;
    times(ch[i].size(), k) {
        long t;
        tie(zoi[k], t) = pyon(ch[i][k], lv-1);
        s += t;
        poi[k] = (bNmod[t] - zoi[k] + MOD) % MOD;
        (a *= poi[k]) %= MOD;
        db(i); db(k); db(zoi[k]); dbg(poi[k]);
    }
    db(i); dbg(a);
    times(ch[i].size(), k) {
        b += a * zoi[k] % MOD * inv(poi[k]) % MOD;
        db(i); db(k); db(inv(poi[k])); dbg(a * zoi[k] % MOD * inv(poi[k]) % MOD);
        b %= MOD;
    }
    db(i); db(lv); db(b); dbg(s);
    return {b, s};
}

signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N; scanf("%d", &N);
    P.resize(N+1);
    ch.resize(N+1);
    sizes.resize(N+1);
    bNmod.resize(N+1);
    depth.resize(N+1);
    //LV.resize(N+1);

    upto(1, N, i) {
        scanf("%lld", &P[i]);
        ch[P[i]].push_back(i);
    }

    int deepest = getSizes(0, 0).second;

    bNmod[0] = 1;
    upto(1, N, i) bNmod[i] = bNmod[i-1] * 2 % MOD;

    direct_ch[0].resize(N+1);
    upto(0, N, i) if(ch[i].size() == 1) direct_ch[0][i] = ch[i][0];

    times(Z-1, k) {
        direct_ch[k+1].resize(N+1);
        upto(0, N, i) {
            int g = direct_ch[k][i], h = direct_ch[k][g];
            if(g && h) direct_ch[k+1][i] = h;
        }
    }
    if(debug) times(Z-1, k) {
        times(N+1, i) cout << (i?" ":"") << direct_ch[k][i]; cout ln;
    }


    long ans = 0;
    upto(0, deepest, lv) {
        long a, t; tie(a, t) = pyon(0, lv);
        (ans += a * bNmod[N + 1 - t] % MOD) %= MOD;
        //dbg(ans);
    }

    cout << ans ln;

    return 0;
}


Measured memory_bytes: 45568