You are given a tree with n nodes (numbered from 1 to n) rooted at node 1. Also, each node has two values associated with it. The values for i-th node are ai and bi.

You can jump from a node to any node in its subtree. The cost of one jump from node x to node y is the product of ax and by. The total cost of a path formed by one or more jumps is sum of costs of individual jumps. For every node, calculate the minimum total cost to reach any leaf from that node. Pay attention, that root can never be leaf, even if it has degree 1.

Note that you cannot jump from a node to itself.

Input

The first line of input contains an integer n (2 ≤ n ≤ 105) — the number of nodes in the tree.

The second line contains n space-separated integers a1, a2, ..., an( - 105 ≤ ai ≤ 105).

The third line contains n space-separated integers b1, b2, ..., bn( - 105 ≤ bi ≤ 105).

Next n - 1 lines contains two space-separated integers ui and vi (1 ≤ ui, vi ≤ n) describing edge between nodes ui and vi in the tree.

Output

Output n space-separated integers, i-th of which denotes the minimum cost of a path from node i to reach any leaf.

Examples

Input

3
2 10 -1
7 -7 5
2 3
2 1


Output

10 50 0 

Input

4
5 -10 5 7
-8 -80 -3 -10
2 1
2 4
1 3


Output

-300 100 0 0 

Note

In the first example, node 3 is already a leaf, so the cost is 0. For node 2, jump to node 3 with cost a2 × b3 = 50. For node 1, jump directly to node 3 with cost a1 × b3 = 10.

In the second example, node 3 and node 4 are leaves, so the cost is 0. For node 2, jump to node 4 with cost a2 × b4 = 100. For node 1, jump to node 2 with cost a1 × b2 = - 400 followed by a jump from 2 to 4 with cost a2 × b4 = 100.
import java.util.*;
import java.math.*;
import java.io.*;

public class CF932F {
	class Line {
		long m, b;  double left = Long.MIN_VALUE;
		public Line(long mm, long x, long y) { m = mm;  b = -m * x + y; }
		public Line(long mm, long bb) { m = mm;  b = bb; }
		long eval(long x) { return m * x + b; }
		double inter(Line x) { return (double) (x.b - b) / (double) (m - x.m); }
	}
	class CHT {
		TreeSet<Line> hull;
		int type;  boolean query = false;
		Comparator<Line> cmp = new Comparator<Line>() {
			public int compare(Line a, Line b) {
				if(!query) return type * Long.compare(a.m, b.m);
				if(a.left == b.left) return Long.compare(a.m, b.m);
				return Double.compare(a.left, b.left);
			}
		};
		public CHT(int tt) { type = tt;  hull = new TreeSet<>(cmp); }
		void add(long m, long b) { add(new Line(m, b)); }
		void add(Line a) {
			Line[] LR = { hull.lower(a), hull.ceiling(a) };
			for(int i= 0 ; i < 2 ; i++) {
				if(LR[i] != null && LR[i].m == a.m) {
					if(type == 1 && LR[i].b >= a.b) return;
					if(type == -1 && LR[i].b <= a.b) return;
					remove(LR[i]);
				}
			}
			hull.add(a);
			Line L = hull.lower(a), R = hull.higher(a);
			if(L != null && R != null && a.inter(R) <= R.left) {
				hull.remove(a);
				return;
			}
			Line LL = (L != null) ? hull.lower(L) : null;
			Line RR = (R != null) ? hull.higher(R) : null;
			if(L != null) a.left = a.inter(L);
			if(R != null) R.left = a.inter(R);
			while(LL != null && L.left >= a.inter(LL)) {
				remove(L);
				a.left = a.inter(L = LL);
				LL = hull.lower(L);
			}
			while(RR != null && R.inter(RR) <= a.inter(RR)) {
				remove(R);
				RR.left = a.inter(R = RR);
				RR = hull.higher(R);
			}
		}
		long query(long x) {
			Line tmp = new Line(0, 0, 0);
			tmp.left = x;  query = true;
			long res = (long) hull.floor(tmp).eval(x);
			query = false;  return res;
		}
		void remove(Line x) { hull.remove(x); }
		int size() { return hull.size(); }
	}
	class Graph {
		int n, p[], subtree[];
		long[] a, b, min;
		List<Integer>[] adj;
		CHT[] hull;
		Graph(int nn, long[] aa, long[] bb) {
			adj = new ArrayList[n = nn];
			for(int i = 0 ; i < n ; i++)
				adj[i] = new ArrayList<>();
			a = aa;  b = bb;
			p = new int[n];
			Arrays.fill(p, -1);
			hull = new CHT[n];
			subtree = new int[n];
			Arrays.fill(subtree, 1);
		}
		void add(int u, int v) {
			adj[u].add(v);
			adj[v].add(u);
		}
		void dfs(int u) {
			for(int v : adj[u]) {
				if(p[u] != v) {
					p[v] = u;
					dfs(v);
					subtree[u] += subtree[v];
				}
			}
		}
		void solve() {
			dfs(0);
			min = new long[n];
			int[] nodes = new int[n];
			int pointer = n;
			Deque<Integer> q = new ArrayDeque<>();
			q.add(0);
			while(!q.isEmpty()) {
				int u = q.pop();
				nodes[--pointer] = u;
				for(int v : adj[u])
					if(v != p[u])
						q.add(v);
			}
			for(int i = 0 ; i < n ; i++) {
				int u = nodes[i];
				if(adj[u].size() == 1 && p[u] != -1) {
					hull[u] = new CHT(-1);
					hull[u].add(new Line(b[u], 0));
				} else {
					int maxNode = -1;
					int maxSubtree = 0;
					for(int v : adj[u]) {
						if(v != p[u] && subtree[v] > maxSubtree) {
							maxSubtree = subtree[v];
							maxNode = v;
						}
					}
					hull[u] = hull[maxNode];
					for(int v : adj[u]) {
						if(v != p[u] && v != maxNode) {
							for(Line l : hull[v].hull)
								hull[u].add(l);
							hull[v] = null;
						}
					}
					long sum = hull[u].query(a[u]);
					long slope = b[u];
					hull[u].add(new Line(slope, sum));
					min[u] = sum;
				}
			}
		}
	}
	public CF932F() {
		FS scan = new FS();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();
		long[] a = new long[n], b = new long[n];
		for(int i = 0 ; i < n ; i++)
			a[i] = scan.nextInt();
		for(int i = 0 ; i < n ; i++)
			b[i] = scan.nextInt();
		Graph g = new Graph(n, a, b);
		for(int i = 0 ; i < n - 1 ; i++) {
			int u = scan.nextInt() - 1, v = scan.nextInt() - 1;
			g.add(u, v);
		}
		g.solve();
		for(long x : g.min)
			out.printf("%d ", x);
		out.close();
	}
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() {
			while(!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) { e.printStackTrace(); }
			}
			return st.nextToken();
		}
		public int nextInt() { return Integer.parseInt(next()); }
	}
	public static void main(String[] args) { new CF932F(); }
}
