#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

struct state{
    map<int,mint> mp[3];
    state(){}
    void init(int d){
        mp[0][d] = 1;
        mp[1][d] = 1;
    }
    int size(){
        return mp[0].size();
    }
    void clear(){
        for(int k=0;k<3;k++) mp[k].clear();
    }
};

auto mymerge = [&](state& large,state& small,bool flag){
    for(auto x:small.mp[0]){
        int d = x.first;
        if(!large.mp[0].count(d)){
            large.mp[0][d] = large.mp[1][d] = 1;
            continue;
        }
        array<mint,3> l = {large.mp[0][d],large.mp[1][d],large.mp[2][d]};
        array<mint,3> s = {small.mp[0][d],small.mp[1][d],small.mp[2][d]};
        mint a = l[0]*(s[0]+s[2]);
        mint b = l[0]*s[1]+l[1]*(s[0]+s[2]);
        mint c = l[1]*s[1];
        if(flag){
            a += l[2]*s[0]+l[2]*s[2];
            b += l[2]*s[1];
        }else{
            c += l[2]*(s[0]+s[1]+s[2]);
        }
        large.mp[0][d] = a;
        large.mp[1][d] = b;
        large.mp[2][d] = c;
    }
    small.clear();
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vvec<int> g(N+1);
    for(int i=1;i<=N;i++){
        int p;
        cin >> p;
        g[p].push_back(i);
    }
    vec<int> cnt(N+1,0);
    vec<state> S(N+1);

    auto dfs = [&](auto&& self,int cur,int d)->void{
        cnt[d]++;
        S[cur].init(d);
        if(g[cur].empty()) return ;
        for(auto& to:g[cur]){
            self(self,to,d+1);
        }
        sort(g[cur].begin(),g[cur].end(),[&](int a,int b){
            return S[a].size()>S[b].size();
        });
        int lid = g[cur][0];
        mymerge(S[lid],S[cur],false);
        swap(S[lid],S[cur]);
        bool f = true;
        for(auto& to:g[cur]) if(to!=lid){
            mymerge(S[cur],S[to],f);
            f = false;
        }
    };
    dfs(dfs,0,0);
    vec<mint> pow2(N+2,1);
    for(int i=1;i<=N+1;i++) pow2[i] = pow2[i-1]*2;
    mint ans = 0;
    for(auto& d:S[0].mp[1]){
//        cerr << d.first << " " << d.second << "\n";
        ans += d.second*pow2[N+1-cnt[d.first]];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 135424