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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.SplittableRandom;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            int[] b = new int[n];
            for (int i = 0; i < n; i++) {
                b[i] = in.nextInt();
            }

            int[] edgeA = new int[n - 1];
            int[] edgeB = new int[n - 1];
            for (int i = 0; i < n - 1; i++) {
                edgeA[i] = in.nextInt() - 1;
                edgeB[i] = in.nextInt() - 1;
            }

            boolean stress = false;
//        boolean stress = true;
            if (stress) {
                SplittableRandom random = new SplittableRandom();
                n = 100000;
                a = new int[n];
                b = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = random.nextInt(-n, n + 1);
                    b[i] = random.nextInt(-n, n + 1);
                }
                edgeA = new int[n - 1];
                edgeB = new int[n - 1];
                for (int i = 0; i < n - 1; i++) {
                    edgeA[i] = i + 1;
                    edgeB[i] = random.nextInt(i + 1);
//                edgeB[i] = i;
                }
            }

            Graph g = new Graph(n);
            for (int i = 0; i < n - 1; i++) {
                g.addEdge(edgeA[i], edgeB[i]);
                g.addEdge(edgeB[i], edgeA[i]);
            }
            EulerTourNumbering et = new EulerTourNumbering(g, 0 /* root */);

            long[] ans = new long[n];
            EnvelopeSet[] envelopes = new EnvelopeSet[n];
            for (int it = n - 1; it >= 0; it--) {
                int v = et.tour[it];

                envelopes[v] = new EnvelopeSet();
                ans[v] = Long.MAX_VALUE;

                for (int e = et.firstEdge[v]; e >= 0; e = et.edgeNxt[e]) {
                    int u = et.edgeDst[e];
                    if (!et.isInSubtree(v, u)) {
                        continue;
                    }

                    ans[v] = Math.min(ans[v], envelopes[u].getMin(a[v]));
                    envelopes[v].merge(envelopes[u]);
                }

                if (et.subtreeSize(v) == 1) {
                    // A leaf.
                    ans[v] = 0;
                }

                LinearFunction line = new LinearFunction();
                line.a = b[v];
                line.b = ans[v];
                envelopes[v].merge(new EnvelopeSet(line));
            }

            for (int i = 0; i < n; i++) {
                if (i > 0) {
                    out.print(" ");
                }
                out.print(ans[i]);
            }
            out.println();
        }

        class EnvelopeSet {
            int size;
            final int initialCapacity = 10;
            UpperEnvelope[] es = new UpperEnvelope[initialCapacity];

            EnvelopeSet() {
            }

            EnvelopeSet(LinearFunction line) {
                es[0] = new UpperEnvelope(new LinearFunction[]{line});
                size = 1;
            }

            void reallocate() {
                int k = es.length;
                es = Arrays.copyOf(es, 3 * k / 2);
            }

            void merge(EnvelopeSet o) {
                UpperEnvelope c = null;
                for (int i = 0; i < es.length || i < o.es.length || c != null; i++) {
                    if (i == es.length) {
                        reallocate();
                    }
                    UpperEnvelope a = es[i];
                    UpperEnvelope b = i < o.es.length ? o.es[i] : null;
                    if (a != null && b != null) {
                        es[i] = c;
                        c = new UpperEnvelope(a.hull, b.hull);
                    } else {
                        es[i] = a == null ? b : a;
                        if (es[i] != null && c != null) {
                            c = new UpperEnvelope(es[i].hull, c.hull);
                            es[i] = null;
                        } else if (c != null) {
                            es[i] = c;
                            c = null;
                        }
                    }
                }
                size += o.size;
            }

            long getMin(int x) {
                long res = Long.MAX_VALUE;
                for (UpperEnvelope e : es) {
                    if (e != null) {
                        res = Math.min(res, e.getMin(x));
                    }
                }
                return res;
            }

        }

        class UpperEnvelope {
            int size;
            LinearFunction[] hull;
            double[] intersectionPoints;

            UpperEnvelope(LinearFunction[] lines) {
                buildConvexHull(lines);
            }

            UpperEnvelope(LinearFunction[] lines1, LinearFunction[] lines2) {
                LinearFunction[] lines = Arrays.copyOf(lines1, lines1.length + lines2.length);
                System.arraycopy(lines2, 0, lines, lines1.length, lines2.length);
                buildConvexHull(lines);
            }

            void buildConvexHull(LinearFunction[] lines) {
                List<LinearFunction> hull = new ArrayList<>();
                List<Double> points = new ArrayList<>();
                Arrays.sort(lines, (u, v) -> {
                    if (u.a != v.a) {
                        return u.a > v.a ? -1 : 1;
                    }
                    if (u.b != v.b) {
                        return u.b > v.b ? -1 : 1;
                    }
                    return 0;
                });
                for (LinearFunction line : lines) {
                    Double x = Double.NEGATIVE_INFINITY;
                    while (!hull.isEmpty()) {
                        int i = hull.size() - 1;
                        x = hull.get(i).intersect(line);
                        if (x == null || x < points.get(i)) {
                            hull.remove(i);
                            points.remove(i);
                        } else {
                            break;
                        }
                    }
                    if (x == null) {
                        x = Double.NEGATIVE_INFINITY;
                    }
                    hull.add(line);
                    points.add(x);
                }

                size = hull.size();
                this.hull = new LinearFunction[size];
                this.intersectionPoints = new double[size];
                for (int i = 0; i < size; i++) {
                    this.hull[i] = hull.get(i);
                    if (i > 0) {
                        this.intersectionPoints[i - 1] = points.get(i);
                    }
                }
            }

            long getMin(int x) {
                int l = -1;
                int r = intersectionPoints.length - 1;
                while (r - l > 1) {
                    int m = (l + r) / 2;
                    if (x <= intersectionPoints[m]) {
                        r = m;
                    } else {
                        l = m;
                    }
                }
                long res = Long.MAX_VALUE;
                if (r < hull.length) {
                    res = hull[r].eval(x);
                }
                return res;
            }

        }

        class LinearFunction {
            long a;
            long b;

            long eval(long x) {
                return a * x + b;
            }

            Double intersect(LinearFunction o) {
                if (a == o.a) {
                    return null;
                }
                return (double) (b - o.b) / (o.a - a);
            }

        }

        class EulerTourNumbering {
            int n;
            int[] firstEdge;
            int[] edgeDst;
            int[] edgeNxt;
            int[] tour;
            int[] timeIn;
            int[] timeOut;
            int globalTime;

            EulerTourNumbering(Graph g, int root) {
                this.n = g.n;
                this.firstEdge = g.firstEdge;
                this.edgeDst = g.edgeDst;
                this.edgeNxt = g.edgeNxt;
                timeIn = new int[n];
                timeOut = new int[n];
                tour = new int[n];
                dfs(root, -1);
                if (globalTime != n) {
                    throw new AssertionError();
                }
            }

            void dfs(int v, int p) {
                tour[globalTime] = v;
                timeIn[v] = globalTime++;
                for (int e = firstEdge[v]; e >= 0; e = edgeNxt[e]) {
                    int u = edgeDst[e];
                    if (u == p) {
                        continue;
                    }
                    dfs(u, v);
                }
                timeOut[v] = globalTime;
            }

            boolean isInSubtree(int root, int candidate) {
                return timeIn[root] <= timeIn[candidate] && timeOut[candidate] <= timeOut[root];
            }

            int subtreeSize(int root) {
                return timeOut[root] - timeIn[root];
            }

        }

        class Graph {
            int n;
            int[] firstEdge;
            int[] edgeDst;
            int[] edgeNxt;
            int numEdges;

            Graph(int n) {
                this.n = n;
                firstEdge = new int[n];
                Arrays.fill(firstEdge, -1);
                final int initialCapacity = 2 * n - 2;
                edgeDst = new int[initialCapacity];
                edgeNxt = new int[initialCapacity];
                numEdges = 0;
            }

            void addEdge(int a, int b) {
                int e = numEdges++;
                if (e >= edgeDst.length) {
                    reallocate();
                }
                edgeDst[e] = b;
                edgeNxt[e] = firstEdge[a];
                firstEdge[a] = e;
            }

            private void reallocate() {
                int k = edgeDst.length;
                edgeDst = Arrays.copyOf(edgeDst, 3 * k / 2);
                edgeNxt = Arrays.copyOf(edgeNxt, 3 * k / 2);
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

