#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n1, long long n2) {
  if (!n1) return n2;
  if (!n2) return n1;
  if (n1 % n2 == 0) return n2;
  return gcd(n2, n1 % n2);
}
long long powmod(long long base, long long exponent) {
  base %= 1000000007;
  long long ans = 1;
  while (exponent) {
    if (exponent & 1) ans = (ans * base) % 1000000007;
    base = (base * base) % 1000000007;
    exponent /= 2;
  }
  ans %= 1000000007;
  return ans;
}
vector<int> adj[1000100 + 1];
int level[1000100 + 1];
vector<int> temp;
int freq[20 * 1000100 + 1];
int arr[1000100 + 1];
long long f(long long x) { return (x * (x - 1)) / 2; }
void dfs(int node, int lv) {
  level[node] = lv;
  for (int i = 0; i < adj[node].size(); i++) dfs(adj[node][i], lv + 1);
}
int main() {
  int n, i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &arr[i]);
  for (i = 2; i <= n; i++) {
    scanf("%d", &j);
    adj[j].push_back(i);
  }
  dfs(1, 1);
  int mx = 0, xr = 0;
  for (i = 1; i <= n; i++) mx = max(mx, level[i]);
  for (i = 1; i <= n; i++) {
    if ((mx & 1) == (level[i] & 1)) {
      temp.push_back(arr[i]);
      xr ^= arr[i];
    } else
      freq[arr[i]]++;
  }
  long long answer = 0;
  k = temp.size();
  if (!xr) answer = f(k) + f(n - k);
  for (i = 0; i < k; i++) answer += freq[(xr ^ temp[i])];
  printf("%lld\n", answer);
  return 0;
}
