#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#define P 1000000007
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}
ll perm(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (fac[n]*finv[n-k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}

vll t(300000, 1);
#define vvi std::vector<std::vector<int> >
const int MAX_V = 1000000;
vvi G = VV(MAX_V, 0, 0, int);
int root;
int parent[30][MAX_V];
vector<int> depth(MAX_V);

void dfs(int v, int p, int d){
  parent[0][v] = p, depth[v] = d;
  for(int i=0;i<G[v].size();i++) if(G[v][i] != p) dfs(G[v][i], v, d+1);
}
void init(int V){
  dfs(root, -1, 0);
  for(int k=0;k+1<30;k++){
    for(int v=0;v<V;v++){
      if(parent[k][v]<0) parent[k+1][v] = -1;
      else parent[k+1][v] = parent[k][parent[k][v]];
    }
  }
}
int lca(int u, int v){
  if(depth[u]>depth[v]) swap(u, v);
  for(int k=0;k<30;k++)if((depth[v]-depth[u])>>k & 1) v = parent[k][v];
  if(u==v) return u;
  for(int k=30-1;k>=0;k--){
    if(parent[k][u] != parent[k][v]){
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}

vvl dp = VV(200001, 2, 1, ll);

pair<ll, ll> calc(vll lis){
  ll all = 1;
  ll n = lis.size();
  vll L(n), R(n);
  for(auto num:lis) all = (all * (dp[num][0] + dp[num][1])%P)%P;
  for(int i=0;i<n;i++) L[i] = ((i==0?1:L[i-1]) * dp[lis[i]][0])%P;
  for(int i=0;i<n;i++) R[i] = ((i==0?1:R[i-1]) * dp[lis[n-1-i]][0])%P;

  ll sub = 0;
  //iだけ1
  for(int i=0;i<n;i++){
    ll tmp = ((i==0?1:L[i-1]) * (i==n-1?1:R[n-i-2]))%P;
    tmp = (tmp * dp[lis[i]][1])%P;
    sub = (sub + tmp)%P;
  }
  return pair<ll, ll>((all-sub+P)%P, sub);//0, 1
}

struct p{
  p* l;
  p* r;
  ll num;
};

p ed = p{NULL, NULL, -1};

int main(int argc, char const *argv[]) {
  init();
  for(int i=1;i<300000;i++) t[i] = (t[i-1]*2)%P;
  ll n;std::cin >> n;
  ll ans = 0;

  for(int i=1;i<=n;i++){
    ll a;scanf("%lld", &a);
    G[a].push_back(i);
  }
  root = 0;
  init(n+1);

  vvl dlist = VV(n+1, 0, 0, ll);
  for(int i=1;i<=n;i++) dlist[depth[i]].push_back(i);

  ll cnt = 0;
  vll trans(n+1, -1);
  vll rev(n+1, -1);
  queue<ll> q;
  q.push(0);

  while(!q.empty()){
    ll top = q.front();q.pop();
    trans[top] = cnt;
    rev[cnt] = top;
    cnt++;
    for(auto to:G[top]){
      if(depth[to]<depth[top]) continue;
      q.push(to);
    }
  }

  //深さdについて
  for(int d=1;d<=n;d++){
    ll tmp = t[n - dlist[d].size()];//独立しているもの
    ll cnt = 0;
    multimap<ll, p*> mp;//LCAtrans -> lef

    ll m = dlist[d].size();
    if(m==0) continue;
    if(m==1) cnt = 1;

    vector<p> k(m);
    for(int i=0;i<m;i++) dlist[d][i] = trans[dlist[d][i]];
    sort(all(dlist[d]));

    for(int i=0;i<m;i++){
      k[i] = p{&ed, &ed, dlist[d][i]};
      if(i!=0) k[i].l = &k[i-1];
      if(i!=m-1) k[i].r = &k[i+1];
      dp[dlist[d][i]][0] = dp[dlist[d][i]][1] = 1;
    }
    for(int i=0;i<m-1;i++){
      ll lc = lca(rev[dlist[d][i]], rev[dlist[d][i+1]]);
      mp.emplace(trans[lc], &k[i]);
    }

    while(!mp.empty()){
      //関係するものを削除
      vll mg;
      ll las = (*--mp.end()).first;
      set<ll> st;
      while(!mp.empty() && (*--mp.end()).first == las){
        p* e = (*--mp.end()).second;
        st.insert(e->r->num);
        st.insert(e->num);
        e->l->r = e->r;
        e->r->l = e->l;
        mp.erase(--mp.end());
      }

      ll max_num = (*--st.end());
      vll TMP;
      for(auto v:st) TMP.push_back(v);
      pair<ll, ll> get = calc(TMP);
      dp[max_num][0] = get.first;
      dp[max_num][1] = get.second;
      //std::cout << max_num << " " << dp[max_num][1] << " " <<  mp.size() << '\n';
      if(mp.empty()) cnt = dp[max_num][1];
    }

    ans = (ans + pp(tmp, cnt))%P;
  }
  std::cout << (ans*2 + t[n])%P << '\n';
  return 0;
}


Measured memory_bytes: 335068