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;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug &>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug &>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug &operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug &operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
long double eps = (long double)1 / 1e6;
const long double pi = 3.14159265359;
long long inf = 1e18, mod1 = 1e9 + 7;
long long sqr(long long a) { return a * a; }
long long qb(long long a) { return a * a * a; }
template <typename T>
bool umax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
bool umin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
bool is_prime(long long val) {
  for (long long i = 2; i <= sqrt(val); i++)
    if (val % i == 0) return 0;
  return 1;
}
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long binpow(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod
                    : sqr(binpow(a, b / 2, mod)) % mod)
           : 1;
}
long long binmult(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod
                    : (2 * binmult(a, b / 2, mod)) % mod)
           : 0;
}
const long long RR = 1e4;
const long long tx[8] = {1, -1, 2, -2, -1, -2};
const long long ty[8] = {-2, -2, -1, -1, 2, 1};
const char rev_to[4] = {'E', 'W', 'N', 'S'};
const int M = 1e9 + 7;
const int N = 1e5 + 3;
const int ppp = 73;
const int K = 2e5 + 2;
const int block = 600;
const int OPEN = 1;
const int CLOSE = 0;
auto rnd = bind(uniform_int_distribution<int>(1, 5969699), mt19937(time(0)));
void bad() {
  cout << "IMPOSSIBLE";
  exit(0);
}
const int Mx = 1e5 + 1;
struct line {
  long long k, b;
  long long first(int x) { return 1ll * k * x + b; }
  line(long long _k, long long _b) {
    k = _k;
    b = _b;
  }
};
struct node {
  node *l;
  node *r;
  line best = line(0, 1e18);
  node() {
    l = r = nullptr;
    best.k = 0;
    best.b = 1e18;
  }
};
node *add(node *v, line a, int tl = -Mx, int tr = Mx) {
  if (!v) {
    v = new node();
    v->best = a;
    return v;
  }
  int tm = (tl + tr) >> 1;
  bool bet1 = a.first(tl) < v->best.first(tl);
  bool bet2 = a.first(tm) < v->best.first(tm);
  if (bet2) {
    swap(v->best, a);
  }
  if (tl == tr) {
    return v;
  }
  if (bet1 != bet2) {
    v->l = add(v->l, a, tl, tm);
  } else {
    v->r = add(v->r, a, tm + 1, tr);
  }
  return v;
}
long long get(node *v, int x, int tl = -Mx, int tr = Mx) {
  if (!v) {
    return inf;
  }
  long long vl = v->best.first(x);
  if (tl == tr) {
    return vl;
  }
  int tm = (tl + tr) >> 1;
  if (tm >= x) {
    umin(vl, get(v->l, x, tl, tm));
  } else {
    umin(vl, get(v->r, x, tm + 1, tr));
  }
  return vl;
}
vector<int> g[N];
int sz[N];
long long dp[N];
int a[N], b[N];
vector<int> *w[N];
node *root[N];
void dfs(int v, int p) {
  sz[v] = 1;
  for (auto &z : g[v]) {
    if (z ^ p) dfs(z, v), sz[v] += sz[z];
  }
}
void dfs3(int v, int p, int nm) {
  root[nm] = add(root[nm], line(b[v], dp[v]));
  for (auto &z : g[v]) {
    if (z ^ p) dfs3(z, v, nm);
  }
}
void dfs2(int v, int p) {
  int big = -1;
  for (auto &z : g[v]) {
    if (z ^ p)
      if (big == -1 || sz[big] < sz[z]) big = z;
  }
  if (big == -1) {
    dp[v] = 0;
    root[v] = add(root[v], line(b[v], dp[v]));
    return;
  } else {
    dfs2(big, v);
    root[v] = root[big];
  }
  for (auto &z : g[v]) {
    if (z ^ p && z ^ big) {
      dfs2(z, v);
      dfs3(z, v, v);
    }
  }
  dp[v] = get(root[v], a[v]);
  root[v] = add(root[v], line(b[v], dp[v]), -Mx, Mx);
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 1; i < n; ++i) {
    int v, u;
    cin >> v >> u;
    --v;
    --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(0, 0);
  dfs2(0, 0);
  for (int i = 0; i < n; ++i) cout << dp[i] << ' ';
  return 0;
}
