Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

F. Escape Through Leaf

time limit per test

3 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou 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 *a* _{ i} and *b* _{ i}.

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 *a* _{ x} and *b* _{ y}. 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* ≤ 10^{5}) — the number of nodes in the tree.

The second line contains *n* space-separated integers *a* _{1}, *a* _{2}, ..., *a* _{ n}( - 10^{5} ≤ *a* _{ i} ≤ 10^{5}).

The third line contains *n* space-separated integers *b* _{1}, *b* _{2}, ..., *b* _{ n}( - 10^{5} ≤ *b* _{ i} ≤ 10^{5}).

Next *n* - 1 lines contains two space-separated integers *u* _{ i} and *v* _{ i} (1 ≤ *u* _{ i}, *v* _{ i} ≤ *n*) describing edge between nodes *u* _{ i} and *v* _{ i} 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 *a* _{2} × *b* _{3} = 50. For node 1, jump directly to node 3 with cost *a* _{1} × *b* _{3} = 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 *a* _{2} × *b* _{4} = 100. For node 1, jump to node 2 with cost *a* _{1} × *b* _{2} = - 400 followed by a jump from 2 to 4 with cost *a* _{2} × *b* _{4} = 100.

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Aug/07/2020 12:24:12 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|