#B4022. Non-Adjacent Song Order
Non-Adjacent Song Order
Non-Adjacent Song Order
Wind's Playlist contains \(n\) songs. These songs are divided into \(m\) categories such that each category appears exactly \(\frac{n}{m}\) times. The \(i\)-th song has a category denoted by \(c_i\). Since Wind has no preference for any particular category, the count of songs in each category is the same.
Your task is to rearrange the songs into a new play order (a permutation of the songs) such that no two consecutive songs share the same category. If there exist multiple answers, you may output any one of them.
Note: It is guaranteed that \(n\) is divisible by \(m\) and \(m \ge 2\), so a valid solution always exists.
inputFormat
The first line contains a single integer \(n\) (the total number of songs).
The second line contains \(n\) integers \(c_1, c_2, \dots, c_n\), where \(c_i\) denotes the category of the \(i\)-th song.
It is guaranteed that the number of occurrences of each distinct category is exactly \(\frac{n}{m}\), where \(m\) is the number of distinct categories.
outputFormat
Output a permutation of song indices (1-indexed) separated by spaces, representing a play order such that no two consecutive songs belong to the same category.
sample
6
1 1 2 2 1 2
3 1 4 2 6 5