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 int maxn = 1e5 + 5;
const int HullType = 0;
const long long inf = 1e18;
struct line {
  long long a, b;
  bool is_query;
  mutable double line_x;
  line() {
    a = 0;
    b = 0;
    line_x = 0;
    is_query = 0;
  }
  line(long long _a, long long _b) {
    a = _a;
    b = _b;
    line_x = 0;
    is_query = 0;
  }
  line(long long _a, long long _b, bool _is_query, double _line_x) {
    a = _a;
    b = _b;
    is_query = _is_query;
    line_x = _line_x;
  };
  bool operator<(const line &l2) const {
    if (!is_query && !l2.is_query)
      return HullType == 0 ? (a > l2.a) : (a < l2.a);
    else
      return line_x < l2.line_x;
  }
  long long value_at(long long x) const { return a * x + b; }
};
struct DynamicHull : set<line> {
  double intersect_x(const line &l1, const line &l2) {
    if (l1.a == l2.a) return (double)inf;
    return (double)(l1.b - l2.b) / (double)(l2.a - l1.a);
  }
  bool has_next(iterator it) { return it != end() && next(it) != end(); }
  bool has_prev(iterator it) { return it != end() && it != begin(); }
  bool irrelevant(const line &l1, const line &l2, const line &l3) {
    return intersect_x(l1, l3) <= intersect_x(l1, l2);
  }
  bool irrelevant(iterator it) {
    return has_prev(it) && has_next(it) &&
           irrelevant(*prev(it), *it, *next(it));
  }
  void update_border(iterator it) {
    if (has_next(it))
      it->line_x = intersect_x(*it, *next(it));
    else
      it->line_x = inf;
  }
  void add(long long a, long long b) {
    line curr_line = line(a, b);
    iterator it = lower_bound(curr_line);
    if (it != end() && it->a == a) {
      if ((HullType == 0 && it->b > b) || (HullType == 1 && it->b < b))
        it = erase(it);
      else
        return;
    }
    it = insert(it, curr_line);
    if (irrelevant(it)) {
      erase(it);
      return;
    }
    while (has_prev(it) && irrelevant(prev(it))) erase(prev(it));
    while (has_next(it) && irrelevant(next(it))) erase(next(it));
    update_border(it);
    if (has_prev(it)) update_border(prev(it));
    if (has_next(it)) update_border(next(it));
  }
  long long query(long long x) {
    if (empty()) return HullType == 0 ? inf : -inf;
    return lower_bound(line(0, 0, 1, x))->value_at(x);
  }
};
DynamicHull *h[maxn];
vector<int> v[maxn];
long long res[maxn];
int n, a[maxn], b[maxn], sz[maxn];
void DFS(int u, int p) {
  sz[u] = 1;
  for (int c : v[u])
    if (c != p) {
      DFS(c, u);
      sz[u] += sz[c];
    }
}
void DSU(int u, int p) {
  int big = -1;
  for (int c : v[u])
    if (c != p && (big == -1 || sz[c] > sz[big])) big = c;
  if (big == -1)
    h[u] = new DynamicHull;
  else
    DSU(big, u), h[u] = h[big];
  for (int c : v[u])
    if (c != p && c != big) {
      DSU(c, u);
      for (line d : (*h[c])) h[u]->add(d.a, d.b);
    }
  if (big != -1) res[u] = h[u]->query(a[u]);
  h[u]->add(b[u], res[u]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen(""
            ".INP",
            "r"))
    freopen(
        ""
        ".INP",
        "r", stdin),
        freopen(
            ""
            ".OUT",
            "w", stdout);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i];
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  DFS(1, 0);
  DSU(1, 0);
  for (int i = 1; i <= n; ++i) cout << res[i] << " ";
  return 0;
}
