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;
inline long long int gcd(long long int x, long long int y) {
  return x % y == 0 ? y : gcd(y, x % y);
}
inline long long int lcm(long long int x, long long int y) {
  return x * (y / gcd(x, y));
}
inline long long int powmod(long long int a, long long int b,
                            long long int mod) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
inline long long int mulmod(long long int a, long long int b, long long int c) {
  if (!b) return 0;
  long long int x = mulmod(a, b / 2, c);
  if (b & 1) return (x + x + a) % c;
  return (x + x) % c;
}
class ConvexHullDynamic {
 private:
  struct Line {
    long long a, b;
    double xLeft;
    enum Type { line, maxQuery, minQuery } type;
    long long val;
    explicit Line(long long aa = 0, long long bb = 0)
        : a(aa), b(bb), xLeft(-INFINITY), type(Type::line), val(0) {}
    long long valueAt(long long x) const { return a * x + b; }
    friend bool areParallel(const Line& l1, const Line& l2) {
      return l1.a == l2.a;
    }
    friend double intersectX(const Line& l1, const Line& l2) {
      return areParallel(l1, l2) ? INFINITY
                                 : 1.0 * (l2.b - l1.b) / (l1.a - l2.a);
    }
    bool operator<(const Line& l2) const {
      if (l2.type == line) return this->a < l2.a;
      if (l2.type == maxQuery) return this->xLeft < l2.val;
      if (l2.type == minQuery) return this->xLeft > l2.val;
    }
  };

 private:
  bool isMax;
  std::set<Line> hull;

 private:
  bool hasPrev(std::set<Line>::iterator it) { return it != hull.begin(); }
  bool hasNext(std::set<Line>::iterator it) {
    return it != hull.end() && std::next(it) != hull.end();
  }
  bool irrelevant(const Line& l1, const Line& l2, const Line& l3) {
    return intersectX(l1, l3) <= intersectX(l1, l2);
  }
  bool irrelevant(std::set<Line>::iterator it) {
    return hasPrev(it) && hasNext(it) &&
           (isMax && irrelevant(*std::prev(it), *it, *std::next(it)) ||
            !isMax && irrelevant(*std::next(it), *it, *std::prev(it)));
  }
  std::set<Line>::iterator updateLeftBorder(std::set<Line>::iterator it) {
    if (isMax && !hasPrev(it) || !isMax && !hasNext(it)) return it;
    double val = intersectX(*it, isMax ? *std::prev(it) : *std::next(it));
    Line buf(*it);
    it = hull.erase(it);
    buf.xLeft = val;
    it = hull.insert(it, buf);
    return it;
  }

 public:
  explicit ConvexHullDynamic(bool isMax) : isMax(isMax) {}
  void addLine(long long a, long long b) {
    Line l3 = Line(a, b);
    auto it = hull.lower_bound(l3);
    if (it != hull.end() && areParallel(*it, l3)) {
      if (isMax && it->b < b || !isMax && it->b > b)
        it = hull.erase(it);
      else
        return;
    }
    it = hull.insert(it, l3);
    if (irrelevant(it)) {
      hull.erase(it);
      return;
    }
    while (hasPrev(it) && irrelevant(std::prev(it))) hull.erase(std::prev(it));
    while (hasNext(it) && irrelevant(std::next(it))) hull.erase(std::next(it));
    it = updateLeftBorder(it);
    if (hasPrev(it)) updateLeftBorder(std::prev(it));
    if (hasNext(it)) updateLeftBorder(std::next(it));
  }
  long long getBest(long long x) const {
    Line q;
    q.val = x;
    q.type = isMax ? Line::Type::maxQuery : Line::Type::minQuery;
    auto bestLine = hull.lower_bound(q);
    if (isMax) --bestLine;
    return bestLine->valueAt(x);
  }
};
long long int dep[100005], L[100005], R[100005], newval[100005], a[100005],
    b[100005];
long long int tms, finans;
vector<long long int> g[100005];
void dfs(long long int v, long long int fa) {
  dep[v] = dep[fa] + 1;
  L[v] = tms + 1;
  newval[++tms] = v;
  for (auto& u : g[v])
    if (u != fa) {
      dfs(u, v);
    }
  R[v] = tms + 1;
}
vector<ConvexHullDynamic> tree(4 * 100005, ConvexHullDynamic(false));
void pupdate(int node, int L, int R, int ind, long long int m,
             long long int c) {
  if (L > ind || R < ind) return;
  if (ind == L && R == ind) {
    tree[node].addLine(m, c);
    return;
  }
  pupdate(node * 2, L, (L + R) / 2, ind, m, c);
  pupdate(node * 2 + 1, (L + R) / 2 + 1, R, ind, m, c);
  tree[node].addLine(m, c);
}
void query(long long int node, long long int L, long long int R,
           long long int l, long long int r, long long int val) {
  if (L > r || R < l) return;
  if (l <= L && R <= r) {
    finans = min(finans, tree[node].getBest(val));
    return;
  }
  query(node * 2, L, (L + R) / 2, l, r, val);
  query(node * 2 + 1, (L + R) / 2 + 1, R, l, r, val);
}
long long int n, dp[100005];
const long long int inf = (long long int)(1e17);
void dfs2(long long int s, long long int par) {
  for (auto it : g[s]) {
    if (it != par) {
      dfs2(it, s);
    }
  }
  finans = inf;
  query(1, 1, n, L[s] + 1, R[s] - 1, a[s]);
  if (finans == inf) finans = 0;
  dp[s] = finans;
  pupdate(1, 1, n, L[s], b[s], dp[s]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int u, v;
  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++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) {
    cout << dp[i] << " ";
  }
  cout << endl;
  return 0;
}
