#K65997. Construct Playlist

    ID: 32321 Type: Default 1000ms 256MiB

Construct Playlist

Construct Playlist

You are given an integer \(n\) representing the number of songs and a list of \(n\) integers where each integer represents the duration (or identifier) of a song. Your task is to construct a playlist such that no two consecutive songs have the same duration. If it is impossible to form such a playlist, output an empty playlist.

Note: The playlist should be arranged in a way that no song is immediately repeated. If there are multiple valid answers, any one of them will be accepted.

Example:

Input: n = 5, durations = [4, 4, 7, 7, 7]
Output: 7 4 7 4 7

Input: n = 3, durations = [1, 1, 1] Output: (an empty output)

</p>

inputFormat

The input is given from standard input (stdin) as follows:

  1. The first line contains an integer \(n\) — the number of songs.
  2. The second line contains \(n\) space-separated integers representing the durations of the songs.

outputFormat

Output the rearranged playlist on a single line with the song durations separated by a single space. If no valid arrangement exists, output an empty line.

## sample
5
4 4 7 7 7
7 4 7 4 7