#include <bits/stdc++.h>
using namespace std;
int n, apple[100010], Max, h[100010];
vector<int> a[100010];
vector<int> blue, red;
void dfs(int u) {
  for (int i = (0); i <= (int((a[u]).size()) - 1); i++) {
    int v = a[u][i];
    h[v] = h[u] + 1;
    Max = max(Max, h[v]);
    dfs(v);
  }
}
int getLeft(vector<int> &red, int e) {
  int dau = 0, cuoi = int((red).size()) - 1, mid;
  while (dau <= cuoi) {
    mid = (dau + cuoi) >> 1;
    if (red[mid] >= e)
      cuoi = mid - 1;
    else
      dau = mid + 1;
  }
  return dau;
}
int getRight(vector<int> &red, int e) {
  int dau = 0, cuoi = int((red).size()) - 1, mid;
  while (dau <= cuoi) {
    mid = (dau + cuoi) >> 1;
    if (red[mid] > e)
      cuoi = mid - 1;
    else
      dau = mid + 1;
  }
  return cuoi;
}
pair<int, int> getRange(vector<int> &red, int e) {
  int lef = getLeft(red, e);
  if (lef < int((red).size()) && red[lef] == e) {
    int rig = getRight(red, e);
    return pair<int, int>(lef, rig);
  }
  return pair<int, int>(-1, -1);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = (1); i <= (n); i++) cin >> apple[i];
  for (int i = (2); i <= (n); i++) {
    int x;
    cin >> x;
    a[x].push_back(i);
  }
  h[1] = 1;
  Max = 1;
  dfs(1);
  int parity = Max % 2;
  int xorSum = 0;
  for (int i = (1); i <= (n); i++)
    if (h[i] % 2 == parity) xorSum ^= apple[i];
  long long res = 0;
  for (int i = (1); i <= (n); i++)
    if (h[i] % 2 == parity)
      blue.push_back(apple[i]);
    else
      red.push_back(apple[i]);
  long long cntBlue = int((blue).size());
  long long cntRed = int((red).size());
  sort((red).begin(), (red).end());
  if (xorSum) {
    for (int i = (0); i <= (int((blue).size()) - 1); i++) {
      int e = xorSum ^ blue[i];
      pair<int, int> range = getRange(red, e);
      if (range.first != -1) res += range.second - range.first + 1;
    }
  } else {
    res += cntBlue * (cntBlue - 1) / 2;
    res += cntRed * (cntRed - 1) / 2;
    for (int i = (0); i <= (int((blue).size()) - 1); i++) {
      int e = blue[i];
      pair<int, int> range = getRange(red, e);
      if (range.first != -1) res += range.second - range.first + 1;
    }
  }
  cout << res;
  return 0;
}
