#K80242. Find Elements With Smaller and Larger
Find Elements With Smaller and Larger
Find Elements With Smaller and Larger
You are given an array of n integers. Your task is to find the number of elements in the array that have at least one strictly smaller element and at least one strictly larger element than themselves.
More formally, if the minimum and maximum elements of the array are \( m = \min_{1 \leq i \leq n} a_i \) and \( M = \max_{1 \leq i \leq n} a_i \), then an element \( x \) is counted if and only if \( m < x < M \).
Note that if the array has less than 3 elements, then no element can satisfy this condition.
inputFormat
The first line of input contains a single integer n (the number of elements in the array). The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output a single integer denoting the number of elements that have both a smaller and a larger element present in the array.
## sample6
5 1 9 2 5 7
4