Limits 1s, 512 MB

Chef Jami had recently started home delivery service for pizzas. Jami has only a single delivery boy that delivers the order by riding his bicycle. Today Chef Jami received NN pizza order, the house of the person that ordered the ii-th pizza needs AiA_i unit time to prepare and the order is BiB_i km away from the restaurant. The delivery boy cannot deliver more than one order at a time and takes 1 unit time per km. Therefore, after delivering an order, he must return back to the restaurant to take the next order. It takes the delivery man no time to get back to the restaurant and the Chef can continue cooking without waiting for the delivery man to come for the next order.

The delivery boy is a lazy person and does not want to spend much time in the delivery process, so he wants your help in prioritizing the orders so that he can deliver all orders in least amount of time.

Input

First line contain the number of orders NN (1N5001 ≤ N ≤ 500).

Second line contains NN space separated integers AiA_i (1Ai10001 ≤ A_i ≤ 1000) - the packing time of every pizza by Chef Jami and the third line contains NN space separated integers BiB_i (1Bi10001 ≤ B_i ≤ 1000) - the distance of the house from the restaurant.

Output

Print the least amount of time to deliver all the orders.

Samples

InputOutput
4
1 1 30 5
5 30 5 10
51
InputOutput
6
11 9 16 19 15 17
11 23 9 7 11 6
93

Submit

Login to submit.

Statistics

28% Solution Ratio
khatribiruEarliest, Jun '17
khatribiruFastest, 0.0s
khatribiruLightest, 131 kB
hbb_fanShortest, 650B
Toph uses cookies. By continuing you agree to our Cookie Policy.