#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
long long n, i, sum, ans, a[100005], p, d[20000009], cnt1, cnt2, lev[100005];
void dfs(int id) {
  lev[id] = 1;
  for (int ii = 0; ii < v[id].size(); ii++)
    dfs(v[id][ii]), lev[id] = max(lev[id], lev[v[id][ii]] + 1);
  if (lev[id] % 2 == 1)
    sum ^= a[id], cnt1++;
  else
    cnt2++, d[a[id]]++;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 2; i <= n; i++) cin >> p, v[p].push_back(i);
  dfs(1);
  if (sum == 0) ans = (cnt1 * (cnt1 - 1) / 2 + cnt2 * (cnt2 - 1) / 2);
  for (i = 1; i <= n; i++) {
    if (lev[i] % 2 == 0) continue;
    sum ^= a[i];
    ans += d[sum];
    sum ^= a[i];
  }
  cout << ans;
}
