D. Lonely King
time limit per test
3 seconds
memory limit per test
1024 mebibytes
input
standard input
output
standard output

You are given a rooted tree with N vertices. Vertex 1 is the root, and each of the other N - 1 vertices has exactly one incoming edge. There are Ci people living in i-th vertex.

Initially, all edges are blue. You can change a "blue path" into a "red edge". Formally, when there are k blue edges, (a1, a2),  (a2, a3), ..., (ak, ak + 1), you can replace them with one red edge, (a1, ak + 1). You can execute this operation any number of times.

Because of the COVID-19, your purpose is to prevent contacts between people, so you want to minimize the total number of contacts.

The total number of contacts is the number of pairs of people (A, B) such that A and B live in different vertices and A can visit B via edges (of any color). Note that the edges are directed.

Find the minimum total number of contacts that can be achieved after some (possibly zero) operations on the tree.

Input

The first line contains an integer N, the number of vertices (1 ≤ N ≤ 200 000).

The next line contains N - 1 integers, P2, P3, ..., PN (1 ≤ Pi ≤ N). It means that vertex i has one incoming edge from vertex Pi. These numbers describe a rooted tree with vertex 1 as the root. Keep in mind that the edges are directed.

The next line contains N integers, C1, C2, ..., CN, which denote the number of people in each vertex (1 ≤ Ci ≤ 106).

Output

Print one integer, the minimum total number of contacts.

Example
Input
4
1 1 2
2 1 3 2
Output
10