#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 1e5 + 2;
int n, m, k, tc = 1, len, q;
vector<int> g[N];
int a[N], c[N], deg[N], leaf_color;
void dfs(int from, int color) {
  c[from] = color;
  for (int to : g[from]) {
    if (0 == c[to]) {
      dfs(to, c[from] == 2 ? 1 : 2);
    }
  }
  return;
}
inline long long f(long long x) {
  if (x <= 0) return 0;
  return (x * (x + 1)) >> 1;
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int x;
  for (int i = 2; i <= n; ++i) {
    cin >> x;
    g[x].push_back(i);
    g[i].push_back(x);
    deg[i]++;
    deg[x]++;
  }
  dfs(1, 1);
  for (int i = 1; i <= n; ++i) {
    if (deg[i] == 1) {
      leaf_color = c[i];
    }
  }
  vector<int> red_color, green_color;
  int xor_sum = 0;
  for (int i = 1; i <= n; ++i) {
    c[i] == 1 ? red_color.push_back(a[i]) : green_color.push_back(a[i]);
    if (c[i] == leaf_color) xor_sum ^= a[i];
  }
  sort((red_color).begin(), (red_color).end());
  sort((green_color).begin(), (green_color).end());
  long long ans = 0;
  if (leaf_color == 1) {
    for (int x : red_color) {
      int now = xor_sum ^ x;
      ans += upper_bound((green_color).begin(), (green_color).end(), now) -
             lower_bound((green_color).begin(), (green_color).end(), now);
    }
  } else {
    for (int x : green_color) {
      int now = xor_sum ^ x;
      ans += upper_bound((red_color).begin(), (red_color).end(), now) -
             lower_bound((red_color).begin(), (red_color).end(), now);
    }
  }
  if (xor_sum == 0) {
    ans += f(int(red_color.size()) - 1) + f(int(green_color.size()) - 1);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  while (tc--) {
    solve();
  }
  return 0;
}
