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>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;

const int N=2e5+1;
int n, p[N], root[N], cnt[N][2], l[N], r[N];
s64 ans;
bool less(int *x, int *y) {
	return (s64)x[1]*y[0]<(s64)x[0]*y[1];
}
int merge(int u, int v) {
	if(u==0||v==0) return u+v;
	if(less(cnt[v], cnt[u])) std::swap(u, v);
	l[u]=merge(l[u], v);
	std::swap(l[u], r[u]);
	return u;
}
int main() {
	n=rd();
	for(int i=2; i<=n; ++i) p[i]=rd();
	for(int i=1; i<=n; ++i) cnt[i][rd()]=1;
	for(int i=n; i>=1; --i) {
		while(root[i]&&less(cnt[root[i]], cnt[i])) {
			ans+=(s64)cnt[i][1]*cnt[root[i]][0];
			cnt[i][0]+=cnt[root[i]][0];
			cnt[i][1]+=cnt[root[i]][1];
			root[i]=merge(l[root[i]], r[root[i]]);
		}
		root[i]=merge(i, root[i]);
		if(i!=1) root[p[i]]=merge(root[i], root[p[i]]);
	}
	int s=0;
	while(root[1]) {
		ans+=(s64)s*cnt[root[1]][0];
		s+=cnt[root[1]][1];
		root[1]=merge(l[root[1]], r[root[1]]);
	}
	printf("%lld\n", ans);
	return 0;
}