Problems > The Missing Term

The Missing Term

Difficulty: 1200 3000 ms 128 MB

math

An arithmetic progression had its terms listed in order, but one interior term was deleted. Recover it.

Input: the first line has the remaining count M; the second line has the M remaining terms in order.

Output: the deleted term.

Constraints:

  • 3 ≤ M ≤ 105
  • the common difference is non-zero; the deleted term is not an endpoint

Sample Tests

Input 1
4
1 3 7 9
Output 1
5
Input 2
3
10 20 40
Output 2
30

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.