#K13776. Find the Missing Number
Find the Missing Number
Find the Missing Number
You are given an array of n distinct integers, which represents a sequence taken from the set \(\{0, 1, 2, \dots, n\}\) with exactly one number missing. Your task is to find and output the missing number.
In particular, if the input array is of length n, then the complete set would be \(\{0, 1, 2, \dots, n\}\). The missing number can be calculated using the formula for the sum of the first \(n\) natural numbers (in this case, from \(0\) to \(n\)):
\(total = \frac{n(n+1)}{2}\)
Subtract the sum of the given array from total to obtain the missing number.
inputFormat
The first line contains an integer n representing the number of elements in the array. The second line contains n space-separated integers which form the array.
outputFormat
Output a single integer — the missing number.
## sample3
3 0 1
2
</p>