ADAGRAFT  Ada and Graft
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 10^{9}+7
Input
The first and line will contain 1 ≤ N ≤ 4*10^{5}.
The next line will contain N1 integers 0 ≤ p_{i} < i, the parent of i^{th} node.
The next line will contain N integers 0 ≤ F_{i} ≤ 10^{9}, the fruit growing on i^{th} 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:
20180424 02:33:27
@julkas sorry,I


amulyagaur:
20180331 08:31:49
In love with MO's <3 

julkas:
20180106 15:11:31
Last edit: 20181129 19:47:32 

Shubhojeet Chakraborty:
20171227 07:38:47
@julkas spoiler alert 

julkas:
20171118 16:40:58
Last edit: 20171125 14:00:20 

julkas:
20171112 13:41:34
Good problem. Last edit: 20181129 19:46:17 
Added by:  Morass 
Date:  20171106 
Time limit:  3s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 