#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int b[maxn * 400];
int c[maxn];
int book[maxn * 100];
vector<int> edg[maxn];
int num, d, sg;
void dfs(int x, int e) {
  d = max(e, d);
  for (int i = 0; i < (int)edg[x].size(); i++) {
    dfs(edg[x][i], e + 1);
  }
}
void dfs2(int x, int e) {
  if (e % 2 == d % 2) {
    num++;
    sg ^= a[x];
    c[x] = 1;
  }
  for (int i = 0; i < (int)edg[x].size(); i++) {
    dfs2(edg[x][i], e + 1);
  }
  return;
}
int main() {
  int n, i, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int x;
  for (i = 2; i <= n; i++) {
    scanf("%d", &x);
    edg[x].push_back(i);
  }
  dfs(1, 1);
  dfs2(1, 1);
  long long ans = 0;
  if (sg == 0) {
    ans += (long long)(n - num) * (long long)(n - num - 1) / 2LL +
           (long long)num * (long long)(num - 1LL) / 2LL;
  }
  for (i = 1; i <= n; i++) {
    if (c[i]) {
      b[sg ^ a[i]]++;
    }
  }
  long long sum = 0;
  for (i = 1; i <= n; i++) {
    if (c[i] == 0) {
      ans += b[a[i]];
    }
  }
  cout << ans + sum / 2 << endl;
}
