#Lutece0192. Party Lamps

Party Lamps

Migrated from Lutece 192 Party Lamps

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

To brighten up the gala dinner of the IOI'98 we have a set of NN (10N10010\leq N\leq 100) colored lamps numbered from 11 to NN.

The lamps are connected to four buttons:

  • Button 11: When this button is pressed, all the lamps change their state: those that are ON are turned OFF and those that are OFF are turned ON.
  • Button 22: Changes the state of all the odd numbered lamps.
  • Button 33: Changes the state of all the even numbered lamps.
  • Button 44: Changes the state of the lamps whose number is of the form 3×K+13\times K+1 (with K0K\geq 0), i.e., 1,4,7,1,4,7,\cdots

A counter CC records the total number of button presses.

When the party starts, all the lamps are ON and the counter CC is set to zero.

You are given the value of counter CC (0C100000\leq C\leq 10000) and the final state of some of the lamps after some operations have been executed. Write a program to determine all the possible final configurations of the N lamps that are consistent with the given information, without repetitions.

Input

No lamp will be listed twice in the input.

Line 11: NN

Line 22: Final value of CC

Line 33: Some lamp numbers ON in the final configuration, separated by one space and terminated by the integer 1-1.

Line 44: Some lamp numbers OFF in the final configuration, separated by one space and terminated by the integer 1-1.

Output

Lines with all the possible final configurations (without repetitions) of all the lamps. Each line has NN characters, where the first character represents the state of lamp 1 and the last character represents the state of lamp NN. A 00 (zero) stands for a lamp that is OFF, and a 11 (one) stands for a lamp that is ON. The lines must be ordered from least to largest (as binary numbers).

If there are no possible configurations, output a single line with the single word IMPOSSIBLE

Samples

10
1
-1
7 -1
0000000000
0101010101
0110110110

Note

In this case, there are three possible final configurations:

  • All lamps are OFF
  • Lamps 1,4,7,101, 4, 7, 10 are OFF and lamps 2,3,5,6,8,92, 3, 5, 6, 8, 9 are ON.
  • Lamps 1,3,5,7,91, 3, 5, 7, 9 are OFF and lamps 2,4,6,8,102, 4, 6, 8, 10 are ON.

Resources

USACO TRAINING selected by rectaflex