#B4066. Sequence Transformation

    ID: 11723 Type: Default 1000ms 256MiB

Sequence Transformation

Sequence Transformation

Given a sequence \(A = [a_1, a_2, \ldots, a_n]\) and a threshold value \(k\), you are required to transform the sequence as follows:

If an element \(a_i > k\), replace it with \(\max(A)\). If \(a_i < k\), replace it with \(\min(A)\). Elements equal to \(k\) remain unchanged.

Output the transformed sequence in a single line.

inputFormat

The first line of input contains two integers \(n\) and \(k\), where \(n\) is the size of the sequence and \(k\) is the threshold. The second line contains \(n\) space-separated integers representing the sequence \(A = [a_1, a_2, \ldots, a_n]\).

outputFormat

Output the transformed sequence after replacing elements as described. The resulting numbers should be printed in one line, separated by spaces.

sample

5 3
1 2 3 4 5
1 1 3 5 5