#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 200001;

template<class T, int SZ> struct RMQ {
    T stor[SZ][32-__builtin_clz(SZ)];
    
    T comb(T a, T b) {
        return min(a,b);
    }
    
    void build(vector<T>& x) {
        F0R(i,sz(x)) stor[i][0] = x[i];
        FOR(j,1,32-__builtin_clz(SZ)) F0R(i,SZ-(1<<(j-1))) 
            stor[i][j] = comb(stor[i][j-1],
                        stor[i+(1<<(j-1))][j-1]);
    }
    
    T query(int l, int r) {
        int x = 31-__builtin_clz(r-l+1);
        return comb(stor[l][x],stor[r-(1<<x)+1][x]);
    }
};

template<int SZ> struct LCA {
    vi edges[SZ];
    RMQ<pi,2*SZ> r;
    vpi tmp;
    int depth[SZ], pos[SZ], en[SZ];
    
    int V, R;
    
    void addEdge(int u, int v) {
        edges[u].pb(v), edges[v].pb(u);
    }
    
    void dfs(int u, int prev){
        pos[u] = sz(tmp); depth[u] = depth[prev]+1;
        tmp.pb({depth[u],u});
        for (int v: edges[u]) if (v != prev) {
            dfs(v, u);
            tmp.pb({depth[u],u});
        }
        en[u] = sz(tmp)-1;
    }
    
    void construct() {
        dfs(R, 0);
        r.build(tmp);
    }
    
    int lca(int u, int v){
        u = pos[u], v = pos[v];
        if (u > v) swap(u,v);
        return r.query(u,v).s;
    }
    
    int dist(int u, int v) {
        return depth[u]+depth[v]-2*depth[lca(u,v)];
    }
};

ll ad(ll a, ll b) { return (a+b)%MOD; }
ll sub(ll a, ll b) { return (a-b+MOD)%MOD; }
ll mul(ll a, ll b) { return a*b%MOD; }

ll po (ll b, ll p) { return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD; }
    
LCA<1<<18> L;

int N, p[MX], depth[MX];
vi tmp[MX];
array<int,3> dp[MX];
ll ans = 0;

bool cmp(int a, int b) {
    return L.pos[a] < L.pos[b];
}

void process(int a, int b) {
    // cout << "TT " << a << " " << b << ""
    dp[b][0] = ad(dp[b][0],dp[b][2]);
    array<int,3> tmp = {0,0,0};
    F0R(i,3) F0R(j,2) tmp[min(i+j,2)] = ad(tmp[min(i+j,2)],mul(dp[a][i],dp[b][j]));
    dp[a] = tmp;
}

void solve(int x) {
    sort(all(tmp[x]),cmp);
    vi res = tmp[x]; res.pb(0);
    F0R(i,sz(tmp[x])-1) res.pb(L.lca(tmp[x][i],tmp[x][i+1]));
    sort(all(res)); res.erase(unique(all(res)),res.end());
    sort(all(res),cmp);
    for (int i: res) {
        dp[i] = {1,0,0};
        if (depth[i] == x) dp[i][1] = 1;
    }
    
    vi st; 
    for (int i: res) {
        while (sz(st) && L.en[st.back()] < L.pos[i]) {
            process(st[sz(st)-2],st.back()); 
            //cout << "OH " << st.back() << "\n";
            st.pop_back();
        }
        st.pb(i);
        //cout << "HI " << i << "\n";
    }
    
    while (sz(st)) {
        if (sz(st) == 1) {
            assert(st.back() == 0);
            ans = ad(ans,mul(po(2,N+1-sz(tmp[x])),dp[0][1]));
        } else {
            process(st[sz(st)-2],st.back());
        }
        //cout << "OH " << st.back() << "\n";
        st.pop_back();
    }
    // cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N; 
    FOR(i,1,N+1) {
        cin >> p[i];
        depth[i] = depth[p[i]]+1;
    }
    F0R(i,N+1) tmp[depth[i]].pb(i);
    L.V = N+1;
    FOR(i,1,N+1) L.addEdge(i,p[i]);
    L.construct();
    F0R(i,N+1) solve(i);
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 123116