#include <bits/stdc++.h>
using namespace std;
const int N = 112345;
long long n;
long long v[N], cnt[21234567];
long long ans, leaf;
vector<long long> g[N], level[N];
long long xorao;
void dfs(long long u, long long lv) {
  leaf = max(leaf, lv);
  level[lv].emplace_back(v[u]);
  for (long long i = 0; i < g[u].size(); i++) {
    long long v = g[u][i];
    dfs(v, lv + 1);
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (long long i = 2; i <= n; i++) {
    long long x;
    cin >> x;
    g[x].emplace_back(i);
  }
  dfs(1, 0);
  long long pari = leaf % 2;
  long long imp = 0, nimp = 0;
  for (long long i = 0; i <= leaf; i++) {
    if (pari != i % 2) continue;
    for (long long j = 0; j < level[i].size(); j++) xorao ^= level[i][j], imp++;
  }
  for (long long i = 0; i <= leaf; i++) {
    if (pari == i % 2) continue;
    for (long long j = 0; j < level[i].size(); j++) cnt[level[i][j]]++, nimp++;
  }
  if (xorao) {
    for (long long i = 0; i <= leaf; i++) {
      if (pari != i % 2) continue;
      for (long long j = 0; j < level[i].size(); j++) {
        xorao ^= level[i][j];
        ans += cnt[xorao];
        xorao ^= level[i][j];
      }
    }
  } else {
    ans += imp * (imp - 1) / 2LL;
    ans += nimp * (nimp - 1) / 2LL;
    for (int i = 0; i <= leaf; i++) {
      if (pari != i % 2) continue;
      for (int j = 0; j < level[i].size(); j++) {
        ans += cnt[level[i][j]];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
