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]]++;
	}
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		a = new int[n];
		for(int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		adjList = new ArrayList[n];
		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 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException { return Double.parseDouble(next()); }

		public boolean ready() throws IOException {return br.ready();} 
	}
}
