시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB322967730.078%

문제

Your younger sister is studying for an upcoming standardized test in mathematics. She needs practice with the common style of problem in which the student is asked to fill in the missing value in a sequence of numbers.

The vast majority of these problems feature either arithmetic sequences (where each number in the sequence is formed by adding an integer constant to the prior number) or geometric sequences (where each number in the sequence is formed by multiplying the prior number by an integer constant).

Write a program that will help your sister practice on this style of problem by allowing her to check her answers on sample problems.

입력

Input will consist of one or more datasets.

Each dataset will be a single line containing 4 integers defining a sequence. One of these will be -1, denoting the missing value. The remainder will be positive integers in the range 1..10,000, inclusive. Other than the -1 placeholder value, the values will be in non-decreasing order.

End of input will be signaled by a line containing four -1 values.

출력

For each dataset, print one line of output.

If an integer in the range 1..10,000 inclusive exists that can be filled in to the missing value position to create an arithmetic or geometric sequence, print that missing value.

If there is no such positive integer, print -1.

예제 입력 1

1 2 -1 4
2 4 8 -1
7 8 -1 21
5 -1 11 14
-1 2 4 6
-1 -1 -1 -1

예제 출력 1

3
16
-1
8
-1