Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

E. Sagheer and Apple Tree

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputSagheer 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 *a*_{i} 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:

- eat the apples, if the node is a leaf.
- 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* ≤ 10^{5}) — the number of nodes in the apple tree.

The second line will contain *n* integers *a*_{1}, *a*_{2}, ..., *a*_{n} (1 ≤ *a*_{i} ≤ 10^{7}) — the number of apples on each node of the tree.

The third line will contain *n* - 1 integers *p*_{2}, *p*_{3}, ..., *p*_{n} (1 ≤ *p*_{i} ≤ *n*) — the parent of each node of the tree. Node *i* has parent *p*_{i} (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.

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/25/2018 04:56:13 (d1).

Desktop version, switch to mobile version.

User lists

Name |
---|