The Calculus of Ada

Given n values of a polynomial at evenly spaced inputs, find the degree of the minimal-degree polynomial and its value at the next input using finite differences.

Easy3MathImplementationArraySimulationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Augusta Ada King-Noel, Countess of Lovelace, is best known for the programs she wrote for Charles Babbage's Analytical Engine. She also described how the method of finite differences solves problems about number sequences and series, and Babbage's Difference Engine implemented those techniques.

The method works like this. Take the difference between each pair of consecutive values in a numeric sequence. The sequence you get is related to the derivative of the function behind the original sequence. When the original sequence comes from a first-degree polynomial (a linear function), the first differences are all the same value, a constant. When it comes from a second-degree polynomial, the first differences change linearly, so the differences of that new sequence, the second differences, are constant. The same rule continues for higher degrees: for a polynomial of degree nn, the nn-th row of differences is constant.

For example, the first-degree polynomial 3x+33x + 3 evaluated at x=0,1,2,3,4x = 0, 1, 2, 3, 4 gives the table below.

rowvalues
sequence3, 6, 9, 12, 15
first differences3, 3, 3, 3

The polynomial x2x^2 evaluated at x=3,5,7,9x = 3, 5, 7, 9 gives this table.

rowvalues
sequence9, 25, 49, 81
first differences16, 24, 32
second differences8, 8

Once a row of differences is constant, you can extend the table one column to the right and read off the value that a minimal-degree polynomial takes at the next regularly spaced input.

You are given the values of a polynomial at nn regularly spaced inputs. Report the degree of a minimal-degree polynomial that produces those values, together with the value that same polynomial takes at the next regularly spaced input.

Input

The input contains an integer nn (2n102 \le n \le 10), the number of polynomial values given, followed by nn integers v1,v2,,vnv_1, v_2, \dots, v_n, the values of a polynomial evaluated at nn regularly spaced inputs. Every vjv_j satisfies 2000000vj2000000-2\,000\,000 \le v_j \le 2\,000\,000, and at least two of the given values differ from each other. The numbers are separated by whitespace, so they may sit on one line or on several.

Output

Print two integers dd and vn+1v_{n+1} separated by one space. The value dd is the degree of a minimal-degree polynomial that produces the given sequence, and vn+1v_{n+1} is the value of that polynomial at the next regularly spaced input. Since at least two of the given values differ, dd is between 1 and n1n - 1, and both answers are unique.