Weight Overflow
Time limit1sMemory limit512 MB
Given n weights and a modulus m, find two disjoint nonempty subsets whose sums are equal modulo m, or report that none exists.
- Level
Medium7 of 10
- Topics
- Brute force, Hash map, Number theory
- Solved
- No attempts yet
Problem
John recently bought an electronic balance scale from a well-known website. The scale has two plates where you can put items. After you put some items on the scale, it shows which plate is heavier than the other, or that the weights on the two plates are equal and the scale is balanced.
John started experimenting with the scale and found that the results are sometimes strange. The scale adds up the weight of the items on each plate in grams and then compares the two totals. However, the software was written by former sport programmers, so the scale calculates the weight on each plate modulo an integer .
John has special weights. The -th weight has a mass of grams. He wants the scale to balance by putting some of these weights on the plates. He must put at least one weight on the scale.
Input
The first line contains two integers and , the number of weights John has and the modulo used for weight calculation (; ).
The second line contains integers , the masses of the weights ().
Output
If an answer exists, print , the number of weights to put on the first plate, on the first line. The second line must contain the numbers of these weights.
Then print , the number of weights to put on the second plate, on the next line. Print the numbers of these weights on the following line.
Weights are numbered from 1 to in the order they appear in the input.
If there is no answer, print a single number "-1".