#K83317. Sum of Array Elements Excluding Extremes

    ID: 36171 Type: Default 1000ms 256MiB

Sum of Array Elements Excluding Extremes

Sum of Array Elements Excluding Extremes

Given an array of integers, your task is to compute the sum of all elements which are not equal to the minimum or maximum values of the array. Specifically, if the array is represented as \(A\), let \(\min(A)\) be the minimum element and \(\max(A)\) be the maximum element. Then, the answer is the sum of all elements \(a\) such that \(a \neq \min(A)\) and \(a \neq \max(A)\). If the array has fewer than three elements, output 0.

Note: If there are multiple occurrences of the minimum or maximum elements, all of them should be excluded from the sum.

inputFormat

The input consists of two lines. The first line contains a single integer (n) ((0 \le n \le 10^5)) representing the number of elements. The second line contains (n) space-separated integers.

outputFormat

Output a single integer representing the sum of the array elements after excluding all occurrences of the minimum and maximum elements. If the array contains fewer than three elements, output 0.## sample

5
4 1 3 2 5
9

</p>