#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1000000007
template <unsigned int mod>
class ModInt {
private:
    unsigned int v;
    static unsigned int norm(const unsigned int& x){ return x < mod ? x : x - mod; }
    static ModInt make(const unsigned int& x){ ModInt m; return m.v = x, m; }
    static ModInt inv(const ModInt& x){ return make(inverse(x.v, mod)); }
    static unsigned int inverse(int a, int m){
        int u[] = {a, 1, 0}, v[] = {m, 0, 1}, t;
        while(*v){
            t = *u / *v;
            swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]), swap(u[2] -= t * v[2], v[2]);
        }
        return (u[1] % m + m) % m;
    }

public:
    ModInt() : v{0}{}
    ModInt(const long long val) : v{norm(val % mod + mod)} {}
    ModInt(const ModInt<mod>& n) : v{n()} {}
    explicit operator bool() const noexcept { return v != 0; }
    bool operator!() const noexcept { return !static_cast<bool>(*this); }
    ModInt& operator=(const ModInt& n){ return v = n(), (*this); }
    ModInt& operator=(const long long val){ return v = norm(val % mod + mod), (*this); }
    ModInt operator+() const { return *this; }
    ModInt operator-() const { return v == 0 ? make(0) : make(mod - v); }
    ModInt operator+(const ModInt& val) const { return make(norm(v + val())); }
    ModInt operator-(const ModInt& val) const { return make(norm(v + mod - val())); }
    ModInt operator*(const ModInt& val) const { return make((long long)v * val() % mod); }
    ModInt operator/(const ModInt& val) const { return *this * inv(val); }
    ModInt& operator+=(const ModInt& val){ return *this = *this + val; }
    ModInt& operator-=(const ModInt& val){ return *this = *this - val; }
    ModInt& operator*=(const ModInt& val){ return *this = *this * val; }
    ModInt& operator/=(const ModInt& val){ return *this = *this / val; }
    ModInt operator+(const long long val) const { return ModInt{v + val}; }
    ModInt operator-(const long long val) const { return ModInt{v - val}; }
    ModInt operator*(const long long val) const { return ModInt{(long long)v * (val % mod)}; }
    ModInt operator/(const long long val) const { return ModInt{(long long)v * inv(val)}; }
    ModInt& operator+=(const long long val){ return *this = *this + val; }
    ModInt& operator-=(const long long val){ return *this = *this - val; }
    ModInt& operator*=(const long long val){ return *this = *this * val; }
    ModInt& operator/=(const long long val){ return *this = *this / val; }
    bool operator==(const ModInt& val) const { return v == val.v; }
    bool operator!=(const ModInt& val) const { return !(*this == val); }
    bool operator==(const long long val) const { return v == norm(val % mod + mod); }
    bool operator!=(const long long val) const { return !(*this == val); }
    unsigned int operator()() const { return v; }
    friend ModInt operator+(const long long val, const ModInt& n) { return n + val; }
    friend ModInt operator-(const long long val, const ModInt& n) { return ModInt{val - n()}; }
    friend ModInt operator*(const long long val, const ModInt& n) { return n * val; }
    friend ModInt operator/(const long long val, const ModInt& n) { return ModInt{val} / n; }
    friend bool operator==(const long long val, const ModInt& n) { return n == val; }
    friend bool operator!=(const long long val, const ModInt& n) { return !(val == n); }
    friend istream& operator>>(istream& is, ModInt& n){
        unsigned int v;
        return is >> v, n = v, is;
    }
    friend ostream& operator<<(ostream& os, const ModInt& n){ return (os << n()); }
    friend ModInt mod_pow(ModInt x, long long n){
        ModInt ans = 1;
        while(n){
            if(n & 1) ans *= x;
            x *= x, n >>= 1;
        }
        return ans;
    }
};

using mod = ModInt<MOD>;



vector<int> p;
vector<int> dep;
vector<vector<int> > a; 
vector<int> c;
int dfs(int id){
    if(id==0){
        return 0;
    }
    if(dep[id]!=0){
        return dep[id];
    }
    int k = dfs(p[id]);
    a[k+1].push_back(id);
    return dep[id] = k+1;
}
mod half;
mod res;
ll n;
void calc(int k){
    auto& v = a[k];
    if(k==0){
        res += half;
        return ;
    }
    priority_queue<pair<int,pair<int,int> > >pq;
    map<int,int> mp;
    mp[0] = 100;
    for(auto x:v){
        pq.push(MP(dep[p[x]],MP(p[x],x)));
        mp[p[x]]++;
    }
    set<int> st;
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        if(st.count(x.second.first))continue;
        st.insert(x.second.first);
        if(mp[x.second.first]==1){
            p[x.second.second] = p[x.second.first];
            mp[p[x.second.second]]++;
            pq.push(MP(dep[p[x.second.second]],MP(p[x.second.second],x.second.second)));
        }else{
            pq.push(MP(dep[p[x.second.first]],MP(p[x.second.first],x.second.first)));
            mp[p[x.second.first]]++;
        }
    }
    map<int,mod> P;
    map<int,vector<mod> > Q;
    priority_queue<pair<int,int> > q;
    for(auto x:v){
        q.push(MP(dep[x],x));
        P[x] = half;
    }
    while(!q.empty()){
        auto x = q.top();
        q.pop();
        int id = x.second;
        int pid = p[id];
        if(Q.find(id)!=Q.end()){
            if(P.find(id)!=P.end())continue;
            mod s = 1;
            auto& vv = Q[id]; 
            for(auto& y:vv){
                //cerr << y << " ";
                s *= (mod)1- y;
            }
            //cerr << endl;
            mod sm = 0;
            for(auto& y:vv){
                sm += (s/((mod)(1)-y))*y;
            }
            P[id] = sm;
            // cerr << k << endl;
            // cerr << id << " " << P[id] << endl;
        }
        Q[pid].push_back(P[id]);
        if(pid == 0)continue;
        q.push(MP(dep[pid],pid));
    }
    mod s = 1;
    auto& vv = Q[0]; 
    for(auto& y:vv){
        s *= (mod)1- y;
    }
    mod sm = 0;
    for(auto& y:vv){
        sm += (s/((mod)(1)-y))*y;
    }
    res += sm;
    return ;
}


int main(){
    cin >> n;
    p.resize(n+1);
    dep.resize(n+1);
    a.resize(n+1);
    half = (mod)(1)/(mod)(2);
    rep(i,n){
        cin >> p[i+1];
    }
    a[0].push_back(0);
    rep(i,n+1){
        dfs(i);
    }
    rep(i,n+1){
        if(a[i].size()!=0){
            calc(i);
        }
    }
    
    res *= mod_pow((mod)2,n+1);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 24552