#K81832. Second Smallest Element

    ID: 35841 Type: Default 1000ms 256MiB

Second Smallest Element

Second Smallest Element

Given an array of integers, your task is to find the second smallest distinct element. If the array is empty, output None. If the array contains only one distinct element, simply output that element.

You must read the input from stdin and print the result to stdout.

The answer is defined as follows: \[ \text{result} = \begin{cases} None, & \text{if the array is empty}\\ a, & \text{if the array has exactly one distinct element } a \\ \min\{ x \in S \setminus \{\min(S)\} \}, & \text{if the array has more than one distinct element} \end{cases} \]

inputFormat

The input consists of two lines:

  • The first line contains an integer n, the number of elements in the array.
  • The second line contains n space-separated integers. If n is 0, the second line will be empty.

outputFormat

Print a single line containing the second smallest distinct element based on the following rules:

  • If the array is empty, output None.
  • If the array has only one distinct element, output that element.
  • If the array has more than one distinct element, output the second smallest one.
## sample
0
None

</p>