Under construction

Still being built. Things may change

Workday Routine

Time limit2sMemory limit1024 MB

Summary
Find an integer first height and a common step so that the arithmetic progression has the smallest total absolute change from the given column heights.
Level

Medium7 of 10

Topics
Binary search, Sorting, Math
Solved
No attempts yet

Statement

Foreman Pavel leads a crew building a concert hall to a new design by foreign architects. The main feature is a colonnade at the main entrance with nn columns. Unlike classical designs, each column has its own height, not equal to the height of the roof above the entrance. In the current plan, the heights are a1,a2,…,ana_1, a_2, \ldots, a_n meters relative to the roof, from left to right. For example, height 10 means the column sticks out ten meters above the roof, and height -5 means there is a five meter gap between the top of the column and the roof.

Three days before the handover and opening, the architects arrived at the site and changed the design. The new requirement follows recent European fashion: the difference between any two adjacent columns must be the same. That is, for any integers ii and jj from 1 to n−1n - 1, ai+1−ai=aj+1−aja_{i+1} - a_i = a_{j+1} - a_j must hold. The exact height of each column does not matter. For technical reasons, each column height must be an integer number of meters relative to the roof.

Changing a column's height by xx meters, up or down, costs xx burles. Pavel asks you to choose a new height for each column so that the requirement holds and the total cost of the changes is as small as possible. Help him, or nobody will ever invite him to build foreign-designed buildings again.

Input

The first line contains an integer nn (2≤n≤3 000 0002 \leq n \leq 3\,000\,000), the number of columns in front of the building.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−109≤ai≤109-10^9 \leq a_i \leq 10^9), the current column heights.

Output

Print two integers: the height of the first column and the difference between adjacent columns in an optimal plan.

The absolute values of both printed numbers must not exceed 101610^{16}. It is guaranteed that an optimal answer satisfying this exists.

Hint

In the first test, no changes are needed, since there are only two columns and they satisfy the requirement automatically.

In the second test, the optimal heights are 3, 7, 11, 15, 19, and the total cost is ∣3−3∣+∣7−8∣+∣11−10∣+∣15−13∣+∣19−20∣=5|3 - 3| + |7 - 8| + |11 - 10| + |15 - 13| + |19 - 20| = 5.

Examples2

  1. Example 1

    Input
    2
    3 -3
    
    Expected output
    3 -6
    
  2. Example 2

    Input
    5
    3 8 10 13 20
    
    Expected output
    3 4