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 pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;
 
#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)
 
typedef long long ll;
typedef int inte;
#define int ll
 
const int N=2e5+50;
 
struct Tuple { 
	int v,c0,c1;
	bool operator<(const Tuple &r)const{
		return c0*r.c1<r.c0*c1;
	}
};
priority_queue<Tuple> q;
 
int n,col[N],ufP[N],trP[N],c0[N],c1[N]; 
vector<int> g[N]; 
long long ans;
 
int find(int x){ return ufP[x]==x?x:ufP[x]=find(ufP[x]); }
 
inte main(inte argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
//	freopen("my.out","w",stdout);
#endif
	scanf("%lld",&n);
	rep(i,2,n){
		scanf("%lld",trP+i); 
		g[trP[i]].pb(i); 
	}
	rep(i,1,n){
		scanf("%lld",col+i); 
		c0[i]=col[i]==0;
		c1[i]=col[i]==1;
		ufP[i]=i;
		if(i>1)q.push((Tuple){i,c0[i],c1[i]});
	}
	rep(k,1,n-1){
		Tuple t;
		for(t=q.top();t.c0!=c0[t.v]||t.c1!=c1[t.v];q.pop(),t=q.top());	
		assert(find(t.v)==t.v);
		int f=find(trP[t.v]);
		ans+=1ll*c1[f]*c0[t.v];
		c0[f]+=c0[t.v];
		c1[f]+=c1[t.v];
		if(f>1)q.push((Tuple){f,c0[f],c1[f]});
		ufP[t.v]=f;
		c0[t.v]=c1[t.v]=-1;
	}
	printf("%lld\n", ans);
	return 0;
}