#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y / 2, x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long sum[200005];
struct ConvexHullDynamic {
  static const long long INF = 1e18;
  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(-INF), type(Type::line), val(0) {}
    long long valueAt(long long x) const { return a * x + b; }
    friend bool isParallel(const Line &l1, const Line &l2) {
      return l1.a == l2.a;
    }
    friend double llersectX(const Line &l1, const Line &l2) {
      return isParallel(l1, l2) ? INF : 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;
      return this->xLeft > l2.val;
    }
  };
  bool isMax;
  set<Line> hull;
  bool hasPrev(set<Line>::iterator it) { return it != hull.begin(); }
  bool hasNext(set<Line>::iterator it) {
    return it != hull.end() && next(it) != hull.end();
  }
  bool irrelevant(const Line &l1, const Line &l2, const Line &l3) {
    return llersectX(l1, l3) <= llersectX(l1, l2);
  }
  bool irrelevant(set<Line>::iterator it) {
    return hasPrev(it) && hasNext(it) &&
           ((isMax && irrelevant(*prev(it), *it, *next(it))) ||
            (!isMax && irrelevant(*next(it), *it, *prev(it))));
  }
  set<Line>::iterator updateLeftBorder(set<Line>::iterator it) {
    if (isMax && !hasPrev(it) || !isMax && !hasNext(it)) return it;
    double val = llersectX(*it, isMax ? (*prev(it)) : (*next(it)));
    Line temp(*it);
    it = hull.erase(it);
    temp.xLeft = val;
    it = hull.insert(it, temp);
    return it;
  }
  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() && isParallel(*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(prev(it))) hull.erase(prev(it));
    while (hasNext(it) && irrelevant(next(it))) hull.erase(next(it));
    it = updateLeftBorder(it);
    if (hasPrev(it)) updateLeftBorder(prev(it));
    if (hasNext(it)) updateLeftBorder(next(it));
  }
  long long getBest(long long x) {
    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);
  }
};
vector<vector<long long> > arr(200001);
long long subtree[200001];
long long a[200001];
long long b[200001];
long long ans[200001];
void dfspre(long long u, long long par) {
  subtree[u] = 1;
  for (auto v : arr[u]) {
    if (v != par) dfspre(v, u), subtree[u] += subtree[v];
  }
}
void dfs(long long u, long long par, ConvexHullDynamic &dp) {
  bool leaf = true;
  long long mx = -1;
  long long biggy = -1;
  for (auto v : arr[u]) {
    if (v != par and subtree[v] > mx) mx = subtree[v], leaf = false, biggy = v;
  }
  if (biggy != -1) {
    dfs(biggy, u, dp);
  }
  for (auto v : arr[u]) {
    if (v != par and v != biggy) {
      ConvexHullDynamic temp(0);
      dfs(v, u, temp);
      for (auto v : temp.hull) dp.addLine(v.a, v.b);
    }
  }
  if (!leaf) ans[u] = dp.getBest(a[u]);
  dp.addLine(b[u], ans[u]);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long i;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> b[i];
  for (i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    arr[u].push_back(v);
    arr[v].push_back(u);
  }
  dfspre(1, 0);
  ConvexHullDynamic dp(0);
  dfs(1, 0, dp);
  for (i = 1; i <= n; i++) cout << ans[i] << " ";
}

### Prompt

In Cpp, your task is to solve the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y / 2, x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long sum[200005];
struct ConvexHullDynamic {
  static const long long INF = 1e18;
  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(-INF), type(Type::line), val(0) {}
    long long valueAt(long long x) const { return a * x + b; }
    friend bool isParallel(const Line &l1, const Line &l2) {
      return l1.a == l2.a;
    }
    friend double llersectX(const Line &l1, const Line &l2) {
      return isParallel(l1, l2) ? INF : 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;
      return this->xLeft > l2.val;
    }
  };
  bool isMax;
  set<Line> hull;
  bool hasPrev(set<Line>::iterator it) { return it != hull.begin(); }
  bool hasNext(set<Line>::iterator it) {
    return it != hull.end() && next(it) != hull.end();
  }
  bool irrelevant(const Line &l1, const Line &l2, const Line &l3) {
    return llersectX(l1, l3) <= llersectX(l1, l2);
  }
  bool irrelevant(set<Line>::iterator it) {
    return hasPrev(it) && hasNext(it) &&
           ((isMax && irrelevant(*prev(it), *it, *next(it))) ||
            (!isMax && irrelevant(*next(it), *it, *prev(it))));
  }
  set<Line>::iterator updateLeftBorder(set<Line>::iterator it) {
    if (isMax && !hasPrev(it) || !isMax && !hasNext(it)) return it;
    double val = llersectX(*it, isMax ? (*prev(it)) : (*next(it)));
    Line temp(*it);
    it = hull.erase(it);
    temp.xLeft = val;
    it = hull.insert(it, temp);
    return it;
  }
  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() && isParallel(*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(prev(it))) hull.erase(prev(it));
    while (hasNext(it) && irrelevant(next(it))) hull.erase(next(it));
    it = updateLeftBorder(it);
    if (hasPrev(it)) updateLeftBorder(prev(it));
    if (hasNext(it)) updateLeftBorder(next(it));
  }
  long long getBest(long long x) {
    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);
  }
};
vector<vector<long long> > arr(200001);
long long subtree[200001];
long long a[200001];
long long b[200001];
long long ans[200001];
void dfspre(long long u, long long par) {
  subtree[u] = 1;
  for (auto v : arr[u]) {
    if (v != par) dfspre(v, u), subtree[u] += subtree[v];
  }
}
void dfs(long long u, long long par, ConvexHullDynamic &dp) {
  bool leaf = true;
  long long mx = -1;
  long long biggy = -1;
  for (auto v : arr[u]) {
    if (v != par and subtree[v] > mx) mx = subtree[v], leaf = false, biggy = v;
  }
  if (biggy != -1) {
    dfs(biggy, u, dp);
  }
  for (auto v : arr[u]) {
    if (v != par and v != biggy) {
      ConvexHullDynamic temp(0);
      dfs(v, u, temp);
      for (auto v : temp.hull) dp.addLine(v.a, v.b);
    }
  }
  if (!leaf) ans[u] = dp.getBest(a[u]);
  dp.addLine(b[u], ans[u]);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long i;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> b[i];
  for (i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    arr[u].push_back(v);
    arr[v].push_back(u);
  }
  dfspre(1, 0);
  ConvexHullDynamic dp(0);
  dfs(1, 0, dp);
  for (i = 1; i <= n; i++) cout << ans[i] << " ";
}

```