#include <bits/stdc++.h>
#define MOD 1000000007
template<int mod>
struct ModInt{
    int x;
    ModInt():x(0){}
    ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
    ModInt &operator+=(const ModInt &p){
        if((x+=p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if((x+=mod-p.x)>=mod)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{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;}
    explicit operator int() const { return x; }                           // added by QCFium
    ModInt operator=(const int p) {x = p; return ModInt(*this);} // added by QCFium
    ModInt inverse()const{
        int a=x,b=mod,u=1,v=0,t;
        while(b>0){
            t=a/b;
            a-=t*b;
            std::swap(a,b);
            u-=t*v;
            std::swap(u,v);
        }
        return ModInt(u);
    }
    friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
        return os<<p.x;
    }
    friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
        long long x;
        is>>x;
        a=ModInt<mod>(x);
        return (is);
    }
};
typedef ModInt<MOD> mint;
typedef int64_t s64;
mint mpow(s64 num, s64 times) { // O(log(times))
    mint next = num%MOD;
	mint res = 1;
	while (times) {
		if (times%2)
            res *= next;
		next *= next;
		times /= 2;
	}
	return res;
}

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int n;
std::vector<int> a;
std::vector<std::vector<int> > child;


using T = std::deque<std::tuple<mint, mint, mint> >;
void merge(T &x, const T &y) {
	assert(x.size() >= y.size());
	for (size_t i = 0; i < y.size(); i++) {
		x[i] = std::tuple<mint, mint, mint>(std::get<0>(x[i]) * std::get<0>(y[i]),
			 	std::get<1>(x[i]) * std::get<0>(y[i]) + std::get<0>(x[i]) * std::get<1>(y[i]), 
				std::get<2>(x[i]) * (std::get<0>(y[i]) + std::get<1>(y[i])) + std::get<1>(x[i]) * std::get<1>(y[i]));
	}
}
std::vector<T> pool;
std::vector<int> depth_num;
size_t dfs(int i, int depth) {
	depth_num[depth]++;
	if (!child[i].size()) {
		pool.push_back({std::tuple<mint, mint, mint>(1, 1, 0)});
		return pool.size() - 1;
	} else {
		std::vector<size_t> all;
		for (auto j : child[i]) all.push_back(dfs(j, depth + 1));
		std::sort(all.begin(), all.end(), [](size_t x, size_t y) {
			return pool[x].size() < pool[y].size();
		});
		/*
		if (all.size() >= 2) {
			for (size_t i = 0; i < pool[all[all.size() - 2]].size(); i++) {
				std::get<2>(pool[all.back()][i]) = 0;
			}
		}*/
		for (size_t i = 0; i + 1 < all.size(); i++) {
			auto &cur = pool[all[i]];
			merge(pool[all.back()], cur);
		}
		if (all.size() >= 2) {
			for (size_t i = 0; i < pool[all[all.size() - 2]].size(); i++) {
				std::get<0>(pool[all.back()][i]) += std::get<2>(pool[all.back()][i]);
				std::get<2>(pool[all.back()][i]) = 0;
			}
		}
		pool[all.back()].push_front(std::tuple<mint, mint, mint>(1, 1, 0));
		return all.back();
	}
}

int main() {
	n = ri();
	depth_num.resize(n + 1);
	a.resize(n);
	for (int i = 0; i < n; i++) a[i] = ri();
	child.resize(n + 1);
	for (int i = 0; i < n; i++) child[a[i]].push_back(i + 1);
	auto &res = pool[dfs(0, 0)];
	mint ans = 0;
	for (size_t i = 0; i < res.size(); i++) {
		ans += std::get<1>(res[i]) * mpow(2, n + 1 - depth_num[i]);
		// std::cerr << i << ":" << std::get<1>(res[i]) << std::endl;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 192136