#include <bits/stdc++.h>
using namespace std;
vector<int> p;
vector<int> b;
void paint(int u, int c) {
  if (u == -1 or b[u] != -1) return;
  b[u] = c;
  paint(p[u], 1 - c);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  b = vector<int>(n, -1);
  p = vector<int>(n);
  p[0] = -1;
  vector<bool> leaf(n, true);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 1; i < n; ++i) {
    cin >> p[i];
    --p[i];
    leaf[p[i]] = false;
  }
  for (int i = 1; i < n; ++i) {
    if (leaf[i]) {
      paint(i, 0);
    }
  }
  map<long long, long long> zero;
  long long s = 0, z = 0;
  for (int i = 0; i < n; ++i) {
    if (b[i] == 0) {
      ++zero[a[i]];
      s ^= a[i];
      ++z;
    }
  }
  long long r = 0;
  if (s == 0) {
    r += (z * (z - 1)) / 2;
    z = n - z;
    r += (z * (z - 1)) / 2;
  }
  for (int i = 0; i < n; ++i) {
    if (b[i] == 1) {
      r += zero[s ^ a[i]];
    }
  }
  cout << r << endl;
}
