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>
using namespace std;
const long long inf = 1e18;
const int mxn = 1e5 + 5;
struct line {
  long long m, c;
  long long operator()(long long x) { return m * x + c; }
};
struct node {
  line seg;
  node *lc, *rc;
  node(line _seg) : seg(_seg), lc(NULL), rc(NULL) {}
};
typedef node* pnode;
void insert(pnode nd, int cl, int cr, line seg) {
  if (cr - cl == 1) {
    if (seg(cl) < nd->seg(cl)) nd->seg = seg;
    return;
  }
  int md = (cl + cr) / 2;
  if (seg.m < nd->seg.m) swap(seg, nd->seg);
  if (nd->seg(md) > seg(md)) {
    swap(seg, nd->seg);
    if (nd->rc)
      insert(nd->rc, md, cr, seg);
    else
      nd->rc = new node(seg);
  } else {
    if (nd->lc)
      insert(nd->lc, cl, md, seg);
    else
      nd->lc = new node(seg);
  }
}
long long query(pnode nd, int cl, int cr, long long x) {
  if (cr - cl == 1) return nd->seg(x);
  int md = (cl + cr) / 2;
  if (x < md && nd->lc)
    return min(nd->seg(x), query(nd->lc, cl, md, x));
  else if (nd->rc)
    return min(nd->seg(x), query(nd->rc, md, cr, x));
  else
    return nd->seg(x);
}
void del(pnode nd) {
  if (nd->lc) del(nd->lc);
  if (nd->rc) del(nd->rc);
  delete nd;
}
void merge(pnode cont, pnode nw) {
  if (nw->seg.m != 0 || nw->seg.c != inf) insert(cont, -mxn, mxn, nw->seg);
  if (nw->lc) merge(cont, nw->lc);
  if (nw->rc) merge(cont, nw->rc);
}
int n;
long long a[mxn], b[mxn], dp[mxn];
vector<int> adj[mxn];
pair<int, pnode> dfs(int nw, int bf) {
  int sz = 0;
  pnode root = new node((line){0, inf});
  for (int nx : adj[nw])
    if (nx != bf) {
      int sznx;
      pnode child;
      tie(sznx, child) = dfs(nx, nw);
      if (sz < sznx) swap(root, child);
      merge(root, child);
      del(child);
      sz += sznx;
    }
  dp[nw] = (sz ? query(root, -mxn, mxn, a[nw]) : 0);
  insert(root, -mxn, mxn, (line){b[nw], dp[nw]});
  return {sz + 1, root};
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) printf("%lld ", dp[i]);
  return 0;
}
