#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool ckmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool ckmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
const long long MaxN = 1e5 + 50;
std::vector<long long> E[MaxN];
long long a[MaxN], dep[MaxN], dr[1 << 24];
inline void dfs(long long u) {
  for (auto v : E[u]) dfs(v), dep[u] = dep[v] ^ 1;
}
signed main(void) {
  long long n;
  read(n);
  for (long long i = 1; i <= n; ++i) read(a[i]);
  register long long x;
  for (long long i = 2; i <= n; ++i) read(x), E[x].push_back(i);
  dfs(1);
  register long long s = 0, c = 0;
  for (long long i = 1; i <= n; ++i)
    if (!(dep[i] & 1))
      s ^= a[i], ++c;
    else
      ++dr[a[i]];
  register long long ans = 0;
  if (!s) ans += c * (c - 1) / 2 + (n - c) * (n - c - 1) / 2;
  for (long long i = 1; i <= n; ++i)
    if (!(dep[i] & 1)) ans += dr[s ^ a[i]];
  write(ans), std::puts("");
  return 0;
}
