#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, maxa = 1e7;
int n, a[maxn], p[maxn], s, cnt, x[maxa + 10], y[maxa + 10];
bool flag[maxn], ind[maxn];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 2; i <= n; i++) scanf("%d", &p[i]), ind[p[i]] = 1;
  for (int i = 1; i <= n; i++)
    if (!ind[i]) {
      int u = i;
      while (u && !flag[u]) flag[u] = 1, u = p[p[u]];
    }
  for (int i = 1; i <= n; i++)
    if (flag[i])
      ++cnt, s ^= a[i], ++x[a[i]];
    else
      ++y[a[i]];
  if (!s) {
    if (cnt >= 2) ans += 1ll * cnt * (cnt - 1) / 2;
    if (n - cnt >= 2) ans += 1ll * (n - cnt) * (n - cnt - 1) / 2;
    for (int i = 0; i <= maxa; i++) ans += 1ll * x[i] * y[i];
    printf("%I64d\n", ans);
  } else {
    for (int i = 0; i <= maxa; i++)
      ans += 1ll * x[i] * ((s ^ i) <= maxa ? y[s ^ i] : 0);
    printf("%I64d\n", ans);
  }
  return 0;
}
