ADAGRAFT - Ada and Graft

no tags 

As you might already know, Ada the Ladybug is a farmer. She grows a big fruit tree (with root in 0). There is a fruit on every node of the tree. Ada is competing in grafting competition and this is her masterpiece. The most valuable tree wins the competition. The value of tree is product of values of each node. The value of a node is the number of distinct fruit kinds in its subtree.

Can you find the value of Ada's tree? Since this number might be pretty big, output it modulo 109+7

Input

The first and line will contain 1 ≤ N ≤ 4*105.

The next line will contain N-1 integers 0 ≤ pi < i, the parent of ith node.

The next line will contain N integers 0 ≤ Fi ≤ 109, the fruit growing on ith node.

Output

Print a single integer - the value of tree modulo 1000000007.

Example Input

5
0 0 1 1
1 1 1 2 2

Example Output

4

Example Input

4
0 1 2
6 7 2 3

Example Output

24

Example Input

11
0 1 1 1 3 5 2 7 5 4
494052753 959648710 959648710 959648710 494052753 959648710 959648710 959648710 959648710 494052753 959648710

Example Output

32

hide comments
nimphy: 2018-04-24 02:33:27

@julkas sorry,I
personally think it is not a good habit to spoiler alert before solving the problem by themselves;

amulyagaur: 2018-03-31 08:31:49

In love with MO's <3

Shubhojeet Chakraborty: 2017-12-27 07:38:47

@julkas spoiler alert

julkas: 2017-11-12 13:41:34

Good problem.

Last edit: 2018-11-29 19:46:17

Added by:Morass
Date:2017-11-06
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All