#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
map<int, int> cnt;
int n, m, i, j, a[100005], d[100005], x, t;
vector<int> e[100005];
long long ans;
void dfs(int x) {
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    dfs(*it);
    d[x] = !d[*it];
  }
}
int main() {
  read(n);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) read(a[i]);
  for (((i)) = (1); ((i)) <= ((n - 1)); ((i))++) {
    read(x);
    e[x].push_back(i + 1);
  }
  dfs(1);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++)
    if (d[i]) {
      cnt[a[i]]++;
    } else {
      t ^= a[i];
      m++;
    }
  if (!t) {
    ans = 1ll * m * (m - 1) / 2 + 1ll * (n - m) * (n - m - 1) / 2;
  }
  for (((i)) = (1); ((i)) <= ((n)); ((i))++)
    if (!d[i]) ans += cnt[a[i] ^ t];
  cout << ans << endl;
  return 0;
}
