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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> P(N);
    for ( int i = 1; i < N; i++ ) {
        cin >> P[i];
        P[i]--;
    }
    P[0] = -1;
    vector<vector<int>> G(N); // ch
    for ( int i = 1; i < N; i++ ) {
        G[P[i]].push_back(i);
    }

    vector<int> pt(N), sb(N,1);
    auto dfs = [&](auto self, int v) -> void {
        vector<vector<int>> val(2); // [even/odd] 選択したときに得るコインの差分
        for ( int u : G[v] ) {
            self(self, u);
            sb[v] += sb[u];
            val[sb[u]%2].push_back(pt[u]);
        }
        int s = -1;
        for ( int a : val[0] ) {
            if ( a > 0 ) s += a;
        }
        sort(val[1].rbegin(), val[1].rend());
        int odd = 1;
        for ( int a : val[1] ) {
            s += a * odd;
            odd *= -1;
        }
        for ( int a : val[0] ) {
            if ( a < 0 ) s += a * odd;
        }
        pt[v] = s;
    };
    dfs(dfs,0);
    
    ll ans = (N-pt[0])/2;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> vec(n);
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      cin >> vec[i];
    }
    else {
      ll tmp;
      cin >> tmp;
      vec[i] = vec[i-1] + tmp;
    }
  }

  ll cur = 0;
  ll ans = 0;
  ll vmax = vec[0];
  for (auto &v : vec) {
    vmax = max(v, vmax);
    ans = max(ans, cur + vmax);
    cur += v;
  }

  cout << ans << endl;
}
