#include <bits/stdc++.h>
using namespace std;

int main() {
    int n; scanf("%d", &n);
    vector<vector<int>> g(n + 1);
    vector<vector<int>> fa(n + 1);
    for (int i = 1; i <= n; ++i) {
        int p; scanf("%d", &p);
        g[p].push_back(i);
        fa[i].push_back(p);
    }

    constexpr int kMod = 1'000'000'000 + 7;
    vector<vector<int>> nd(n + 1);
    vector<int> dep(n + 1), tin(n + 1), tout(n + 1), pw(n + 2, 1);

    for (int i = 1; i <= n + 1; ++i) pw[i] = (pw[i - 1] + pw[i - 1]) % kMod;

    auto GetLCA = [&](int u, int v) {
        if (dep[u] > dep[v]) swap(u, v);
        for (int i = 0; i < fa[v].size(); ++i) {
            if ((dep[v] - dep[u]) >> i & 1) v = fa[v][i];
        }
        if (u == v) return u;
        for (int i = 20; i >= 0; --i) {
            if (i < fa[u].size() && i < fa[v].size() && fa[u][i] != fa[v][i]) {
                u = fa[u][i];
                v = fa[v][i];
            }
        }
        return fa[u][0];
    };

    function<void(int)> DfsDepth = [&](int x) {
        nd[dep[x]].push_back(x);
        for (int i = 1; (1 << i) <= dep[x]; ++i) {
            fa[x].push_back(fa[fa[x][i - 1]][i - 1]);
        }
        static int tk = 0;
        tin[x] = tk++;
        for (int u : g[x]) {
            dep[u] = dep[x] + 1;
            DfsDepth(u);
        }
        tout[x] = tk;
    };

    DfsDepth(0);
    vector<vector<int>> cg(n + 1);
    vector<vector<int>> dp(n + 1, vector<int>(2));

    auto Solve = [&](vector<int> v) {
        if (v.empty()) return 0;
        vector<int> dv;
        for (int u : v) dv.push_back(tin[u]);
        sort(dv.begin(), dv.end());
        vector<int> que(v.begin(), v.end());
        set<int> used(v.begin(), v.end());
        set<int> root(v.begin(), v.end());

        auto Count = [&](int x) {
            return lower_bound(dv.begin(), dv.end(), tout[x]) - lower_bound(dv.begin(), dv.end(), tin[x]);
        };

        for (int it = 0; it < que.size(); ++it) {
            int x = que[it], y = x;
            int cnt = Count(x);
            for (int i = 20; i >= 0; --i) {
                if (i >= fa[x].size()) continue;
                if (Count(fa[x][i]) == cnt) x = fa[x][i];
            }
            if (x != 0) {
                x = fa[x][0];
                cg[x].push_back(y);
                root.erase(y);
                if (!used.count(x)) {
                    used.insert(x);
                    root.insert(x);
                    que.push_back(x);
                }
            }
        }
        assert(root.size() == 1);
        int r = *root.begin();

        function<void(int)> Dfs = [&](int x) {
            if (cg[x].empty()) {
                dp[x][0] = 1;
                dp[x][1] = 1;
                return;
            }
            vector<int> cur(3);
            cur[0] = 1;
            for (int u : cg[x]) {
                Dfs(u);
                vector<int> nxt(3);
                for (int i = 0; i < 2; ++i) {
                    for (int j = 0; j < 3; ++j) {
                        nxt[min(i + j, 2)] += 1LL * dp[u][i] * cur[j] % kMod;
                        if (nxt[min(i + j, 2)] >= kMod) nxt[min(i + j, 2)] -= kMod;
                    }
                }
                cur = nxt;
            }
            dp[x][0] = (cur[0] + cur[2]) % kMod;
            dp[x][1] = cur[1];
        };

        Dfs(r);
        for (int u : que) cg[u].clear();
        return dp[r][1];
    };

    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        int res = 1LL * Solve(nd[i]) * pw[n + 1 - nd[i].size()] % kMod;
        ans += res;
        if (ans >= kMod) ans -= kMod;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 82048