#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

#define int long long

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
//typedef string S;

/*ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}*/

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const int N = 120010;
const long long MOD = 1e9 + 7;
const int INF = 1e9;
const long long rev2 = (MOD + 1) / 2;

int n;
int p[500000];
vector<int> ch[500000];

struct State{
    long long var0, var1, var2;
};

vector<State> dp[500000];
int link[500000];

void dfs(int v)
{
    //cout << v << endl;
    for (auto u : ch[v])
    {
        dfs(u);
    }
    vector<pii> szs;
    for (int i = 0; i < ch[v].size(); i++)
    {
        szs.push_back({dp[link[ch[v][i]]].size(), ch[v][i]});
    }
    sort(all(szs));
    for (int i = 0; i + 1 < ch[v].size(); i++)
    {
        int u = szs[i].second;
        int w = szs[i + 1].second;
        u = link[u], w = link[w];
        for (int j = 0; j < dp[u].size(); j++)
        {
            int a = dp[w].size() - 1 - j;
            int b = dp[u].size() - 1 - j;
            State other;
            other.var0 = (dp[w][a].var0 * dp[u][b].var0) % MOD;
            other.var1 = (dp[w][a].var0 * dp[u][b].var1 + dp[w][a].var1 * dp[u][b].var0) % MOD;
            other.var2 = (dp[w][a].var1 * dp[u][b].var1 + dp[w][a].var1 * dp[u][b].var2 + dp[w][a].var0 * dp[u][b].var2) % MOD;
            dp[w][a] = other;
        }
        dp[u].shrink_to_fit();
    }
    if (ch[v].size() > 0)
    {
        link[v] = link[szs.back().second];
        //dp[v] = dp[szs.back().second];
        //dp[szs.back().second].shrink_to_fit();
        if (ch[v].size() > 1)
        {
            v = link[v];
            for (int i = 0; i < dp[v].size(); i++)
            {
                dp[v][i].var0 = (dp[v][i].var0 + dp[v][i].var2) % MOD;
                dp[v][i].var2 = 0;
            }
            dp[v].push_back({rev2, rev2, 0});
        }
        else
        {
            v = link[v];
            dp[v].push_back({rev2, rev2, 0});
        }
    }
    else
    {
        link[v] = v;
        dp[v] = {{rev2, rev2, 0}};
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i];
        ch[p[i]].push_back(i);
    }
    dfs(0);
    //for (int i = 0; i <= n; i++) cout << i << " " << link[i] << endl;
    long long ans = 0;
    for (int i = 0; i < dp[link[0]].size(); i++)
    {
        //cout << dp[0][i].var1 << endl;
        ans = (ans + dp[link[0]][i].var1) % MOD;
    }
    for (int i = 0; i <= n; i++)
    {
        ans = ans * 2 % MOD;
    }
    cout << ans;
}


Measured memory_bytes: 74992