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.io.*;
import java.util.*;

public class CF932F {
    static int MIN_X = (int)-1e5 - 5, MAX_X = (int)1e5 + 5;
    static int N, A[], B[];
    static long ans[];
    static ArrayList<Integer> g[];
    static ArrayList<Line> lines[];
    static LiChaoNode roots[];

    public static void main(String args[]) throws Exception {
        FastReader fr = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int N = fr.nextInt();
        A = new int[N];
        B = new int[N];
        for (int i = 0; i < N; i++) A[i] = fr.nextInt();
        for (int i = 0; i < N; i++) B[i] = fr.nextInt();
        g = new ArrayList[N];
        for (int i = 0; i < N; i++) g[i] = new ArrayList<>();
        for (int i = 0; i < N - 1; i++) {
            int u = fr.nextInt() - 1, v = fr.nextInt() - 1;
            g[u].add(v); g[v].add(u);
        }

        lines = new ArrayList[N];
        roots = new LiChaoNode[N];
        ans = new long[N];
        dfs(0, 0);

        for (int i = 0; i < N; i++)
            pw.print(ans[i] + " ");

        pw.close();
    }

    static int dfs(int u, int p) {
        int h = u;
        roots[h] = new LiChaoNode(MIN_X, MAX_X, null);
        lines[h] = new ArrayList<Line>();
        for (int v : g[u]) if (v != p) {
            int h1 = dfs(v, u);
            if (lines[h].size()  < lines[h1].size()) { int t = h; h = h1; h1 = t; }
            for (Line l : lines[h1]) {
                roots[h].insert(l);
                lines[h].add(l);
            }
        }
        if (h != u) ans[u] = roots[h].query(A[u]);
        Line l = new Line(B[u], ans[u]);
        roots[h].insert(l);
        lines[h].add(l);
        return h;
    }
}

class LiChaoNode {
    int s, e, m;
    Line cur;
    LiChaoNode lt, rt;

    LiChaoNode(int ss, int ee, Line l) {
        s = ss; e = ee; m = (s + e) >> 1; cur = l;
    }

    void insert(Line l) {
        if (cur == null) {
            cur = l;
            return;
        }
        boolean b1 = l.eval(s) < cur.eval(s);
        boolean b2 = l.eval(m) < cur.eval(m);
        if (b2) { Line t = l; l = cur; cur = t; }
        if (s == e) return;
        if (b1 != b2) {
            if (lt == null) lt = new LiChaoNode(s, m, l);
            else lt.insert(l);
        } else {
            if (rt == null) rt = new LiChaoNode(m + 1, e, l);
            else rt.insert(l);
        }
    }

    long query(int x) {
        long y = cur.eval(x);
        if (x < m && lt != null) y = Math.min(y, lt.query(x));
        if (x > m && rt != null) y = Math.min(y, rt.query(x));
        return y;
    }
}

class Line {
    long m, c;
    Line(long mm, long cc) { m = mm; c = cc; }
    long eval(long x) { return m * x + c; }
}

class FastReader{
    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if(index >= total){
            index = 0;
            total = in.read(buf);
            if(total <= 0)
                return -1;
        }
        return buf[index++];
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for(c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if(c == '-' || c == '+')
            c = scan();
        for(; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 0xf);
        return neg ? -val : val;
    }
}