#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
int value[10000000 + 7][3], level[100000 + 7], arr[100000 + 7];
long long odd;
vector<int> graph[100000 + 7];
void dfs(int u) {
  level[u] = 1;
  int v;
  for (int i = 0; i < graph[u].size(); i++) {
    v = graph[u][i];
    dfs(v);
    level[u] = level[v] ^ 1;
  }
  odd += level[u];
}
int main() {
  int mx = 0, n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  int p;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &p);
    graph[p].push_back(i);
  }
  dfs(1);
  int xr = 0;
  for (int i = 1; i <= n; i++) {
    value[arr[i]][level[i]]++;
    if (level[i]) xr = xr ^ arr[i];
  }
  long long ans = 0;
  if (xr == 0) {
    ans += (odd * (odd - 1)) / 2LL;
    odd = n - odd;
    ans += (odd * (odd - 1)) / 2LL;
  }
  for (int i = 1; i <= n; i++) {
    if (level[i] && (arr[i] ^ xr) <= 10000000) ans += value[arr[i] ^ xr][0];
  }
  printf("%lld\n", ans);
  return 0;
}
