Print the minimum total sadness on the first line.
On the second line print the numbers of the members in camp A in increasing order, separated by single spaces. On the third line print the numbers of the members in camp B the same way. If a camp holds nobody, print an empty line for it.
Several divisions can reach the minimum total sadness, so only one of them counts as correct. Put a member in camp A only if that member belongs to camp A in every division that reaches the minimum, and put everyone else in camp B. The division built this way also reaches the minimum total sadness, and its camp A is contained in the camp A of every other minimal division, so exactly one division satisfies the rule.