#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 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;
  if (xorSum) {
    for (int i = (1); i <= (n); i++)
      if (h[i] % 2 == parity)
        blue.push_back(apple[i]);
      else
        red.push_back(apple[i]);
    sort((red).begin(), (red).end());
    for (int i = (0); i <= (int((blue).size()) - 1); i++) {
      int e = xorSum ^ blue[i];
      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;
      }
      if (dau < int((red).size()) && red[dau] == e) {
        int lef = dau;
        dau = 0;
        cuoi = int((red).size()) - 1;
        while (dau <= cuoi) {
          mid = (dau + cuoi) >> 1;
          if (red[mid] > e)
            cuoi = mid - 1;
          else
            dau = mid + 1;
        }
        int rig = cuoi;
        res += (rig - lef + 1);
      }
    }
  } else {
    long long cntBlue = 0;
    for (int i = (1); i <= (n); i++)
      if (h[i] % 2 == parity) cntBlue++;
    long long cntRed = n - cntBlue;
    res += cntBlue * (cntBlue - 1) / 2;
    res += cntRed * (cntRed - 1) / 2;
    for (int i = (1); i <= (n); i++)
      if (h[i] % 2 == parity)
        blue.push_back(apple[i]);
      else
        red.push_back(apple[i]);
    sort((red).begin(), (red).end());
    for (int i = (0); i <= (int((blue).size()) - 1); i++) {
      int e = blue[i];
      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;
      }
      if (dau < int((red).size()) && red[dau] == e) {
        int lef = dau;
        dau = 0;
        cuoi = int((red).size()) - 1;
        while (dau <= cuoi) {
          mid = (dau + cuoi) >> 1;
          if (red[mid] > e)
            cuoi = mid - 1;
          else
            dau = mid + 1;
        }
        int rig = cuoi;
        res += (rig - lef + 1);
      }
    }
  }
  cout << res;
  return 0;
}
