#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
const int MAXA = 1e7 + 10;
std::map<long long, long long> numa;
long long a[MAXN];
std::vector<int> edg[MAXN];
int dep[MAXN];
int ji[MAXN];
int mxdep = 0;
void dfs(int u, int fa, int depth) {
  dep[u] = depth;
  mxdep = std::max(mxdep, depth);
  int flag = 0;
  for (auto val : edg[u]) {
    if (val == fa) continue;
    flag = 1;
    dfs(val, u, depth + 1);
    ji[u] = (ji[val] + 1) % 2;
  }
  if (!flag) ji[u] = 1;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int N;
  std::cin >> N;
  for (int i = 1; i <= N; i++) {
    std::cin >> a[i];
  }
  for (int i = 2, x; i <= N; i++) {
    std::cin >> x;
    edg[x].push_back(i);
  }
  dfs(1, -1, 0);
  long long ans = 0;
  std::multiset<long long> st;
  long long numji = 0;
  for (int i = 1; i <= N; i++) {
    if (dep[i] % 2 == mxdep % 2) {
      ans ^= a[i];
      numji++;
    } else {
      numa[a[i]]++;
    }
  }
  long long rlans = 0;
  if (ans) {
    for (int i = 1; i <= N; i++) {
      if (dep[i] % 2 == mxdep % 2) {
        if ((ans ^ a[i]) >= 0) rlans += numa[ans ^ a[i]];
      }
    }
  } else {
    long long sum = 0;
    for (int i = 1; i <= N; i++) {
      if (dep[i] % 2 == mxdep % 2) {
        rlans += numa[a[i]];
      } else {
        sum++;
      }
    }
    rlans += ((sum - 1) * sum) / 2 + (N - sum) * (N - sum - 1) / 2;
  }
  std::cout << rlans << '\n';
}
