Problem: Snuke has a rooted tree with N vertices, numbered 1 through N. Vertex 1 is the root of the tree, and the parent of Vertex i ( 2\leq i \leq N ) is Vertex P_i ( P_i < i ). There is a number, 0 or 1, written on each vertex. The number written on Vertex i is V_i.

Snuke would like to arrange the vertices of this tree in a horizontal row. Here, for every vertex, there should be no ancestor of that vertex to the right of that vertex.

After arranging the vertices, let X be the sequence obtained by reading the numbers written on the vertices from left to right in the arrangement. Snuke would like to minimize the inversion number of X. Find the minimum possible inversion number of X.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 1 \leq P_i < i ( 2 \leq i \leq N )
* 0 \leq V_i \leq 1 ( 1 \leq i \leq N )
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N
P_2 P_3 ... P_N
V_1 V_2 ... V_N


Output

Print the minimum possible inversion number of X.

Examples

Input

6
1 1 2 3 3
0 1 1 0 0 0


Output

4


Input

1

0


Output

0


Input

15
1 2 3 2 5 6 2 2 9 10 1 12 13 12
1 1 1 0 1 1 0 0 1 0 0 1 1 0 0


Output

31

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

namespace TYC
{
	typedef long long ll;
	const int N = 2e5 + 5;

	int n, Fa[N], C[N][2], bel[N];
	struct data
	{
		int p, c0, c1;
		bool operator < (const data &t) const { return (ll)c0 * t.c1 < (ll)t.c0 * c1; }
	};
	priority_queue<data> Q;

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	int find(const int x) { return bel[x] == x ? x : bel[x] = find(bel[x]); }

	void work()
	{
		n = read();
		for (int i = 2; i <= n; i++)
			Fa[i] = read();
		for (int i = 1; i <= n; i++)
		{
			C[i][read()] = 1, bel[i] = i;
			if (i != 1)
				Q.push({i, C[i][0], C[i][1]});
		}
		ll ans = 0;
		data v;
		for (int k = 1; k < n; k++)
		{
			do
			{
				v = Q.top();
				Q.pop();
			}
			while (v.c0 != C[v.p][0] || v.c1 != C[v.p][1]);
			int p = v.p, f = find(Fa[p]);
			ans += (ll)C[f][1] * C[p][0];
			C[f][0] += C[p][0];
			C[f][1] += C[p][1];
			bel[p] = f;
			if (f != 1)
				Q.push({f, C[f][0], C[f][1]});
		}
		printf("%lld\n", ans);
	}
}

int main()
{
	TYC::work();
	return 0;
}