import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class SagheerAppleTree_AC1 {
static final int MAXA = 10000000;
static ArrayList<Integer>[] adjList;
static boolean[] blue;
static int xorValue, cnt, cntBlue[], cntRed[],a[];
static void dfs(int u)
{
for(int v: adjList[u])
dfs(v);
blue[u] = adjList[u].size() == 0 || !blue[adjList[u].get(0)];
if(blue[u])
{
xorValue ^= a[u];
cntBlue[a[u]]++;
++cnt;
}
else
cntRed[a[u]]++;
}
Scanner sc
= new Scanner
(System.
in);
int n = sc.nextInt();
a = new int[n];
for(int i = 0; i < n; ++i)
a[i] = sc.nextInt();
for(int i = 0; i < n; ++i)
adjList[i] = new ArrayList<>(1);
for(int i = 1; i < n; ++i)
adjList[sc.nextInt() - 1].add(i);
blue = new boolean[n];
cntBlue = new int[MAXA + 1];
cntRed = new int[MAXA + 1];
dfs(0);
long ans = 0;
if(xorValue == 0)
{
for(int i = 1; i <= MAXA; ++i)
ans += 1l * cntBlue[i] * cntRed[i];
long x = cnt, y = n - x;
ans += x * (x - 1) / 2 + y * (y - 1) / 2;
}
else
{
for(int i = 1; i <= MAXA; ++i)
{
int j = xorValue ^ i;
if(j <= MAXA)
ans += 1l * cntBlue[i] * cntRed[j];
}
}
out.println(ans);
out.flush();
out.close();
}
static class Scanner
{
{
while (st == null || !st.hasMoreTokens())
return st.nextToken();
}
public boolean ready
() throws IOException {return br.
ready();} }
}