#P6352. Find the Missing Number in the Arithmetic Sequence

    ID: 19568 Type: Default 1000ms 256MiB

Find the Missing Number in the Arithmetic Sequence

Find the Missing Number in the Arithmetic Sequence

You originally had four numbers which, when sorted in increasing order, formed an arithmetic progression. However, one number was lost and the remaining three numbers were shuffled randomly. Your task is to find the missing fourth number.

An arithmetic progression is a sequence of numbers in which the difference between any two successive terms is constant. In other words, if the four numbers are x, x+d, x+2d, and x+3d (with d \neq 0), then after losing one term and shuffling the rest, you are given three numbers. It is guaranteed that these three numbers come from a unique arithmetic progression.

inputFormat

The input consists of a single line containing three space‐separated integers.

outputFormat

Output a single integer: the missing number.

sample

2 4 8
6