#C14272. Find the Missing Number
Find the Missing Number
Find the Missing Number
You are given a list of sorted consecutive integers with exactly one number missing. Your task is to determine the missing number. The numbers in the list are in increasing order and the difference between any two successive numbers is 1, except for one gap where the missing number should be. Use the formula for the sum of an arithmetic progression: ( S = \frac{n}{2}(a_1 + a_n) ), where ( a_1 ) and ( a_n ) are the first and last terms, respectively, and ( n ) is the total number of terms if the sequence were complete. Read the input from stdin and write the result to stdout.
inputFormat
The first line contains an integer ( n ) representing the number of given numbers. The second line contains ( n ) space-separated integers which make up the nearly complete sequence. Note that the full sequence should have ( n+1 ) numbers.
outputFormat
Output a single integer, which is the missing number in the sequence.## sample
5
1 2 4 5 6
3
</p>