#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater() {}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
long long p = 1e9 + 7;
const int N = 2e5 + 5;
const long long INF = 2e18;
long long eval(long long m, long long c, long long x) {
  if (m == -INF) return -INF;
  return m * x + c;
}
struct node {
  node *a[2];
  long long m, c;
};
long long n;
long long LO = -1e5, HI = 1e5;
node *getnode() {
  node *tree = new node();
  tree->m = -INF;
  tree->c = -INF;
  return tree;
}
void insert(node *tree, long long l, long long r, long long m, long long c) {
  long long mid = (l + r) / 2;
  bool lef = eval(m, c, l) > eval(tree->m, tree->c, l);
  bool mi = eval(m, c, mid) > eval(tree->m, tree->c, mid);
  if (mi) {
    swap(m, tree->m);
    swap(c, tree->c);
  }
  if (r == l) {
    return;
  }
  if (lef != mi) {
    if (tree->a[0] == NULL) {
      tree->a[0] = getnode();
      tree->a[0]->m = m;
      tree->a[0]->c = c;
    }
    insert(tree->a[0], l, mid, m, c);
  } else {
    if (mid + 1 > r) return;
    if (tree->a[1] == NULL) {
      tree->a[1] = getnode();
      tree->a[1]->m = m;
      tree->a[1]->c = c;
    }
    insert(tree->a[1], mid + 1, r, m, c);
  }
}
long long find(node *tree, long long l, long long r, long long x) {
  if (tree == NULL) {
    return -INF;
  }
  long long val = eval(tree->m, tree->c, x);
  if (r == l) {
    return val;
  }
  long long mid = (l + r) / 2;
  if (x < mid) {
    return max(val, find(tree->a[0], l, mid, x));
  }
  if (mid + 1 > r) return -INF;
  return max(val, find(tree->a[1], mid + 1, r, x));
}
long long a[N];
long long b[N];
long long ans[N];
long long sub[N];
vector<int> g[N];
node *tree;
void dfs1(int i, int p) {
  sub[i] = 1;
  for (auto j : g[i]) {
    if (j != p) {
      dfs1(j, i);
      sub[i] += sub[j];
    }
  }
}
void add(int i, int p) {
  insert(tree, LO, HI, -b[i], -ans[i]);
  for (auto j : g[i]) {
    if (j != p) {
      add(j, i);
    }
  }
}
void dfs(int i, int p, bool keep) {
  int mx = 0, big = -1;
  for (auto j : g[i]) {
    if (j != p) {
      if (mx < sub[j]) {
        mx = sub[j];
        big = j;
      }
    }
  }
  for (auto j : g[i]) {
    if (j != p && j != big) {
      dfs(j, i, 0);
    }
  }
  if (big != -1) {
    dfs(big, i, 1);
  }
  for (auto j : g[i]) {
    if (j != p && j != big) {
      add(j, i);
    }
  }
  ans[i] = (-find(tree, LO, HI, a[i]));
  if (big == -1) {
    ans[i] = 0;
  }
  insert(tree, LO, HI, -b[i], -ans[i]);
  if (!keep) {
    delete tree;
    tree = getnode();
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  ;
  int T = 1;
  while (T--) {
    cin >> n;
    for (int i = 0; i < (n); ++i) cin >> a[i + 1];
    for (int i = 0; i < (n); ++i) cin >> b[i + 1];
    for (int i = 0; i < (n - 1); ++i) {
      long long u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    tree = getnode();
    dfs1(1, -1);
    dfs(1, -1, 1);
    for (int i = 0; i < (n); ++i) {
      cout << ans[i + 1] << " ";
    }
  }
  timecalculater();
  return 0;
}

### Prompt

Please formulate a cpp solution to 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 auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater() {}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
long long p = 1e9 + 7;
const int N = 2e5 + 5;
const long long INF = 2e18;
long long eval(long long m, long long c, long long x) {
  if (m == -INF) return -INF;
  return m * x + c;
}
struct node {
  node *a[2];
  long long m, c;
};
long long n;
long long LO = -1e5, HI = 1e5;
node *getnode() {
  node *tree = new node();
  tree->m = -INF;
  tree->c = -INF;
  return tree;
}
void insert(node *tree, long long l, long long r, long long m, long long c) {
  long long mid = (l + r) / 2;
  bool lef = eval(m, c, l) > eval(tree->m, tree->c, l);
  bool mi = eval(m, c, mid) > eval(tree->m, tree->c, mid);
  if (mi) {
    swap(m, tree->m);
    swap(c, tree->c);
  }
  if (r == l) {
    return;
  }
  if (lef != mi) {
    if (tree->a[0] == NULL) {
      tree->a[0] = getnode();
      tree->a[0]->m = m;
      tree->a[0]->c = c;
    }
    insert(tree->a[0], l, mid, m, c);
  } else {
    if (mid + 1 > r) return;
    if (tree->a[1] == NULL) {
      tree->a[1] = getnode();
      tree->a[1]->m = m;
      tree->a[1]->c = c;
    }
    insert(tree->a[1], mid + 1, r, m, c);
  }
}
long long find(node *tree, long long l, long long r, long long x) {
  if (tree == NULL) {
    return -INF;
  }
  long long val = eval(tree->m, tree->c, x);
  if (r == l) {
    return val;
  }
  long long mid = (l + r) / 2;
  if (x < mid) {
    return max(val, find(tree->a[0], l, mid, x));
  }
  if (mid + 1 > r) return -INF;
  return max(val, find(tree->a[1], mid + 1, r, x));
}
long long a[N];
long long b[N];
long long ans[N];
long long sub[N];
vector<int> g[N];
node *tree;
void dfs1(int i, int p) {
  sub[i] = 1;
  for (auto j : g[i]) {
    if (j != p) {
      dfs1(j, i);
      sub[i] += sub[j];
    }
  }
}
void add(int i, int p) {
  insert(tree, LO, HI, -b[i], -ans[i]);
  for (auto j : g[i]) {
    if (j != p) {
      add(j, i);
    }
  }
}
void dfs(int i, int p, bool keep) {
  int mx = 0, big = -1;
  for (auto j : g[i]) {
    if (j != p) {
      if (mx < sub[j]) {
        mx = sub[j];
        big = j;
      }
    }
  }
  for (auto j : g[i]) {
    if (j != p && j != big) {
      dfs(j, i, 0);
    }
  }
  if (big != -1) {
    dfs(big, i, 1);
  }
  for (auto j : g[i]) {
    if (j != p && j != big) {
      add(j, i);
    }
  }
  ans[i] = (-find(tree, LO, HI, a[i]));
  if (big == -1) {
    ans[i] = 0;
  }
  insert(tree, LO, HI, -b[i], -ans[i]);
  if (!keep) {
    delete tree;
    tree = getnode();
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  ;
  int T = 1;
  while (T--) {
    cin >> n;
    for (int i = 0; i < (n); ++i) cin >> a[i + 1];
    for (int i = 0; i < (n); ++i) cin >> b[i + 1];
    for (int i = 0; i < (n - 1); ++i) {
      long long u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    tree = getnode();
    dfs1(1, -1);
    dfs(1, -1, 1);
    for (int i = 0; i < (n); ++i) {
      cout << ans[i + 1] << " ";
    }
  }
  timecalculater();
  return 0;
}

```