#P4934. Magical Gifts Packaging
Magical Gifts Packaging
Magical Gifts Packaging
You are given \(n\) gifts with unique magic values \(a_1, a_2, \dots, a_n\). The gifts are magical: if two gifts with values \(a_i\) and \(a_j\) (with \(a_i \neq a_j\)) are placed in the same box and if
\(a_i \operatorname{bitand} a_j \ge \min(a_i, a_j)\),
then the magic of these two gifts cancels out. Here, \(\operatorname{bitand}\) denotes the bitwise AND operation. In other words, if for two gifts with values \(x\) and \(y\) (assume \(x < y\)) it holds that
\(x \operatorname{bitand} y = x\),
they cannot be placed in the same box.
Your task is to assign each gift to exactly one box so that no two gifts in the same box conflict. Moreover, you need to minimize the number of boxes used. If there are multiple solutions, you may output any one of them.
inputFormat
The first line contains an integer \(n\) (the number of gifts).
The second line contains \(n\) distinct integers \(a_1, a_2, \dots, a_n\), representing the magic values of the gifts.
outputFormat
Output the minimum number of boxes \(k\) in the first line.
Then output \(k\) lines. Each line starts with an integer \(m\), which is the number of gifts in that box, followed by \(m\) space-separated integers denoting the 1-indexed positions of the gifts assigned to that box.
sample
3
1 2 3
2
2 1 2
1 3
</p>