Electrical switches
In Fuad's house, there are light bulbs and electrical switches. The light switches are numbered from to , and the light bulbs from to . Each switch can be connected to zero or more light bulbs. Each light bulb is connected to two switches.
When a switch is toggled, the light bulbs connected to that switch will turn off if they were on, and turn on if they were off. Currently, some light bulbs are on, and some are off.
Since Fuad wants to become an electrical engineer, he decided to play with the light bulbs. He can toggle each switch no more than once. Fuad wants to toggle several switches in a specific sequence to turn on all the light bulbs. Determine if this is possible. If possible, find out how many different ways this can be done. Any two methods are considered different if the sequence of switch toggles is different.
Since the number of ways can be large, find the remainder when dividing the answer by .
Input
The first line contains two integers and — the number of switches and light bulbs respectively. The next lines describe the light bulbs. The -th bulb is described by three integers and . It is known that the -th bulb is connected to switches with numbers and . indicates the initial state of the bulb. If , then the bulb is on. If , then the bulb is off.
For any two switches, each of them is guaranteed to be connected to at most one light bulb.
Output
In the first line, output yay! if all light bulbs can be turned on. Otherwise, output meh. In the second line, indicate the number of ways to turn on all the light bulbs (if possible). Since the number of ways can be large, output its remainder when divided by .
Examples
In the first example, all light bulbs can be turned on in one of three ways:
do not toggle any electrical switches;
toggle switch first, then toggle switch ;
toggle switch first, then toggle switch ;
Scoring
This problem consists of subtasks. Points for each subtask are awarded only if all the tests for that subtask are passed successfully.
For each subtask in this problem, if you correctly determine whether it is possible to simply turn on the light bulbs in all tests for this subtask, you will receive of the points for that subtask.
( points): ;
( points): ;
( points): there are no additional constraints;