Your are given a sequence of integers a1, …, an. Find an arithmetic
progression b1, …, bn for which the
value ∑(ai − bi)2 is minimal. The elements of the progression can be
non-integral.
Input
The first line contains the number n of elements in the sequence (2 ≤ n
≤ 104). In the second line you are given the integers a1, …, an;
their absolute values do not exceed 104.
Output
Output two numbers separated with a space: the first term of the required
arithmetic progression and its difference, with an absolute or relative error
of at most 10−6. It is guaranteed that the answer is unique for all input
data.
Samples
input | output |
---|
4
0 6 10 15
| 0.400 4.900
|
4
-2 -2 -2 -2
| -2 0
|
Problem Author: Alex Samsonov
Problem Source: XII USU Open Personal Contest (March 19, 2011)