Testing Round 8
A
IQ Test
Codeforces
1800
原题
←B →
翻译中…

Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.

翻译中…

Arithmetic progression is a sequence $*a*_{1}$, $*a*_{1} + *d*$, $*a*_{1} + 2*d*$, $...$, $*a*_{1} + (*n* - 1)*d*$, where $*a*_{1}$ and $*d*$ are any numbers.

翻译中…

Geometric progression is a sequence $*b*_{1}$, $*b*_{2} = *b*_{1}*q*$, $...$, $*b*_{*n*} = *b*_{*n* - 1}*q*$, where $*b*_{1} ≠ 0$, $*q* ≠ 0$, $*q* ≠ 1$.

翻译中…

Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.

翻译中…

Input

翻译中…

The first line contains exactly four integer numbers between 1 and 1000, inclusively.

翻译中…

Output

翻译中…

Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element.

翻译中…

Print 42 if the given sequence is not an arithmetic or geometric progression.

翻译中…

Note

翻译中…

This problem contains very weak pretests!

翻译中…

样例

Input #1
836 624 412 200
Output #1
-12
InputCopy OutputCopy
Input #2
1 334 667 1000
Output #2
1333
InputCopy OutputCopy
题目信息
题号
328A
所属比赛
时间限制
1 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。