402230: GYM100703 M It's complicated

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

M. It's complicatedtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Dragon was drinking tea on a balcony and admiring a very beautiful sunset. Two outgoing silhouettes were still descrying in the rays of a setting sun. Of course, Princess promised to visit Dragon sometime, but what could be a reason for her to come back in the Castles Valley?..

Dragon decided to cook biscuits according to a recipe that was told him by Princess. So he needs to check if he has sufficient quantity of ingredients for it. Of course, he has a few of ginger, cinnamon, cloves and cardamon... But, comparing to making tea, he needs some more ingredients to bake biscuits.

Dragon revised all his ingredients, and knew how many units of each ingredient he had.

It was written in the recipe how many units of each ingredient are required to bake a biscuit. Certainly, Dragon wanted to bake an integer number of biscuits.

Dragon realized that he will expend some ingredients completely, while some other ingredients will remain. He believed he must purchase some extra ingredients, so that all ingredients will be completely expended after baking some number of biscuits.

Dragon knew the cost for a unit of each ingredient. Your task is to figure out minimum amount of money which is needed to spend to fulfil the condition above.

Input

The first line contains integer n (1 ≤ n ≤ 10) — the number of ingredients.

The second line contains n integers q1, q2, ..., qn (1 ≤ qj ≤ 100,  j = 1, 2, ..., n), qj — the number of units of jth ingredient, which Dragon has.

The third line contains n integers c1, c2, ..., cn (1 ≤ cj ≤ 10,  j = 1, 2, ..., n), cj — the number of units of jth ingredient which it needs for cooking a biscuit.

The fourth line contains n integers p1, p2, ..., pn (1 ≤ pj ≤ 100,  j = 1, 2, ..., n), pj — cost of a unit of jth ingredient.

Output

Print the only integer — minimum amount of money to spend.

ExamplesInput
3
15 8 10
2 3 5
12 1 4
Output
148

加入题单

算法标签: