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;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 1e5 + 1, inf = 1e5;
struct line {
  long long k;
  long long b;
  line(){};
  line(long long _k, long long _b) {
    k = _k;
    b = _b;
  }
  long long get(long long x) { return k * x + b; }
};
struct Node {
  line l = {inf, inf};
  Node* left = nullptr;
  Node* right = nullptr;
};
using pNode = Node*;
pNode t[N];
long long a[N], b[N], ans[N];
vector<long long> v[N];
vector<line> lines[N];
void del(pNode v) {
  if (!v) return;
  del(v->left);
  del(v->right);
  delete (v);
}
void add(pNode& v, long long l, long long r, line n) {
  if (!v) {
    v = new Node();
    v->l = n;
    return;
  }
  long long m = (l + r) / 2;
  bool mid = n.get(m) < v->l.get(m);
  bool left = n.get(l) < v->l.get(l);
  if (mid) swap(n, v->l);
  if (l == r - 1) return;
  if (left != mid)
    add(v->left, l, m, n);
  else
    add(v->right, m, r, n);
}
long long get(pNode v, long long l, long long r, long long x) {
  if (!v) return LLONG_MAX;
  long long m = (l + r) / 2;
  if (l == r - 1) return get(v->left, l, m, x);
  if (m > x)
    return min(v->l.get(x), get(v->left, l, m, x));
  else
    return min(v->l.get(x), get(v->right, m, r, x));
}
void dfs(long long x, long long p) {
  long long id = x;
  for (auto u : v[x]) {
    if (u == p) continue;
    dfs(u, x);
    if (lines[id].size() < lines[u].size()) id = u;
  }
  swap(t[x], t[id]);
  swap(lines[x], lines[id]);
  for (auto u : v[x]) {
    if (u == p || u == id) continue;
    del(t[u]);
    for (auto l : lines[u]) {
      add(t[x], -inf, inf, l);
      lines[x].push_back(l);
    }
    lines[u].clear();
  }
  if (!x || v[x].size() > 1) ans[x] = get(t[x], -inf, inf, a[x]);
  add(t[x], -inf, inf, {b[x], ans[x]});
  lines[x].push_back({b[x], ans[x]});
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  for (long long i = 0; i < n - 1; i++) {
    long long from, to;
    cin >> from >> to;
    from--, to--;
    v[from].push_back(to);
    v[to].push_back(from);
  }
  dfs(0, -1);
  for (long long i = 0; i < n; i++) cout << ans[i] << ' ';
}
