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.
#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
const int MAXL = 1e5;
const double INF = 1e10;
const double eps = 1e-8;
inline int sgn(double);
inline int dcmp(double, double);
struct EDGE {
  int to;
  int next;
};
EDGE edge[MAXN << 1];
int head[MAXN], cnt;
inline void add_edge(int u, int v) {
  cnt++;
  edge[cnt].to = v;
  edge[cnt].next = head[u];
  head[u] = cnt;
}
typedef struct Interval {
  friend inline double GetLineInterSectionX(Interval&, Interval&);
  friend inline bool compare(Interval&, Interval&, long long);
  Interval(long long _k = 0, long long _b = 0);
  long long k;
  long long b;
  inline long long Get_Point(long long);
} LINE;
struct TREE_NODE {
  int l;
  int r;
  LINE rec;
};
TREE_NODE tree[200005 * 51];
int ncnt;
void update(int l, int r, Interval v, int& i) {
  if (!i) {
    tree[i = ++ncnt].rec = v;
    return;
  }
  double l1 = v.Get_Point(l), r1 = v.Get_Point(r);
  double l2 = tree[i].rec.Get_Point(l), r2 = tree[i].rec.Get_Point(r);
  if (l1 > l2 && r1 > r2)
    return;
  else if (l1 < l2 && r1 < r2)
    tree[i].rec = v;
  else {
    int mid = l + r >> 1;
    double x = GetLineInterSectionX(v, tree[i].rec);
    if (tree[i].rec.k < v.k) {
      if (x > mid) {
        update(mid + 1, r, tree[i].rec, tree[i].r);
        tree[i].rec = v;
      } else
        update(l, mid, v, tree[i].l);
    } else {
      if (x < mid) {
        update(l, mid, tree[i].rec, tree[i].l);
        tree[i].rec = v;
      } else
        update(mid + 1, r, v, tree[i].r);
    }
  }
}
long long query(int l, int r, long long x, int i) {
  if (!i) return INF;
  if (l == r) return tree[i].rec.Get_Point(x);
  int mid = l + r >> 1;
  long long res = tree[i].rec.Get_Point(x);
  if (x <= mid)
    return std::min(res, query(l, mid, x, tree[i].l));
  else
    return std::min(res, query(mid + 1, r, x, tree[i].r));
}
int merge(int l, int r, int x, int y) {
  if (!x || !y) return x | y;
  if (l == r) {
    if (tree[x].rec.Get_Point(l) > tree[y].rec.Get_Point(l))
      tree[x].rec = tree[y].rec;
    return x;
  }
  int mid = l + r >> 1;
  tree[x].l = merge(l, mid, tree[x].l, tree[y].l);
  tree[x].r = merge(mid + 1, r, tree[x].r, tree[y].r);
  update(l, r, tree[y].rec, x);
  return x;
}
int root[MAXN];
int a[MAXN], b[MAXN];
long long dp[MAXN];
void dfs(int u, int fa) {
  bool flag = true;
  for (int i = head[u], v; i; i = edge[i].next)
    if ((v = edge[i].to) != fa) {
      dfs(v, u);
      root[u] = merge(-MAXN, MAXN, root[u], root[v]);
      flag = false;
    }
  if (!flag) dp[u] = query(-MAXN, MAXN, a[u], root[u]);
  update(-MAXN, MAXN, {b[u], dp[u]}, root[u]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) printf("%lld ", dp[i]);
}
inline int sgn(double d) {
  if (fabs(d) < eps) return 0;
  return d > 0 ? 1 : -1;
}
inline int dcmp(double x, double y) { return sgn(x - y); }
inline Interval::Interval(long long _k, long long _b) : k(_k), b(_b) {}
inline long long Interval::Get_Point(long long x) { return k * x + b; }
inline double GetLineInterSectionX(Interval& l1, Interval& l2) {
  return (double)(l1.b - l2.b) / (l2.k - l1.k);
}
inline bool compare(Interval& l1, Interval& l2, long long x) {
  return l1.Get_Point(x) < l2.Get_Point(x);
}
