#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

unordered_map<ll, ll> minvmap;
ll minv(ll a, ll m) {
  auto k = a; auto p = minvmap[a]; if (p != 0) return p;
  ll b = m, u = 1, v = 0;
  while (b) { ll t = a/b; swap(a -= t*b, b); swap(u -= t*v, v); }
  p = (u%m+m)%m; minvmap[k] = p; return p;
}
struct mint {
    ll x;
    mint():x(0){}
    mint(ll x):x((x%mod+mod)%mod){}
    mint& fix() { x = (x%mod+mod)%mod; return *this;}
    mint operator-() const { return mint(0) - *this;}
    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){ (x*=minv(a.x, mod))%=mod; return *this; }
    mint operator+(const mint& a)const{ return mint(*this) += a;}
    mint operator-(const mint& a)const{ return mint(*this) -= a;}
    mint operator*(const mint& a)const{ return mint(*this) *= a;}
    mint operator/(const mint& a)const{ return mint(*this) /= a;}
    bool operator<(const mint& a)const{ return x < a.x;}
    bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

mint mod_pow(mint a, ll x) {
  mint res = 1;
  while(x > 0) {
    if (x & 1) res *= a;
    a *= a; x >>= 1;
  }
  return res;
}

using T = tuple<mint, mint, mint>;
const mint half = mint(1)/2;

deque<T> que[200005];
vector<int> graph[200005];

void merge(deque<T>& a, const deque<T>& b) {
  const auto n = b.size();
  debug(n);
  for(int i=0; i<n; i++) {
    auto& a0 = get<0>(a[i]);
    auto& a1 = get<1>(a[i]);
    auto& a2 = get<2>(a[i]);
    auto b0 = get<0>(b[i]);
    auto b1 = get<1>(b[i]);
    auto b2 = get<2>(b[i]);
    auto c0 = a0*b0;
    auto c1 = a0*b1+a1*b0;
    auto c2 = a0*b2+a1*(b1+b2)+a2*(b0+b1+b2);
    a0 = c0; a1 = c1; a2 = c2;
    //a[i] = make_tuple(c0, c1, c2);
  }
}

int merge_children(const vector<int>& children) {
  const auto n = children.size();
  vector<P> vec(n);
  rep(i, n) {
    vec[i].first = que[children[i]].size();
    vec[i].second = children[i];
  }
  sort(vec.begin(), vec.end());
  for(int i=1; i<n; i++) {
    merge(que[vec[i].second], que[vec[i-1].second]);
  }

  if (n>=2) {
    int k = vec[n-2].first;
    auto& q = que[vec[n-1].second];
    rep(i, k) {
      get<0>(q[i]) = get<0>(q[i])+get<2>(q[i]);
      get<2>(q[i]) = 0;
    }
  }

  return vec[n-1].second;
}

int dfs(int p) {
  vector<int> pos;
  for(auto v: graph[p]) {
    pos.push_back(dfs(v));
  }
  int c = p;
  if (!pos.empty()) {
    debug(p);
    c = merge_children(pos);
  }
  que[c].emplace_front(half, half, 0);
  return c;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  for(int i=1; i<=n; i++) {
    int p; cin >> p;
    graph[p].push_back(i);
  }

  int p = dfs(0);
  mint ans = 0;
  for(auto e: que[p]) {
    ans += get<1>(e);
  }
  const mint base = mod_pow(2, n+1);
  cout << ans*base << endl;
}

Measured memory_bytes: 240884