#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct node {
  int to, next;
} edge[MAXN * 2];
int head[MAXN], top = 0;
void push(int i, int j) { edge[++top] = (node){j, head[i]}, head[i] = top; }
int depth[MAXN], a[MAXN], xr = 0;
void dfs_dep(int nd) {
  depth[nd] = 0;
  for (int i = head[nd]; i; i = edge[i].next) {
    int to = edge[i].to;
    dfs_dep(to);
    if (depth[to] == 0) depth[nd] = 1;
  }
  if (depth[nd] == 0) xr ^= a[nd];
}
map<int, int> mp;
int n, p[MAXN];
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]);
    push(p[i], i);
  }
  dfs_dep(1);
  for (int i = 1; i <= n; i++)
    if (depth[i] == 1) mp[a[i] ^ xr]++;
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (depth[i] == 0) ans += mp[a[i]];
  if (xr == 0) {
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) {
      if (depth[i] == 1)
        cnt1++;
      else
        cnt2++;
    }
    ans += (long long)cnt1 * (cnt1 - 1) / 2 + (long long)cnt2 * (cnt2 - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
