#include <bits/stdc++.h>
using namespace std;
int main() {
  unordered_map<long long, long long> tab[2];
  unordered_set<long long> ind[2];
  long long n, x;
  cin >> n;
  vector<long long> a(n);
  for (int i = (0); i <= (int(n) - 1); ++i) cin >> a[i];
  tab[0][a[0]]++;
  ind[0].insert(0);
  long long last = -1;
  for (int i = (0); i <= (int(n - 1) - 1); ++i) {
    cin >> x;
    if (ind[0].count(x - 1) > 0) {
      ind[1].insert(i + 1);
      tab[1][a[i + 1]]++;
      last = 1;
    } else {
      ind[0].insert(i + 1);
      tab[0][a[i + 1]]++;
      last = 0;
    }
  }
  if (last == 1) {
    swap(tab[0], tab[1]);
    swap(ind[0], ind[1]);
  }
  long long s = 0;
  long long c1 = 0, c2 = 0;
  for (auto it = tab[0].begin(); it != tab[0].end(); ++it) {
    if (it->second % 2 == 1) s ^= (it->first);
    c1 += (it->second);
  }
  for (auto it = tab[1].begin(); it != tab[1].end(); ++it) {
    c2 += (it->second);
  }
  long long res = 0;
  if (s == 0) {
    res = c1 * (c1 - 1) / 2 + c2 * (c2 - 1) / 2;
    for (auto it = tab[0].begin(); it != tab[0].end(); ++it) {
      res += (it->second * tab[1][it->first]);
    }
  } else {
    for (auto it = tab[1].begin(); it != tab[1].end(); ++it) {
      long long sn = s ^ it->first;
      res += (it->second * tab[0][sn]);
    }
  }
  cout << res << endl;
  return 0;
}
