#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;

int add(int x, int y) {
    x += y;
    if(x >= mod) x -= mod;
    return x;
}

int mul(int x, int y) {
    LL z = 1LL * x * y;
    return z - z / mod * mod;
}

int p[maxn];
vector<int> g[maxn], g2[maxn];
vector<int> fu[maxn];
int depth = 0, bn = 0, b[maxn << 1];
int f[maxn << 1], dfn[maxn], dis[maxn], fs[maxn];
LL ans[maxn];

void dfs(int u, int fa) {
    int tmp = ++depth;
    b[++bn] = tmp;
    f[tmp] = u;
    dfn[u] = bn;
    for (auto v : g[u]) {
        if (v == fa) continue;
        dis[v] = dis[u] + 1;
        dfs(v, u);
        b[++bn] = tmp;
    }
}

int st[maxn << 1][20];
int lg[maxn << 1];
void st_init() {
    for (int i = 2; i < maxn * 2; ++i) lg[i] = lg[i >> 1] + 1;
    for (int i = bn; i >= 1; --i) {
        st[i][0] = b[i];
        for (int j = 1; i + (1 << j) - 1 <= bn; ++j)
            st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
    }
}
int rmq(int l, int r) {
    int k = lg[r - l + 1];
    return min(st[l][k], st[r - (1 << k) + 1][k]);
}

int lca(int a, int b) {
    if(a == b) return a;
    if (dfn[a] > dfn[b]) swap(a, b);
    int k = rmq(dfn[a], dfn[b]);
    return f[k];
}

bool cmp(const int &i, const int &j) {
    return dfn[i] < dfn[j];
}

void build_tree(vector<int> &vec) {
    int sz = 0, k = vec.size();
    sort(vec.begin(), vec.end(), cmp);
    fs[sz] = 0;
    g2[0].clear();
    for (int i = 0; i < k; ++i) {
        int u = vec[i], ll = lca(u, fs[sz]);
        g2[u].clear();
        if (ll == fs[sz]) fs[++sz] = u;
        else {
            while (sz >= 1 && dis[fs[sz - 1]] >= dis[ll]) {
                g2[fs[sz - 1]].push_back(fs[sz]);
                sz--;
            }
            if (fs[sz] != ll) {
                g2[ll].clear();
                g2[ll].push_back(fs[sz--]);
                fs[++sz] = ll;
            }
            fs[++sz] = u;
        }
    }
    for (int i = 0; i < sz; ++i) g2[fs[i]].push_back(fs[i + 1]);
}

int dp[maxn][2];

void dfs2(int u) {
    int a,b,c;
    a = 1;
    b = c = 0;
    for(auto v:g2[u]) {
        dfs2(v);
        c = add(mul(c,add(dp[v][1],dp[v][0])),mul(b,dp[v][1]));
        b = add(mul(b,dp[v][0]),mul(a,dp[v][1]));
        a = mul(a,dp[v][0]);
    }
    if(g2[u].size() == 0) dp[u][0] = dp[u][1] = 1;
    else {
        dp[u][0] = add(a,c);
        dp[u][1] = b;
    }
   // cout<<a<<" "<<b<<" "<<c<<endl;
   // cout<<"--"<<u<<" "<<dp[u][0]<<" "<<dp[u][1]<<endl;
}

int main() {
#ifdef CX_TEST
    freopen("E:\\program--GG\\test_in.txt", "r", stdin);
#endif
    int n, i, x, ans = 0;
    scanf("%d", &n);
    for(i = p[0] = 1; i < maxn; i++) p[i] = mul(p[i - 1], 2);
    for(i = 1; i <= n; i++) {
        scanf("%d", &x);
        g[x + 1].push_back(i + 1);
    }
    dis[1] = 1;
    dfs(1,0);
    st_init();
    for(i = 1;i <= n + 1; i++) fu[dis[i]].push_back(i);
    for(i = 1;i <= n + 1; i++) {
        if(fu[i].size()) {
            //cout<<i<<" = "<<fu[i].size()<<endl;
            build_tree(fu[i]);
            dfs2(0);
        //cout<<dp[0][1]<<endl;
            ans = add(ans,mul(dp[0][1],p[n + 1 - fu[i].size()]));
        }
    }
    printf("%d\n", ans);
    return 0;;
}


Measured memory_bytes: 81536