#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 1e5 + 5;
map<int, int> m0, m1;
i64 ant;
int n;
vector<int> g[N];
int sg[N], a[N];
void dfs(int u) {
  if (g[u].empty())
    sg[u] = 1;
  else {
    for (auto v : g[u]) dfs(v);
    sg[u] = sg[g[u].back()] ^ 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int xs, l0, l1;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int t, i = 2; i <= n; ++i) {
    cin >> t;
    g[t].push_back(i);
  }
  dfs(1);
  l0 = l1 = xs = 0;
  for (int i = 1; i <= n; ++i)
    if (sg[i]) {
      xs ^= a[i];
      ++l1;
      ++m1[a[i]];
    } else {
      ++l0;
      ++m0[a[i]];
    }
  if (xs) {
    for (auto i : m0) ant += m1[xs ^ i.first] * i64(i.second);
  } else {
    ant = i64(l0) * (l0 - 1) / 2 + i64(l1) * (l1 - 1) / 2;
    for (auto i : m0) ant += m1[i.first] * i64(i.second);
  }
  cout << ant << '\n';
  return 0;
}
