# Ternary search

# Building Construction

Given **n** buildings of height `h`

, _{1}`h`

, _{2}`h`

, ..., _{3}`h`

, the objective is to make every building has equal height. This can be done by removing bricks from a building or adding some bricks to a building. Removing a brick or adding a brick is done at certain cost which will be given along with the heights of the buildings. Find the minimal cost at which you can make the buildings look beautiful by reconstructing the buildings such that the _{n}**n** buildings satisfy `h`

= _{1}`h`

= _{2}`h`

= ... = _{3}`h`

= _{n}**k** (**k** can be any number).

For convenience, all buildings are considered to be vertical piles of bricks, which are of same dimensions.

#### Input

The first line contains number of buildings **n** (**n** ≤ `10`

). The second line contains ^{5}**n** integers which denotes the heights of the buildings `h`

, _{1}`h`

, _{2}`h`

, ..., _{3}`h`

(_{n}**0** ≤ `h`

≤ _{i}**10000**). The third line contains **n** integers `c`

, _{1}`c`

, _{2}`c`

, ..., _{3}`c`

(_{n}**0** ≤ `c`

≤ _{i}**10000**) which denotes the cost of adding or removing one unit of brick from the corresponding building.

#### Output

Print the minimal cost to make all the buildings look beautiful.

4 2 3 1 4 10 20 30 40

110

3 1 2 3 10 100 1000

120