Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: the lengths of all paths from the root to any leaf have the same parity (i.e. all paths have even length or all paths have odd length).

Sagheer and Soliman will take turns to play. Soliman will make the first move. The player who can't make a move loses.

In each move, the current player will pick a single node, take a non-empty subset of apples from it and do one of the following two things:

  1. eat the apples, if the node is a leaf. 
  2. move the apples to one of the children, if the node is non-leaf. 



Before Soliman comes to start playing, Sagheer will make exactly one change to the tree. He will pick two different nodes u and v and swap the apples of u with the apples of v.

Can you help Sagheer count the number of ways to make the swap (i.e. to choose u and v) after which he will win the game if both players play optimally? (u, v) and (v, u) are considered to be the same pair.

Input

The first line will contain one integer n (2 ≤ n ≤ 105) — the number of nodes in the apple tree.

The second line will contain n integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the number of apples on each node of the tree.

The third line will contain n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n) — the parent of each node of the tree. Node i has parent pi (for 2 ≤ i ≤ n). Node 1 is the root of the tree.

It is guaranteed that the input describes a valid tree, and the lengths of all paths from the root to any leaf will have the same parity.

Output

On a single line, print the number of different pairs of nodes (u, v), u ≠ v such that if they start playing after swapping the apples of both nodes, Sagheer will win the game. (u, v) and (v, u) are considered to be the same pair.

Examples

Input

3
2 2 3
1 1


Output

1


Input

3
1 2 3
1 1


Output

0


Input

8
7 2 2 5 4 3 1 1
1 1 1 4 4 5 6


Output

4

Note

In the first sample, Sagheer can only win if he swapped node 1 with node 3. In this case, both leaves will have 2 apples. If Soliman makes a move in a leaf node, Sagheer can make the same move in the other leaf. If Soliman moved some apples from a root to a leaf, Sagheer will eat those moved apples. Eventually, Soliman will not find a move.

In the second sample, There is no swap that will make Sagheer win the game.

Note that Sagheer must make the swap even if he can win with the initial tree.

// Problem : E. Sagheer and Apple Tree
// Contest : Codeforces - Codeforces Round #417 (Div. 2)
// URL : https://codeforces.com/contest/812/problem/E
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class a implements Runnable{
	
    public static void main(String[] args) {
        new Thread(null, new a(), "process", 1<<26).start();
    }
	public void run() {
		FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		//PrintWriter out = new PrintWriter("file.out");
		Task solver = new Task();
		//int t = scan.nextInt();
		int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {
		static final int inf = Integer.MAX_VALUE;

		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			//CHECK FOR QUICKSORT TLE
			//***********************//
			//CHECK FOR INT OVERFLOW
			//***********************//
			int n = sc.nextInt();
			int[] weight = new int[n];
			for(int i = 0; i < n; i++) {
				weight[i] = sc.nextInt();
			}
			int[] leaves = new int[n];
			int[] pars = new int[n];
			for(int i = 0; i < n - 1; i++) {
				int p = sc.nextInt() - 1;
				pars[i] = p;
				leaves[p] = 1;
			}
			int[] color = new int[n];
			int[] vis = new int[n];
			ArrayDeque<Integer> dq = new ArrayDeque<Integer>();
			for(int i = 0; i < n; i++) {
				if(leaves[i] == 0) {
					dq.add(i);
					vis[i] = 1;
				}
			}
			
			while(!dq.isEmpty()) {
				int k = dq.poll();
				if(k == 0) continue;
				if(vis[pars[k - 1]] == 0) {
					vis[pars[k - 1]] = 1;
					color[pars[k - 1]] = color[k] ^ 1;
					dq.add(pars[k - 1]);
				}
			}
			int cxor = 0;
			int z = n;
			int o = 0;
			for(int i = 0; i < n; i++) {
				if(color[i] == 0) {
					cxor ^= weight[i];
					z--;
					o++;
				}
			}
			if(cxor == 0) {
				long sum = 0;
				sum += z * (z - 1l) / 2;
				sum += o * (o - 1l) / 2;
				HashMap<Integer, Integer> hm = new HashMap<>();
				for(int i = 0; i < n; i++){ 
					if(color[i] == 1) {
						hm.put(weight[i], hm.getOrDefault(weight[i], 0) + 1);
					}
				}
				for(int i = 0; i < n; i++) {
					if(color[i] == 0) {
						if(hm.get(weight[i]) != null) 
							sum += hm.get(weight[i]);
					}
				}
				pw.println(sum);
			}
			else{
				long sum = 0;
				HashMap<Integer, Integer> hm = new HashMap<>();
				for(int i = 0; i < n; i++){ 
					if(color[i] == 1) {
						hm.put(cxor ^ weight[i], hm.getOrDefault(cxor ^ weight[i], 0) + 1);
					}
				}
				for(int i = 0; i < n; i++) {
					if(color[i] == 0) {
						if(hm.get(weight[i]) != null)
						sum += hm.get(weight[i]);
					}
				}
				pw.println(sum);
			}
		}
	}
	static long binpow(long a, long b, long m) {
		a %= m;
		long res = 1;
		while (b > 0) {
			if ((b & 1) == 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
	}
	static void sort(int[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static void sort(long[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static class tup implements Comparable<tup>{
		int a, b;
		tup(int a,int b){
			this.a=a;
			this.b=b;
		}
		@Override
		public int compareTo(tup o){
			return Integer.compare(o.b,b);
		}
	}
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(i + 1);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(i + 1);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}