#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

int modpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

struct edge{int to, cost;};

int mod = 1000000007;

class Graph
{
public:
    int V;
    vector<vector<edge>> G;
    vector<mat> dp;
    vec g;

    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
        dp.resize(V);
        g = vec(V, 0);
    }

    void add_edge(int from, int to, int cost = 0){
        G[from].push_back(edge({to, cost}));
    }

    void add_edge2(int v1, int v2, int cost = 0){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

    int dfs(int v = 0, int p = -1, int d = 0){
        g[d]++;
        int v0 = -1, m = -1;
        REP(k, G[v].size()) if(G[v][k].to != p){
            int n = dfs(G[v][k].to, v, d + 1);
            if(n > m){
                m = n;
                v0 = G[v][k].to;
            }
        }
        if(v0 != -1){
            dp[v].swap(dp[v0]);
            vec tmp(3);
            int mm = -1;
            REP(k, G[v].size()) if(G[v][k].to != p && G[v][k].to != v0){
                int w = G[v][k].to, n = dp[w].size();
                REP(i, n){
                    fill(tmp.begin(), tmp.end(), 0);
                    REP(j1, 3) REP(j2, 3){
                        tmp[min(2LL, j1 + j2)] += dp[v][m - 1 - i][j1] * dp[w][n - 1 - i][j2];
                        tmp[min(2LL, j1 + j2)] %= mod;
                    }
                    REP(j, 3) dp[v][m - 1 - i][j] = tmp[j];
                }
                Max(mm, n);
            }
            REP(i, mm){
                dp[v][m - 1 - i][0] = (dp[v][m - 1 - i][0] + dp[v][m - 1 - i][2]) % mod;
                dp[v][m - 1 - i][2] = 0;
            }
        }
        dp[v].push_back(vec({1, 1, 0}));
        return dp[v].size();
    }

    int calc_ans(){
        dfs();
        int ans = 0, n = dp[0].size();
        REP(i, n){
            ans += dp[0][n - 1 - i][1] * modpow(2, V - g[i], mod);
            ans %= mod;
        }
        return ans;
    }

};

signed main(){

    int N; cin >> N;
    Graph G(N + 1);
    int p;
    REP(i, N){
        cin >> p;
        G.add_edge2(i + 1, p);
    }
    cout << G.calc_ans() << endl;

    return 0;
}


Measured memory_bytes: 69804