Electrical switches#11691

Electrical switches

In Fuad's house, there are bulbs and electrical switches. The switches are numbered from to , and the bulbs are numbered from to . Each switch may be connected to zero or more bulbs, but each bulb is connected to exactly two different switches.

When a switch is toggled, every bulb connected to it has its state flipped: if the bulb was on, it turns off; if it was off, it turns on. Initially, some bulbs are on and some are off.

Since Fuad dreams of becoming an electrical engineer, he decided to play with the bulbs. He can toggle each switch at most once, and he wants to choose some switches and toggle them in some particular order so that all bulbs end up on. Determine whether this is possible. If so, find how many different ways this can be achieved. Two ways are considered different if the sequence of toggled switches differs.

Since the number of ways may be large, output the answer modulo (10^9+7).

Input

The first line contains two integers (2 \le n \le 500) and (1 \le m \le \frac{n(n-1)}{2}) — the number of switches and the number of bulbs, respectively. The next lines each describe a bulb. The -th bulb is given by three integers: a_i and b_i (1 \le a_i \ne b_i \le n), the two switches it is connected to, and c_i (0 \le c_i \le 1), its initial state ( if it is on, if off).

For any two switches, there is at most one bulb connected to both.

Output

Print **yay!** on the first line if it is possible to turn on all bulbs, or **meh** otherwise. If it is possible, print on the second line the number of ways to turn on all bulbs modulo (10^9+7).

Examples

In the first example, all bulbs can be turned on in one of three ways:

  • by toggling no switches;

  • by toggling switch first, then switch ;

  • by toggling switch first, then switch .

Example 1

Loading
Loading

Example 2

Loading
Loading

Scoring

This problem consists of subtasks. Points for a subtask are awarded only if all corresponding tests are passed.

For each subtask, if you correctly determine whether it is possible to simply turn all bulbs on in all cases, you will receive of the points for that subtask.

Let denote the number of connected components in the graph where the switches are vertices and the bulbs are edges.

  1. ( points): h < 9;

  2. ( points): h < 18;

  3. ( points): no additional constraints.