#include <bits/stdc++.h>
using namespace std;
long long d[1 << 18], a[1 << 18], f[1 << 24], i, n, ans = 0, j, s = 0;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 2; i <= n; i++) cin >> j, d[i] = d[j] ^ 1;
  for (i = 1, j = 0; i <= n; i++) {
    if (d[i] - d[n])
      f[a[i]]++;
    else
      s ^= a[i], j++;
  }
  if (!s) ans += (j * j - j + (n - j) * (n - j - 1)) / 2;
  for (i = 1; i <= n; i++)
    if (d[i] == d[n]) ans += f[s ^ a[i]];
  cout << ans;
}
