#K32752. Sum of Array Excluding Extremes
Sum of Array Excluding Extremes
Sum of Array Excluding Extremes
Given an array of integers, compute the sum of its elements excluding one occurrence of the minimum and maximum element. Formally, for an array \(A\) of size \(n\):
If \(n < 3\), output 0. Otherwise, let \(\min = \min(A)\) and \(\max = \max(A)\). Remove one instance each of \(\min\) and \(\max\) from \(A\) and output the sum of the remaining elements.
For example, for the input array [6, 2, 1, 8, 10], after removing one occurrence of 1 (the minimum) and one occurrence of 10 (the maximum), the sum of the remaining elements is 16.
inputFormat
The first line of input contains an integer \(n\) representing the number of elements. The second line contains \(n\) integers separated by spaces representing the array elements.
outputFormat
Output a single integer which is the sum of the array elements after excluding one occurrence each of the minimum and maximum values. If the number of elements is fewer than three, output 0.
## sample5
6 2 1 8 10
16
</p>