#C3976. Swap Maximum and Minimum Values in a List

    ID: 47462 Type: Default 1000ms 256MiB

Swap Maximum and Minimum Values in a List

Swap Maximum and Minimum Values in a List

You are given a list of n integers. Your task is to modify the list such that all occurrences of the maximum value are replaced with the minimum value, and all occurrences of the minimum value are replaced with the maximum value. The remaining elements should remain unchanged.

Let \(max = \max(a_1, a_2, \ldots, a_n)\) and \(min = \min(a_1, a_2, \ldots, a_n)\). Then, for each element \(a_i\) in the list, update it as follows:

[ \tilde{a_i} = \begin{cases} min & \text{if } a_i = max,\ max & \text{if } a_i = min,\ a_i & \text{otherwise.} \end{cases} ]

Print the modified list as a sequence of space-separated integers.

inputFormat

The input is read from standard input and consists of two lines:

  1. The first line contains a single integer \(n\) representing the number of elements in the list.
  2. The second line contains \(n\) space-separated integers representing the elements of the list.

outputFormat

Output the modified list as a sequence of space-separated integers on a single line. If the list is empty, output nothing.

## sample
5
1 3 5 3 1
5 3 1 3 5