#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18 + 7, offset = 1e5;
struct Line {
  long long a, b;
  Line() {}
  Line(long long _a, long long _b) : a(_a), b(_b) {}
  long long val(long long x) { return a * x + b; }
  bool operator==(Line other) { return (other.a == a && other.b == b); }
};
struct PersistentLiChaoTree {
  vector<Line> st;
  long long n, cnt;
  stack<pair<long long, Line> > changes;
  stack<long long> popcount;
  PersistentLiChaoTree() {}
  PersistentLiChaoTree(long long _n) {
    this->n = _n;
    st.resize(4 * n + 5);
    for (long long i = 0, _n = (st.size()); i < _n; i++) st[i] = Line(oo, oo);
  }
  long long Left(long long x) { return (x << 1); }
  long long Right(long long x) { return (x << 1) + 1; }
  void Assign(long long id, Line b) {
    cnt++;
    changes.push(pair<long long, Line>(id, st[id]));
    st[id] = b;
  }
  void update(long long id, long long L, long long R, Line a) {
    if (L == R) {
      if (st[id] == Line(oo, oo))
        Assign(id, a);
      else if (a.val(L - offset) < st[id].val(L - offset))
        Assign(id, a);
      return;
    }
    if (st[id] == Line(oo, oo)) {
      Assign(id, a);
      return;
    }
    long long mid = (L + R) >> 1;
    bool l = st[id].val(L - offset) < a.val(L - offset),
         r = st[id].val(R - offset) < a.val(R - offset);
    bool m1 = st[id].val(mid - offset) < a.val(mid - offset),
         m2 = st[id].val(mid + 1 - offset) < a.val(mid + 1 - offset);
    if (l && r) return;
    if (!l && !r) {
      Assign(id, a);
      return;
    }
    if (l && m1) {
      update(Right(id), mid + 1, R, a);
      return;
    }
    if (!l && !m1) {
      update(Right(id), mid + 1, R, st[id]);
      Assign(id, a);
      return;
    }
    if (m2 && r) {
      update(Left(id), L, mid, a);
      return;
    }
    if (!m2 && !r) {
      update(Left(id), L, mid, st[id]);
      Assign(id, a);
      return;
    }
  }
  void addLine(Line a) {
    cnt = 0;
    update(1, 1, n, a);
    popcount.push(cnt);
  }
  long long query(long long id, long long L, long long R, long long x) {
    long long ret;
    if (st[id] == Line(oo, oo))
      ret = oo;
    else
      ret = st[id].val(x - offset);
    if (L == R) return ret;
    long long mid = (L + R) >> 1;
    if (x > mid)
      ret = min(ret, query(Right(id), mid + 1, R, x));
    else
      ret = min(ret, query(Left(id), L, mid, x));
    return ret;
  }
  long long query(long long x) { return query(1, 1, n, x + offset); }
  void pop() {
    if (popcount.empty()) return;
    long long tmp = popcount.top();
    popcount.pop();
    while (tmp && !changes.empty()) {
      pair<long long, Line> c = changes.top();
      changes.pop();
      st[c.first] = c.second;
      tmp--;
    }
  }
  void clear() {
    while (!popcount.empty()) pop();
  }
} IT;
const long long N = 1e5 + 5;
long long dp[N], a[N], b[N], n, subSize[N];
vector<long long> adj[N];
void prepare(long long u, long long pre) {
  subSize[u] = 1;
  for (long long v : adj[u]) {
    if (v == pre) continue;
    prepare(v, u);
    subSize[u] += subSize[v];
  }
}
void trv(long long u, long long pre) {
  IT.addLine(Line(b[u], dp[u]));
  for (long long v : adj[u])
    if (v != pre) trv(v, u);
}
void dfs(long long u, long long pre, bool keep) {
  long long maxSize = 0, bigChild = -1;
  for (long long v : adj[u]) {
    if (v == pre) continue;
    if (subSize[v] > maxSize) {
      maxSize = subSize[v];
      bigChild = v;
    }
  }
  for (long long v : adj[u])
    if (v != pre && v != bigChild) dfs(v, u, 0);
  if (bigChild != -1) dfs(bigChild, u, 1);
  for (long long v : adj[u]) {
    if (v == pre || v == bigChild) continue;
    trv(v, u);
  }
  if (pre == -1 || adj[u].size() > 1) dp[u] = IT.query(a[u]);
  IT.addLine(Line(b[u], dp[u]));
  if (!keep) IT.clear();
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  clock_t tStart = clock();
  cin >> n;
  for (long long i = (1), _b = (n); i <= _b; i++) cin >> a[i];
  for (long long i = (1), _b = (n); i <= _b; i++) cin >> b[i];
  for (long long i = (1), _b = (n - 1); i <= _b; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  IT = PersistentLiChaoTree(2 * N);
  prepare(1, -1);
  dfs(1, -1, 1);
  for (long long i = (1), _b = (n); i <= _b; i++) cout << dp[i] << ' ';
  fprintf(stderr, "Time taken: %.2fs\n",
          (double)(clock() - tStart) / CLOCKS_PER_SEC);
  return 0;
}

### 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;
const long long oo = 1e18 + 7, offset = 1e5;
struct Line {
  long long a, b;
  Line() {}
  Line(long long _a, long long _b) : a(_a), b(_b) {}
  long long val(long long x) { return a * x + b; }
  bool operator==(Line other) { return (other.a == a && other.b == b); }
};
struct PersistentLiChaoTree {
  vector<Line> st;
  long long n, cnt;
  stack<pair<long long, Line> > changes;
  stack<long long> popcount;
  PersistentLiChaoTree() {}
  PersistentLiChaoTree(long long _n) {
    this->n = _n;
    st.resize(4 * n + 5);
    for (long long i = 0, _n = (st.size()); i < _n; i++) st[i] = Line(oo, oo);
  }
  long long Left(long long x) { return (x << 1); }
  long long Right(long long x) { return (x << 1) + 1; }
  void Assign(long long id, Line b) {
    cnt++;
    changes.push(pair<long long, Line>(id, st[id]));
    st[id] = b;
  }
  void update(long long id, long long L, long long R, Line a) {
    if (L == R) {
      if (st[id] == Line(oo, oo))
        Assign(id, a);
      else if (a.val(L - offset) < st[id].val(L - offset))
        Assign(id, a);
      return;
    }
    if (st[id] == Line(oo, oo)) {
      Assign(id, a);
      return;
    }
    long long mid = (L + R) >> 1;
    bool l = st[id].val(L - offset) < a.val(L - offset),
         r = st[id].val(R - offset) < a.val(R - offset);
    bool m1 = st[id].val(mid - offset) < a.val(mid - offset),
         m2 = st[id].val(mid + 1 - offset) < a.val(mid + 1 - offset);
    if (l && r) return;
    if (!l && !r) {
      Assign(id, a);
      return;
    }
    if (l && m1) {
      update(Right(id), mid + 1, R, a);
      return;
    }
    if (!l && !m1) {
      update(Right(id), mid + 1, R, st[id]);
      Assign(id, a);
      return;
    }
    if (m2 && r) {
      update(Left(id), L, mid, a);
      return;
    }
    if (!m2 && !r) {
      update(Left(id), L, mid, st[id]);
      Assign(id, a);
      return;
    }
  }
  void addLine(Line a) {
    cnt = 0;
    update(1, 1, n, a);
    popcount.push(cnt);
  }
  long long query(long long id, long long L, long long R, long long x) {
    long long ret;
    if (st[id] == Line(oo, oo))
      ret = oo;
    else
      ret = st[id].val(x - offset);
    if (L == R) return ret;
    long long mid = (L + R) >> 1;
    if (x > mid)
      ret = min(ret, query(Right(id), mid + 1, R, x));
    else
      ret = min(ret, query(Left(id), L, mid, x));
    return ret;
  }
  long long query(long long x) { return query(1, 1, n, x + offset); }
  void pop() {
    if (popcount.empty()) return;
    long long tmp = popcount.top();
    popcount.pop();
    while (tmp && !changes.empty()) {
      pair<long long, Line> c = changes.top();
      changes.pop();
      st[c.first] = c.second;
      tmp--;
    }
  }
  void clear() {
    while (!popcount.empty()) pop();
  }
} IT;
const long long N = 1e5 + 5;
long long dp[N], a[N], b[N], n, subSize[N];
vector<long long> adj[N];
void prepare(long long u, long long pre) {
  subSize[u] = 1;
  for (long long v : adj[u]) {
    if (v == pre) continue;
    prepare(v, u);
    subSize[u] += subSize[v];
  }
}
void trv(long long u, long long pre) {
  IT.addLine(Line(b[u], dp[u]));
  for (long long v : adj[u])
    if (v != pre) trv(v, u);
}
void dfs(long long u, long long pre, bool keep) {
  long long maxSize = 0, bigChild = -1;
  for (long long v : adj[u]) {
    if (v == pre) continue;
    if (subSize[v] > maxSize) {
      maxSize = subSize[v];
      bigChild = v;
    }
  }
  for (long long v : adj[u])
    if (v != pre && v != bigChild) dfs(v, u, 0);
  if (bigChild != -1) dfs(bigChild, u, 1);
  for (long long v : adj[u]) {
    if (v == pre || v == bigChild) continue;
    trv(v, u);
  }
  if (pre == -1 || adj[u].size() > 1) dp[u] = IT.query(a[u]);
  IT.addLine(Line(b[u], dp[u]));
  if (!keep) IT.clear();
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  clock_t tStart = clock();
  cin >> n;
  for (long long i = (1), _b = (n); i <= _b; i++) cin >> a[i];
  for (long long i = (1), _b = (n); i <= _b; i++) cin >> b[i];
  for (long long i = (1), _b = (n - 1); i <= _b; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  IT = PersistentLiChaoTree(2 * N);
  prepare(1, -1);
  dfs(1, -1, 1);
  for (long long i = (1), _b = (n); i <= _b; i++) cout << dp[i] << ' ';
  fprintf(stderr, "Time taken: %.2fs\n",
          (double)(clock() - tStart) / CLOCKS_PER_SEC);
  return 0;
}

```