Under construction

Still being built. Things may change

Let's fly!

Interview

Time limit2sMemory limit1024 MB

Summary
Given altitudes h_i and weights a_i, find the single altitude minimizing the sum of |h_i - x| * a_i and print that altitude with the minimum cost.
Level

Medium4 of 10

Topics
Sorting, Prefix sum, Greedy
Solved
No attempts yet

Problem

Malysh and Karlson decided to go out for a walk. More precisely, a flight. Karlson, being a responsible person, drew up a flight plan and showed it to Malysh. The plan works like this: for every moment in time ii, Karlson assigned an altitude hih_i at which he will be flying at that moment.

But after yet another round of eating too much jam, Malysh did not like the altitude changes in Karlson's plan. He decided to adjust the plan slightly so that the flight stays at one altitude the whole time. Karlson, in turn, said he would be very upset if Malysh changed the plan a lot. Precisely: if Malysh changes the altitude at moment ii by one meter, Karlson's displeasure grows by aia_i, where aia_i is how much Karlson wants to fly at altitude hih_i at moment ii.

So Malysh can change the altitude at any point by any amount, but replacing hih_i with hi±cih_i \pm c_i at point ii increases Karlson's displeasure by ci⋅aic_i \cdot a_i. Help Malysh fix the plan by replacing all altitudes with one single value, so that Karlson's displeasure is minimal.

Input

The first line contains one integer nn (1≤n≤1051 \le n \le 10^5), the duration of the flight. The second line contains nn integers hih_i (1≤hi≤1061 \le h_i \le 10^6), the altitude at moment ii. The third line contains nn integers aia_i (1≤ai≤1061 \le a_i \le 10^6), Karlson's displeasure coefficient at moment ii.

Output

Print two numbers: the final altitude of the flight and the total displeasure of Karlson. If several altitudes are possible, print the smallest one.

Hint

If there are several answers, print the lexicographically smallest pair.

Examples3

  1. Example 1

    Input
    6
    6 7 8 8 7 7
    10 6 3 1 1 4
    
    Expected output
    7 14
    
  2. Example 2

    Input
    5
    7 5 7 9 8
    10 8 7 8 5
    
    Expected output
    7 37
    
  3. Example 3

    Input
    5
    8 5 10 9 7
    2 5 4 8 4
    
    Expected output
    9 34