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.
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;

public class e812 implements Runnable{
	
    public static void main(String[] args) {
    	try{
            new Thread(null, new e812(), "process", 1<<26).start();
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
	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;

		static List<List<Integer>> adj = new ArrayList<>();
		static long[] apples;
		static long[] depth;
		
		static Map<Long, Long> blue = new HashMap<>();
		static Map<Long, Long> red = new HashMap<>();
		public void solve(int testNumber, FastReader sc, PrintWriter out) {
			int N = sc.nextInt();
			apples = new long[N+1];
			for(int i = 1; i <= N; i++) {
				apples[i] = sc.nextInt();
				adj.add(new ArrayList<>());
			}
			adj.add(new ArrayList<>());
			
			for(int i = 2; i <= N; i++) {
				adj.get(sc.nextInt()).add(i);
			}
			
			depth = new long[N+1];
			dfs(1, 0);
			
			long blueCount = 0, redCount = 0;
			if(maxDepth % 2 == 0) {
				for(int i = 1; i < depth.length; i++) {
					if(depth[i] % 2 == 0) {
						if(!blue.containsKey(apples[i]))
							blue.put(apples[i], 0l);
						blue.put(apples[i], blue.get(apples[i])+1);
						blueCount++;
					} else {
						if(!red.containsKey(apples[i]))
							red.put(apples[i], 0l);
						red.put(apples[i], red.get(apples[i]) +1);
						redCount++;
					}
				}
			} else {
				for(int i = 1; i < depth.length; i++) {
					if(depth[i] % 2 == 1) {
						if(!blue.containsKey(apples[i]))
							blue.put(apples[i], 0l);
						blue.put(apples[i], blue.get(apples[i])+1);
						blueCount++;
					} else {
						if(!red.containsKey(apples[i]))
							red.put(apples[i], 0l);
						red.put(apples[i], red.get(apples[i]) +1);
						redCount++;
					}
				}
			}
			
			Map<Long, Long> xor = new HashMap<>();
			long XOR = 0;
			for(long each: blue.keySet()) {
				if(blue.get(each) % 2 == 1) {
					XOR ^= each;
				}
			}
			
			for(long each: blue.keySet()) {
				if(!xor.containsKey(XOR ^ each)) {
					xor.put(XOR ^ each, 0l);
				}
				xor.put(XOR ^ each, xor.get(XOR ^ each) + blue.get(each));
			}
			if(XOR == 0) { // Sagheer guaranteed a win anyways -- don't change the tree
				long total = blueCount * (blueCount - 1) / 2;
				total += (redCount * (redCount - 1)) / 2;
				for(long each: blue.keySet()) {
					if(red.containsKey(each)) {
						total += blue.get(each) * red.get(each);
					}
				}
				out.println(total);
				return;
			}
			
			//System.out.println(xor);
			long total = 0;
			for(long each: xor.keySet()) {
				if(red.containsKey(each)) {
					total += xor.get(each) * red.get(each);
				}
			}
			out.println(total);
			
		}
		
		static long maxDepth = 0;
		
		public static void dfs(int node, long dep) {
			depth[node] = dep;
			maxDepth = Math.max(maxDepth, dep);
			
			for(int each: adj.get(node)) {
				dfs(each, dep+1);
			}
		}
	}
	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>, Comparator<tup>{
		int a, b;
		tup(int a,int b){
			this.a=a;
			this.b=b;
		}
		public tup() {
		}
		@Override
		public int compareTo(tup o){
			return Integer.compare(b,o.b);
		}
		@Override
		public int compare(tup o1, tup o2) {
			return Integer.compare(o1.b, o2.b);
		}
		
		@Override
	    public int hashCode() {
			return Objects.hash(a, b);
	    }
 
	    @Override
	    public boolean equals(Object obj) {
	    	if (this == obj)
                return true;
	    	if (obj == null)
                return false;
	    	if (getClass() != obj.getClass())
                return false;
	    	tup other = (tup) obj;
	    	return a==other.a && b==other.b;
	    }
	    
	    @Override
	    public String toString() {
	    	return a + " " + b;
	    }
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			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(a.length);
			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;
		}
	}

}