#include <bits/stdc++.h>
double eps = 1e-9;
using namespace std;
long long n, a[100005], p[100005], x, num_blue[10000002], num_red[10000002], b,
    r;
set<long long> s;
vector<int> g[100005];
int dd = 1;
void dfs(int v, bool blue) {
  if (blue) {
    x ^= a[v];
    b++;
    num_blue[a[v]]++;
  } else {
    r++;
    num_red[a[v]]++;
  }
  for (int i = 0; i < g[v].size(); i++) dfs(g[v][i], !blue);
}
void d(int v, int depth) {
  if (g[v].empty()) {
    dd = depth;
    return;
  }
  for (int i = 0; i < g[v].size(); i++) d(g[v][i], depth + 1);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], s.insert(a[i]);
  for (int i = 2; i <= n; i++) {
    cin >> p[i];
    g[p[i]].push_back(i);
  }
  d(1, dd);
  dfs(1, dd % 2);
  long long ans = 0;
  if (!x) {
    if (b) ans += (b * (b - 1)) / 2;
    ans += (r * (r - 1)) / 2;
    for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {
      long long i = *it;
      ans += num_red[i] * num_blue[i];
    }
  } else {
    for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {
      long long i = *it;
      long long y = x ^ i;
      if (y <= 10000000) ans += num_red[y] * num_blue[i];
    }
  }
  cout << ans << endl;
}
