This page is still under construction.

Parts of this page are still being built. What you see may change.

Ostap and chairs

Time limit1sMemory limit256 MB

Summary
Given N x-coordinates and N y-coordinates, find real k and b minimizing the sum of |x_i - (k*y_i + b)|.
Level

Hard8 of 10

Topics
Geometry, Binary search, Greedy, Math
Solved
No attempts yet

Problem

There is an emotional moment in the computer game called <>, when each Ostap, from a crowd of tiny Ostaps, runs to his own chair. The graphics of the event has been drawn already: the first image is of Ostaps (with predefined coordinates xix_i), and the second image is of the chairs (their coordinates yiy_i are also known).

Before you start a game, you cannot move Ostaps or chairs, but you can change the scale of the second picture using a linear transformation yi→k∗yi+by_i \rightarrow k*y_i+b. After that, the first Ostap runs to the first chair, then the second Ostap runs to the second chair, etc., and the total elapsed time is summed up. The player's task is to make this time as short as possible, i.e. minimize the total summarized distance.

Your task is to find the minimum possible value: ∑i=1N∣xi−(kyi+b)∣\sum_{i=1}^{N} |x_i-(k y_i+b)|

Input

The first line of the input file contains a single integer NN, the number of Ostaps and chairs (2≤N≤3002 \le N \le 300). Each of the following two lines contains NN integers: the second line of the file contains xix_i, the coordinates of Ostaps, the third line contains yiy_i, the coordinates of chairs (1≤i≤N1 \le i \le N, ∣xi∣,∣yi∣≤103|x_i|, |y_i| \le 10^3). All xix_i are different, all yiy_i are different.

Output

In your answer, print three real numbers: DD, the minimum possible value of the total distance, and KK and BB, coefficients with which such distance is achievable.

The relative or absolute deviation of the distance DD from the optimal must not exceed 10−910^{-9}. The total distance calculated using the coefficients KK and BB must match DD with the same precision.

Examples2

  1. Example 1

    Input
    3
    0 3 -5
    4 1 -2 
    
    Expected output
    5.5 0.8333333333 -3.3333333333
    
  2. Example 2

    Input
    2
    -7 12
    -7 12
    
    Expected output
    0 1 0