#include <bits/stdc++.h>
const long long oo = 0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
long long o(long long x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
using namespace std;
void file_put() {
  freopen("filename.in", "r", stdin);
  freopen("filename.out", "w", stdout);
}
long long x, sum = 0, ans = 0;
int n, c[200005], p, cnt = 0, a[200005], dep = 0;
map<int, int> M[2];
vector<int> V[200005];
void dfs(int k, int p, int step) {
  M[step & 1][a[k]]++;
  dep = ((dep) > (step) ? (dep) : (step));
  for (int i = 0; i < V[k].size(); i++) {
    if (V[k][i] == p) continue;
    dfs(V[k][i], k, step + 1);
  }
}
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);
    V[p].push_back(i);
  }
  dfs(1, 0, 1);
  int now = dep & 1;
  for (auto it = M[now].begin(); it != M[now].end(); it++) {
    if (it->second % 2 == 0) continue;
    sum ^= it->first;
  }
  for (auto it = M[now].begin(); it != M[now].end(); it++)
    ans += (long long)it->second * M[now ^ 1][it->first ^ sum];
  for (auto it = M[now].begin(); it != M[now].end(); it++) cnt += (it->second);
  if (sum == 0) ans += (long long)cnt * (cnt - 1) / 2;
  if (sum == 0) ans += (long long)(n - cnt) * (n - cnt - 1) / 2;
  cout << ans << endl;
  return 0;
}
