Bobo has a rooted tree with n nodes which are conveniently labeled with 1,2,…,n. Node 1 is the root, and the i-th node has weight w_i.
He would like to find out f(2),f(3),…,f(n) where
f(i)=∑_j=1i−1w_LCA(i,j).
The input contains zero or more test cases, and is terminated by end-of-file. For each test case:
The first line contains an integer n (2≤n≤2⋅105).
The second line contains n integers w_1,w_2,…,w_n (1≤w_i≤104).
The third line contains (n−1) integers p_2,p_3,…,p_n, where p_i denotes an edge from the p_i-th node to the i-th node (1≤p_i≤n). The edges form a tree.
It is guaranteed that the sum of n does not exceed 2⋅105.
For each test case, output (n−1) integers: f(2),f(3),…,f(n).