Hide

Problem E
Antivirus

A computer network has been infected by evil viruses, so Hacke Hackspett 1 has been tasked with removing them.

Each computer in the network has some number of viruses or antiviruses. There can never be both viruses and antiviruses in the same computer at the same time because they would immediately delete each other in pairs.

First, Hacke placed the $N$ computers in a row and numbered them from left to right with numbers $1$ to $N$. He then used $N$ one-way network cables to connect each computer to exactly one other computer. To make the setup tidy, he made sure that each computer is connected to a computer further to the left, except for computer number $1$, which could be connected to any other computer.

Each day, starting with day 1, Hacke will let the computer with the most antiviruses send them all to the computer that it is connected to. If multiple computers are tied for most antiviruses, he chooses the one furthest to the left (the one with the smallest number). If a virus-infected computer receives antiviruses, the viruses and antiviruses will delete each other in pairs. For example, if there are $5$ viruses in a computer when it receives $3$ antiviruses, only $2$ viruses will remain.

Input

The first line contains the integer $N$ ($2 \leq N \leq 200\, 000$), the number of computers.

The second line contains $N$ integers $a_1, \dots , a_ N$. For each $i$, Hacke has connected computer number $i$ to computer $a_ i$. $a_1 > 1$ and $1 \leq a_ i < i$ for $i \neq 1$.

The third line contains $N$ integers $b_1, \dots , b_ N$ ($-10^9 \leq b_ i \leq 10^9$). $b_ i$ is the number of viruses or antiviruses in computer $i$ at the start. A positive $b_ i$ means there are $b_ i$ antiviruses in computer $i$, while a negative $b_ i$ means there are $-b_ i$ viruses in computer $i$.

Output

Output the the day on which the last virus is deleted. If some virus will never be deleted (or if all antiviruses are deleted first), output never instead.

Sample Input 1 Sample Output 1
4
4 1 2 3
-3 0 2 1
5
Sample Input 2 Sample Output 2
4
4 1 2 3
-3 0 1 1
never
Sample Input 3 Sample Output 3
4
4 1 2 2
-1 2 2 -1
4

Footnotes

  1. Swedish for Woody Woodpecker

Please log in to submit a solution to this problem

Log in