#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template<int mod=1000000007>
class ModInt {
  int x;
public:
  ModInt() : x(0){}
  ModInt(int64_t y){ x = y % mod; if(x < 0) x += mod; }
  ModInt &operator += (const ModInt &p){ x += p.x; if(x >= mod) x -= mod; return *this; }
  ModInt &operator -= (const ModInt &p){ x -= p.x; if(x < 0) x += mod; return *this; }
  ModInt &operator *= (const ModInt &p){ x = (int) (1LL * x * p.x % mod); return *this; }
  ModInt &operator /= (const ModInt &p){ *this *= p.inverse(); return *this; }
  ModInt &operator += (const int64_t y){ x = (x + y)%mod; if(x < 0) x += mod; return *this; }
  ModInt &operator -= (const int64_t y){ x = (x - y)%mod; if(x < 0) x += mod; return *this; }
  ModInt &operator *= (const int64_t y){ x = (int) (x * y % mod); return *this; }
  ModInt &operator /= (const int64_t y){ *this *= ModInt(y).inverse(); return *this; }
  ModInt operator -() const { return ModInt(-x); }
  ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator == (const ModInt &p) const { return x == p.x; }
  bool operator != (const ModInt &p) const { return x != p.x; }
  ModInt operator + (const int64_t y) const { return ModInt(*this) += y; }
  ModInt operator - (const int64_t y) const { return ModInt(*this) -= y; }
  ModInt operator * (const int64_t y) const { return ModInt(*this) *= y; }
  ModInt operator / (const int64_t y) const { return ModInt(*this) /= y; }
  bool operator == (const int64_t y) const { return x == (mod + y%mod)%mod; }
  bool operator != (const int64_t y) const { return x != (mod + y%mod)%mod; }
  ModInt operator = (const int64_t y) { return *this = ModInt(y); }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0){
      t = a/b; a -= t*b; swap(a, b);
      u -= t*v; swap(u, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t y) const {
    if(x==0) return ModInt(0);
    int64_t r = 1, t = x;
    while(y > 0){
      if(y&1) r = r*t%mod;
      t = t*t%mod; y >>= 1;
    }
    return ModInt(r);
  }
  friend ostream &operator << (ostream &os, const ModInt<mod> &p) { return os<<p.x; }
  friend istream &operator >> (istream &is, ModInt<mod> &a) { int64_t x; is>>x; a = ModInt<mod>(x); return is; }
};
using Int = ModInt<>;

vector<int> tree[200005];
int dep_nodes[200005];

int dd(int v, int dep){
  dep_nodes[dep]++;
  int ret = dep;
  for(auto to : tree[v]) ret = max(ret, dd(to, dep+1));
  return ret;
}

deque<vector<Int>> memo[200005];

int calc(int v){
  vector<int> idxs;
  for(auto to : tree[v]){
    int r = calc(to);
    idxs.pb(r);
  }

  int m = idxs.size();

  if(m==0){
    memo[v] = {{1,1,0}};
    return v;
  }

  sort(all(idxs), [](const int &l, const int &r){
    return memo[l].size() < memo[r].size();
  });

  int p = idxs.back();
  if(m>=2){
    rep(j, memo[idxs[m-2]].size()){
      memo[p][j][0] += memo[p][j][2];
      memo[p][j][2] = 0;
    }
  }

  rep(i,m-1){
    int q = idxs[i];
    rep(j,memo[q].size()){
      memo[q][j][0] += memo[q][j][2];

      vector<Int> nxt = {0,0,0};
      rep(ii,2) rep(jj,3){
        nxt[min(ii+jj,2)] += memo[q][j][ii] * memo[p][j][jj];
      }
      memo[p][j] = nxt;
    }
  }

  memo[p].push_front({1,1,0});
  return p;
}

int main(){
  int n;
  cin>>n;
  rep(i,n){
    int d;
    cin>>d;
    tree[d].pb(i+1);
  }

  fill(dep_nodes, dep_nodes+n, 0);
  int dep_max = dd(0, 0);

  int r = calc(0);

  Int ans = 0;
  rep(i,dep_max+1){
    ans += memo[r][i][1] * Int(2).pow(n+1 - dep_nodes[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 244724