Petya is preparing for an IQ test and has noticed many problems asking to find the next number in a given sequence. He can only solve problems that involve either arithmetic or geometric progressions. Your task is to help Petya determine if a given sequence is arithmetic or geometric, and to find the next number in the progression. If the sequence is neither or if the next element is not an integer, you should print 42.
Definitions
Arithmetic Progression: A sequence of the form:
[
a_1, a_1 + d, a_1 + 2d, \ldots, a_1 + (n - 1)d
]
where ( a_1 ) is the first term and ( d ) is the common difference.
Geometric Progression: A sequence of the form:
[
b_1, b_1 \cdot q, b_1 \cdot q^2, \ldots, b_1 \cdot q^{n-1}
]
where ( b_1 \neq 0 ), ( q \neq 0 ), and ( q \neq 1 ).
Input Format
The first line contains exactly four integer numbers between 1 and 1000 (inclusive).
Output Format
If the given sequence forms an arithmetic progression, print the next element of that progression.
If the sequence forms a geometric progression, print the next element of that progression.
If the sequence is neither, or if the next element is not an integer, print 42.
Examples
Example 1
Input:
text
836 624 412 200
Output:
text
-12
Example 2
Input:
text
1 334 667 1000
Output:
text
1333
Note
This problem contains very weak pretests, so be sure to test your implementation thoroughly.
Implementation
You should implement the solution in the app/ directory.
Important: place your implementation at /app/solution.py so the verifier can run it.