#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<int mod> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % mod) {
        if (val < 0) val += mod;
    }
    constexpr int getmod() { return mod; }
    constexpr Fp operator - () const noexcept {
        return val ? mod - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= mod) val -= mod;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % mod;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % mod;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream &is, const Fp<mod>& x) noexcept {
        int val; is >> val;
        x = Fp<mod>(val);
        return is;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<mod>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<mod> modpow(const Fp<mod> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int mod = 1e9+7;
using mint = Fp<mod>;

int main(){
    int n; cin  >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    if(n == 1){
        cout << a[0] << endl;
        return 0;
    }

    vector<mint> v(n), w(n);
    v[0] = 1; v[1] = 2;
    w[0] = 1; w[1] = 1;
    rep(i,n-2) {
        v[i+2] = v[i+1] + v[i];
        w[i+2] = w[i+1] + w[i];
    }

    mint ans = 0;
    rep(i,n) {
        mint p = v[n-1-i]*w[i];
        mint m = v[n-1]-p;
        ans += (mint)a[i]*(p-m);
    }
    cout << ans << endl;
}

    /**   Created by: Humberto Yusta
          Codeforces User: humbertoyusta
          Country: Cuba
          Copyright��                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2") //Enable AVX
/// Recently stolen pragmas:
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#pragma GCC optimize ("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
/// Constraints:
const int maxn = 100010;
const int mod = 1000000007;
const int mod2 = 998244353;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 1ll * mod * mod;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// rng
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/// Functions:
#define lg2(x) 63 - __builtin_clzll(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow and Primality Check------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return pwur * pwur % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
bool isprime(int x){
    for(int i=2; i*i<=x; i++)
        if( x % i == 0 ) return false;
    return true;
}
/// My Code -------------------------------------------------

int n, dp[maxn], subt[maxn], cnt[maxn];
vector<int> g[maxn];

void dfs(int u){

    for( auto v : g[u] )
        dfs(v);
    subt[u] = 1;
    for( auto v : g[u] ){
        subt[u] += subt[v];
        cnt[u] += subt[v] % 2;
    }

    if( subt[u] == 1 ){
        dp[u] = 0;
        return;
    }

    if( g[u].size() == 1 ){
        dp[u] = dp[g[u][0]];
        return;
    }

    vector<int> vx;
    for( auto v : g[u] ){
        if( subt[v] & 1 ){
            dp[u] += dp[v];
            vx.pb(-dp[v]+subt[v]-dp[v]);
        }
        else{
            if( dp[v] >= subt[v] - dp[v] ){
                dp[u] += dp[v];
            }
            else{
                if( cnt[u] % 2 ){
                    dp[u] += subt[v] - dp[v];
                }
                else{
                    dp[u] += dp[v];
                }
            }
        }
    }
    sort(all(vx));
    //reverse(all(vx));
    for(int i=1; i<vx.size(); i+=2){
         dp[u] += vx[i];
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);

    cin >> n;

    for(int i=1; i<=n; i++){
        dp[i] = 0;
    }

    for(int i=2; i<=n; i++){
        int u;
        cin >> u;
        g[u].pb(i);
    }

    dfs(1);

    for(int i=1; i<=n; i++){
        ;//db(dp[i])
    }

    cout << n - dp[1] << '\n';

    return 0;
}
