#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100001];
bool even[100001];
vector<int> v[100001];
int dfs(int x, int d) {
  if (v[x].size() == 0) {
    even[x] = true;
    return d % 2;
  }
  int aaa = 0;
  for (int i = 0; i < (v[x].size()); i++) {
    aaa = dfs(v[x][i], (d + 1) % 2);
  }
  if (d % 2 == aaa % 2) {
    even[x] = true;
  } else {
    even[x] = false;
  }
  return aaa;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    a[i] = a[i];
  }
  for (int i = 0; i < (n - 1); i++) {
    int a;
    cin >> a;
    v[a - 1].push_back(i + 1);
  }
  dfs(0, 0);
  vector<long long> ev;
  vector<long long> od;
  for (int i = 0; i < (n); i++) {
    if (even[i] == true) {
      ev.push_back(a[i]);
    } else {
      od.push_back(a[i]);
    }
  }
  long long now = 0;
  for (int i = 0; i < (ev.size()); i++) {
    now = (now ^ ev[i]);
  }
  if (now == 0) {
    map<long long, int> m;
    for (int i = 0; i < (od.size()); i++) {
      m[od[i]]++;
    }
    long long ans = 0;
    for (int i = 0; i < (ev.size()); i++) {
      ans += m[ev[i]];
    }
    cout << ans + ev.size() * (ev.size() - 1) / 2 +
                od.size() * (od.size() - 1) / 2
         << endl;
  } else {
    map<long long, int> m;
    for (int i = 0; i < (od.size()); i++) {
      m[od[i]]++;
    }
    long long ans = 0;
    for (int i = 0; i < (ev.size()); i++) {
      long long t = (now ^ ev[i]);
      ans += m[t];
    }
    cout << ans << endl;
  }
  return (0);
}
