#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int64_t> A(N+1);
    vector<int64_t> M(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] += A[i-1];
        M[i] = M[i-1];
        M[i] = max(M[i], A[i]);
    }
    int64_t total = 0;
    int64_t ans = 0;
    for (int i = 1; i <= N; i++) {
        ans = max(ans, total + M[i]);
        total += A[i];
        ans = max(ans, total);
    }
    cout << ans;
}

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

const int N = 100005;

int n;
int p[N];

int sz[N];
vector<int> edges[N];

int dfs(int u) {
  sz[u] = 1;
  vector<int> evens;
  vector<int> odds;
  for (int v : edges[u]) {
    int val = dfs(v);
    sz[u] += sz[v];

    if (sz[v] & 1) {
      odds.emplace_back(val);
    } else {
      evens.emplace_back(val);
    }
  }

  int ret = 1;
  for (int i = 0; i < evens.size(); ++i) if (evens[i] < 0) ret += evens[i];
  sort(odds.begin(), odds.end());
  for (int i = 0; i < odds.size(); ++i) {
    if (i & 1) ret -= odds[i];
    else ret += odds[i];
  }

  for (int i = 0; i < evens.size(); ++i) {
    if (evens[i] >= 0) {
      if (odds.size() & 1) ret -= evens[i];
      else ret += evens[i];
    }
  }
  
  return ret;
}

int solve() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int p;
    scanf("%d", &p);
    edges[--p].push_back(i);
  }

  int ans = dfs(0);
  ans += sz[0];
  ans /= 2;

  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    solve();
  }
  return 0;
}
