6026: 智商测试

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

A. 智商测试
每次测试的时间限制
1 秒
每个测试的内存限制
256 兆字节
输入
标准输入
输出
标准输出
Petya正在准备智商测试,他注意到有很多问题,例如:给你一个序列,找到下一个数字。现在,Petya只能解决算术或几何级数的问题。
算术级数是一个序列 a 1、a 1+d、a 1+2 d、...a1+(n-1d,其中 1 和 d 是任何数字。
几何级数是一个序列 b 1, b 2=b 1 q, ..., b n=bn-1 q,其中 b1≠0, q≠0, q≠1
帮助Petya并编写一个程序来确定给定的序列是算术还是几何。它也应该找到下一个数字。如果序列既不是算术也不是几何的,打印42(他认为不可能找到更好的答案)。如果级数的下一个元素不是整数,您还应该打印 42。所以答案总是整数。

输入
第一行正好包含 1 到 1000 之间的四个整数(包括 <> 和 <>)。
输出
打印所需的数字。如果给定的序列是算术级数,则打印下一个级数元素。同样,如果给定序列是几何级数,则打印下一个级数元素。
如果给定序列不是算术或几何级数,则打印 42。

例子
输入
836 624 412 200
输出
-12
输入
1 334 667 1000
输出
1333
注意
此问题包含非常弱的预测试!
A. IQ Test
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 a1, a1+d, a1+2d, ..., a1+(n-1)d, where a1 and d are any numbers.
Geometric progression is a sequence b1, b2=b1q, ..., bn=bn-1q, where b1≠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.

Examples
Input
836 624 412 200
Output
-12
Input
1 334 667 1000
Output
1333
Note
This problem contains very weak pretests!

输入样例 复制


输出样例 复制