301733: CF328A. IQ Test

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

IQ Test

题意翻译

给定一个数列的前四个数 $a,b,c,d (1\le a,b,c,d \le 1000)$,如果这是个等差数列或者等比数列且下一项为整数,输出下一项。否则,输出 `42`。

题目描述

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}+2d $ , $ ... $ , $ 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.

输入输出格式

输入格式


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

输出格式


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.

输入输出样例

输入样例 #1

836 624 412 200

输出样例 #1

-12

输入样例 #2

1 334 667 1000

输出样例 #2

1333

说明

This problem contains very weak pretests!

Input

题意翻译

给定一个数列的前四个数 $a,b,c,d (1\le a,b,c,d \le 1000)$,如果这是个等差数列或者等比数列且下一项为整数,输出下一项。否则,输出 `42`。

加入题单

上一题 下一题 算法标签: