#K95077. Sum of Second Smallest and Second Largest Unique Elements

    ID: 38783 Type: Default 1000ms 256MiB

Sum of Second Smallest and Second Largest Unique Elements

Sum of Second Smallest and Second Largest Unique Elements

You are given a list of integers. Your task is to find the sum of the second smallest and second largest unique elements in the list.

Let \(S\) be the sorted list of unique integers. If \(|S| \ge 4\), then the answer is \(S_2 + S_{|S|-1}\), where \(S_2\) is the second smallest and \(S_{|S|-1}\) is the second largest element in \(S\). Otherwise, output None.

For example, for the list [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5], the unique sorted list is [1,2,3,4,5,6,9] so the answer is \(2+6=8\>.

inputFormat

The input is given via standard input (stdin) in the following format:

  • The first line contains an integer \(N\) representing the number of elements in the list.
  • The second line contains \(N\) space-separated integers.

outputFormat

Print the sum of the second smallest and second largest unique elements if there are at least four unique numbers, otherwise print None.

## sample
11
3 1 4 1 5 9 2 6 5 3 5
8