#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
int a[maxn];
bool color[maxn];
vector<int> g[maxn];
void add_edge(int u, int v) {
  g[u].push_back(v);
  g[v].push_back(u);
}
bool draw(int u, int father) {
  bool flag = false;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == father) continue;
    flag = true;
    color[u] = true ^ draw(v, u);
  }
  if (flag == false)
    return color[u] = false;
  else
    return color[u];
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      g[i].clear();
    }
    for (int i = 2; i <= n; i++) {
      int x;
      scanf("%d", &x);
      add_edge(i, x);
    }
    draw(1, -1);
    int s = 0;
    long long cnt_false = 0, cnt_true = 0;
    map<int, int> t, f;
    for (int i = 1; i <= n; i++) {
      if (color[i] == false) {
        s ^= a[i];
        cnt_false++;
        f[a[i]]++;
      } else {
        t[a[i]]++;
        cnt_true++;
      }
    }
    if (s == 0) {
      long long ans =
          cnt_true * (cnt_true - 1) / 2 + cnt_false * (cnt_false - 1) / 2;
      for (int i = 1; i <= n; i++) {
        if (color[i] == false) {
          ans += (long long)t[a[i]] * (long long)f[a[i]];
          t[a[i]] = 0;
          f[a[i]] = 0;
        }
      }
      printf("%I64d\n", ans);
    } else {
      long long ans = 0;
      for (int i = 1; i <= n; i++) {
        if (color[i] == false) {
          ans += t[s ^ a[i]];
        }
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
