#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) { 
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const set<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll MOD = 1e9+7;
ll mod(ll a, ll b=MOD) {
  return ((a%b)+b)%b;
}
ll extended_euclid(ll a,ll b,ll &x,ll &y) {
    if (a == 0) { x = 0; y = 1; return b;}
    ll x1, y1; ll d = extended_euclid(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll mod_inverse(ll a, ll n=MOD) {
  ll x, y;
  ll d = extended_euclid(a, n, x, y);
  if (d > 1) return -1;
  return mod(x,n);
}
struct Mt {
    ll x = 0;
    Mt(){}
    Mt(ll y):x(mod(y)){}
    bool operator==(Mt &y){return x==y.x;}
    Mt operator+(Mt y){return mod(x+y.x);}
    Mt operator-(){return mod(-x);}
    Mt operator-(Mt y){return mod(x-y.x);}
    Mt operator*(Mt y){return mod(x*y.x);}
    Mt operator/(Mt y){return mod(x*mod_inverse(y.x));}
    Mt operator+=(Mt y){return x=(*this+y).x;}
    Mt operator-=(Mt y){return x=(*this-y).x;}
    Mt operator*=(Mt y){return x=(*this*y).x;}
    Mt operator/=(Mt y){return x=(*this/y).x;}
};
ostream& operator<<(ostream& os, const Mt&m){
    os << m.x; return os;
}

const ll N = 1e5+7;
ll a[N];
ll n;
ll CNT[N][2];
Mt cnt(ll x, bool lm) {
    ll &ret = CNT[x][lm];
    if(~ret) return ret;
    if(x==n) return 1;
    Mt r = cnt(x+1,0);
    if(x && !lm) r += cnt(x+1, 1);
    return ret=r.x;
}

ll DP[N][2];
Mt dp(ll x, bool lm) {
    ll &ret = DP[x][lm];
    if(~ret) return ret;
    if(x==n) return 0;
    Mt r = Mt(a[x])*cnt(x+1,0) + dp(x+1, 0);
    if(x && !lm) r += Mt(-a[x])*cnt(x+1,1) + dp(x+1, 1);
    return ret=r.x;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    CL(DP,-1); CL(CNT,-1);
    cin >> n;
    F(n) cin >> a[i];
    cout << dp(0,0) << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define For(i,a,b) for(register int i=a;i<=b;++i)
#define Down(i,a,b) for(register int i=a;i>=b;i--)
#define reg register
namespace yspm{
	inline int read(){
		int res=0,f=1; char k;
		while(!isdigit(k=getchar())) if(k=='-') f=-1;
		while(isdigit(k)) res=res*10+k-'0',k=getchar();
		return res*f;
	}
	const int N=1e5+10;
	inline int min(int x,int y){return x<y?x:y;}
	inline int max(int x,int y){return x>y?x:y;}
	inline void swap(int &x,int &y){int t=x; x=y; y=t; return ;}
	vector<int>g[N];
	int sz[N],f[N],n;
	inline void dfs(int x){
		sz[x]=1; vector<int> ev,od; f[x]=-1; 
		for(auto t:g[x]) dfs(t),sz[x]^=sz[t],sz[t]?od.push_back(f[t]):ev.push_back(f[t]);
		sort(od.begin(),od.end()); reverse(od.begin(),od.end());
		sort(ev.begin(),ev.end()); reverse(ev.begin(),ev.end());
		int ne=0,no=0,fl=0; 
		while(ne<ev.size()&&ev[ne]>0) f[x]+=ev[ne],++ne; 
		while(no<od.size()) fl?f[x]-=od[no]:f[x]+=od[no],++no,fl^=1; 
		while(ne<ev.size()) fl?f[x]-=ev[ne]:f[x]+=ev[ne],++ne;
		return ;
	}
	signed main(){
		n=read(); for(reg int i=2,tf;i<=n;++i) tf=read(),g[tf].push_back(i); dfs(1); 
		printf("%lld\n",(n-f[1])/2);
		return 0;
	}
}
signed main(){return yspm::main();}

