#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const int mod = (int)1e9 + 7;
const double PI = acos(-1.0);
const int MAX = 20000005;
const int N = 100009;
int n;
long long a[N];
int color[N];
vector<int> g[N];
int cnt[MAX][2];
void DFS(int u) {
  color[u] = -1;
  for (int i = 0; i < (int)(g[u]).size(); i++) {
    int v = g[u][i];
    DFS(v);
    color[u] = !color[v];
  }
  if (color[u] == -1) color[u] = 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p);
    g[--p].push_back(i);
  }
  DFS(0);
  long long Xor = 0;
  long long sum0 = 0, sum1 = 0;
  for (int i = 0; i < n; i++) {
    if (color[i] == 0) {
      Xor ^= a[i];
    }
    cnt[a[i]][color[i]]++;
    sum0 += (color[i] == 0);
    sum1 += (color[i] == 1);
  }
  long long res = 0;
  if (Xor == 0) {
    res += sum0 * (sum0 - 1) / 2 + sum1 * (sum1 - 1) / 2;
    for (int i = 0; i < MAX; i++) res += 1LL * cnt[i][0] * cnt[i][1];
  } else {
    for (int i = 0; i < n; i++) {
      if (color[i] == 0) res += cnt[Xor ^ a[i]][1];
    }
  }
  cout << res << endl;
  return 0;
}
