#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> c(n), p(n, 0);
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 1; i < n; i++) cin >> p[i], p[i]--;
  vector<vector<int> > child(n);
  for (int i = 1; i < n; i++) child[p[i]].push_back(i);
  vector<int> col(n, 0);
  col[0] = 1;
  vector<int> q;
  q.push_back(0);
  int depth = 1;
  for (int i = 0; i < q.size(); i++) {
    for (auto j : child[q[i]])
      if (!col[j])
        q.push_back(j), col[j] = 1 + col[q[i]], depth = max(depth, col[j]);
  }
  multiset<int> even, odd;
  int xorsum = 0;
  for (int i = 0; i < n; i++)
    if (col[i] % 2 == depth % 2)
      odd.insert(c[i]), xorsum ^= c[i];
    else
      even.insert(c[i]);
  long long swaps = 0;
  if (xorsum == 0) {
    long long a = odd.size();
    long long b = even.size();
    swaps = a * (a - 1) / 2 + b * (b - 1) / 2;
  }
  vector<int> freq(20000001, 0);
  for (auto i : even) freq[i]++;
  for (auto i : odd) swaps += freq[xorsum ^ i];
  cout << swaps;
}
