Pero the Baker

Time limit1sMemory limit64 MB

Summary
Assign loaves of P sizes to P ovens so all finish as fast as possible; each round bakes everything in an oven and takes five minutes.
Level

Medium6 of 10

Topics
Greedy, Binary search, Implementation
Solved
No attempts yet

Problem

Pero the baker has taken over a bakery, and he bakes bread in his PP ovens.

The loaves come in several sizes, and so do the ovens. The ovens are numbered 1,2,…,P1, 2, \dots, P, where oven 1 is the largest, oven 2 is the second largest, and each next oven is smaller. The largest loaves fit only in oven 1, the next size down fits in ovens 1 and 2, and the smallest loaves fit in every oven, including oven PP.

Several loaves can bake in one oven at the same time. Oven qq holds at most AqA_q loaves at once, no matter what their sizes are. Each loaf still has to be small enough to fit in that oven. All ovens run at the same time.

Pero has to bake T1T_1 loaves that fit only in oven 1 (the largest loaves), T2T_2 loaves that fit in ovens 1 and 2, and so on down to TPT_P loaves that fit in every oven.

An oven takes five minutes to bake everything inside it. Find the smallest amount of time Pero needs to bake all of the loaves.

Input

The first line contains the number of ovens PP (P≤100000P \le 100000). The loaves come in PP sizes as well.

The second line contains PP natural numbers T1,T2,…,TPT_1, T_2, \dots, T_P, each at most 101210^{12}. The number TqT_q is how many loaves can be baked in oven qq or in any larger oven.

The third line contains PP natural numbers A1,A2,…,APA_1, A_2, \dots, A_P, each at most 101210^{12}. The number AqA_q is how many loaves oven qq can bake at once.

Output

Print on the first line the smallest baking time in minutes.

Hint

A single oven with capacity 3 needs three rounds to bake 7 loaves. It bakes 3 loaves in each of the first two rounds and 1 loaf in the last one, so it takes 15 minutes.

Examples3

  1. Example 1

    Input
    1
    7
    3
    
    Expected output
    15
    
  2. Example 2

    Input
    3
    10 3 2
    1 100 100
    
    Expected output
    50
    
  3. Example 3

    Input
    3
    10 18 9
    3 4 2
    
    Expected output
    25