#include <bits/stdc++.h>
using namespace std;
const long long N = 4e5 + 1000;
vector<long long> u[2];
long long c[N], s = 0, h[N];
vector<long long> a[N];
void dfs(long long v) {
  u[h[v]].push_back(c[v]);
  for (auto u : a[v]) {
    h[u] = 1 - h[v];
    dfs(u);
  }
}
long long f(long long x) {
  return upper_bound(u[0].begin(), u[0].end(), x) -
         lower_bound(u[0].begin(), u[0].end(), x);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (long long i = 1, x; i < n; i++) {
    cin >> x;
    a[x - 1].push_back(i);
  }
  dfs(0);
  sort(u[0].begin(), u[0].end());
  sort(u[1].begin(), u[1].end());
  for (long long i = 0; i < n; i++) {
    if (a[i].size() == 0) {
      if (h[i] == 1) swap(u[0], u[1]);
      break;
    }
  }
  for (long long i = 0; i < u[0].size(); i++) {
    s ^= u[0][i];
  }
  long long ans = 0;
  for (auto v : u[1]) {
    ans += f(v ^ s);
  }
  long long m = u[0].size();
  if (s == 0) {
    ans += (m - 1) * m / 2;
    m = u[1].size();
    ans += (m - 1) * m / 2;
  }
  cout << ans << "\n";
  return 0;
}
