#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=2e5+10,mod=1e9+7;
LL f[M][2],g[M];
LL a[M];
int n;
int main(){
	n=read();
	F(i,1,n){
		a[i]=read();
	}
	f[0][0]=1; g[0]=1;
	F(i,1,n){
		f[i][0]=(f[i-1][1]+f[i-1][0])%mod;
		f[i][1]=f[i-1][0];
		g[i]=(f[i][1]+f[i][0])%mod;
	}
	LL tot=g[n-1];
	LL ans=g[n-1]*a[1]%mod;
//	cout<<tot<<"   tt\n";
	F(i,2,n){
		LL tmp=f[i-1][1]*(n-i-1<=0 ? 1 : g[n-i-1])%mod;
//		cout<<tmp<<"\n";
		ans=(ans+(tot-2ll*tmp%mod+mod)*a[i])%mod;
	}
	cout<<ans<<"\n";
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for (int i = 1; i < n; ++i) {
        int p;
        cin >> p;
        p--;
        g[p].push_back(i);
    }

    vector<int> f(n), sz(n);
    auto dfs = [&](auto self, int u) -> void {
        int stock = 0;
        vector<int> fs;
        for (int v : g[u]) {
            self(self, v);
            sz[u] += sz[v];
            if (sz[v] % 2 == 0) {
                if (f[v] < 0) {
                    f[u] += f[v];
                } else {
                    stock += f[v];
                }
            } else {
                fs.push_back(f[v]);
            }
        }
        sort(fs.begin(), fs.end());
        for (size_t i = 0; i < fs.size(); ++i) {
            f[u] += (i % 2 == 0 ? fs[i] : -fs[i]);
        }
        f[u] += (fs.size() % 2 == 0 ? stock : -stock);
        f[u]++;
        sz[u]++;
    };

    dfs(dfs, 0);

    int ans = (n + f[0]) / 2;
    cout << ans << '\n';
}