Time limit
2s
Memory limit
128 MB
An arithmetic sequence with an integer common difference can be described by two integers P and Q. P is the first term, and Q is the value added to the previous term to get the next one. For example, if P=1 and Q=2, the sequence is 1, 3, 5, 7, ... .
A geometric sequence with an integer common ratio can also be described by two integers P and Q. P is the first term, and Q is the value multiplied by the previous term to get the next one. For example, if P=3 and Q=2, the sequence is 3, 6, 12, ... .
Teddy decides every day whether a given sequence is arithmetic or geometric, then finds its next term.
The given sequence follows one of the two rules above. Write a program that finds the rule and prints the next number.
The first line contains the length N of the sequence. Each of the next N lines contains one term of the sequence in order.
The given sequence is either arithmetic or geometric. N is always between 3 and 50 inclusive, and every input number is a natural number no greater than 10^6.
Print the next term of the sequence on the first line. This number is a natural number no greater than 2,000,000,000.