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>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T &t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __zz = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__zz] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__zz], --__zz)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
}  // namespace my_std
using namespace my_std;
int n;
long long a[101001], b[101001];
struct hh {
  int t, nxt;
} edge[101001 << 1];
int head[101001], ecnt;
void make_edge(int f, int t) {
  edge[++ecnt] = (hh){t, head[f]};
  head[f] = ecnt;
  edge[++ecnt] = (hh){f, head[t]};
  head[t] = ecnt;
}
struct Point {
  long long x, y;
  Point(long long X = 0, long long Y = 0) { x = X, y = Y; }
  const bool operator<(const Point &a) const { return x < a.x; }
  const Point operator+(const Point &a) const {
    return Point(x + a.x, y + a.y);
  }
  const Point operator-(const Point &a) const {
    return Point(x - a.x, y - a.y);
  }
};
long double Cross(Point a, Point b) {
  return (long double)b.y * a.x - (long double)a.y * b.x;
}
long long dp[101001];
set<Point> con[101001];
void insert(int id, Point a) {
  auto it = con[id].lower_bound(a);
  if (it != con[id].end() && (*it).x == a.x) {
    if ((*it).y <= a.y) return;
    con[id].erase(it++);
  }
  if (it != con[id].begin() && it != con[id].end() &&
      Cross(a - *prev(it), *it - *prev(it)) <= 0)
    return;
  while (233) {
    if (it == con[id].end() || next(it) == con[id].end()) break;
    auto i1 = it, i2 = next(it);
    auto p1 = *i1, p2 = *i2;
    if (Cross(p2 - a, p1 - a) >= 0)
      con[id].erase(it++);
    else
      break;
  }
  if (it == con[id].begin()) return (void)(con[id].insert(a));
  --it;
  while (233) {
    if (it == con[id].begin()) break;
    auto i1 = it, i2 = prev(it);
    auto p1 = *i1, p2 = *i2;
    if (Cross(a - p2, p1 - p2) >= 0)
      con[id].erase(it--);
    else
      break;
  }
  con[id].insert(a);
}
long long calc(Point a, long long k) { return a.y - k * a.x; }
long long query(int id, long long k) {
  long long ret = 1e18;
  if (con[id].size() <= 5) {
    for (auto a : con[id]) chkmin(ret, calc(a, k));
    return ret;
  }
  long long l = -1e6, r = 1e6;
  while (l <= r) {
    long long mid = (l + r) / 2;
    auto it = con[id].lower_bound(Point(mid, 0));
    if (it == con[id].end()) {
      r = mid - 1;
      continue;
    }
    chkmin(ret, calc(*it, k));
    if (next(it) == con[id].end()) {
      r = mid - 1;
      continue;
    }
    auto itt = next(it);
    if ((*itt).y - (*it).y >= k * ((*itt).x - (*it).x))
      r = mid - 1;
    else
      l = mid + 1;
  }
  return ret;
}
int rt[101001];
void dfs(int x, int fa) {
  for (int i = head[x]; i; i = edge[i].nxt)
    if (edge[i].t != fa) {
      dfs(edge[i].t, x);
      if (!rt[x]) {
        rt[x] = rt[edge[i].t];
        continue;
      }
      if (con[rt[x]].size() < con[rt[edge[i].t]].size())
        swap(rt[x], rt[edge[i].t]);
      for (auto w : con[rt[edge[i].t]]) insert(rt[x], w);
    }
  if (rt[x])
    dp[x] = query(rt[x], -a[x]);
  else
    rt[x] = x;
  insert(rt[x], (Point){b[x], dp[x]});
}
int main() {
  file();
  read(n);
  for (int i = (1); i <= (n); i++) read(a[i]);
  for (int i = (1); i <= (n); i++) read(b[i]);
  int x, y;
  for (int i = (1); i <= (n - 1); i++) read(x, y), make_edge(x, y);
  dfs(1, 0);
  for (int i = (1); i <= (n); i++) printf("%I64d ", dp[i]);
  return 0;
}
