#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
vector<int> g[N];
int cnt[1 << 24], cnt2[1 << 24], n;
int a[N], x, is, val, have[N], ed;
void dfs(int x = 1, int d = 0, int fa = 0) {
  if (g[x].size() == 0) {
    is = (d & 1);
  }
  for (auto &it : g[x])
    if (it != fa) dfs(it, d + 1, x);
}
void dfs2(int x = 1, int d = 0, int fa = 0) {
  if ((d & 1) == is) have[++ed] = a[x];
  for (auto &it : g[x])
    if (it != fa) dfs2(it, d + 1, x);
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%d", a + i), cnt[a[i]]++;
  for (int i = (2); i <= (n); ++i) {
    scanf("%d", &x);
    g[x].push_back(i);
  }
  dfs(), dfs2();
  for (int i = (1); i <= (ed); ++i) val ^= have[i], cnt2[have[i]]++;
  long long ans = 0;
  for (int i = (1); i <= (ed); ++i) {
    int tmp = val ^ have[i];
    ans += cnt[tmp] - cnt2[tmp];
  }
  if (!val) {
    ans += 1ll * ed * (ed - 1) / 2;
    ans += 1ll * (n - ed) * (n - ed - 1) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}
