Codeforces Round 263 (Div. 1) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

dsu

math

*2800

No tag edit access

The problem statement has recently been changed. View the changes.

×
D. Appleman and Complicated Task

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputToastman came up with a very complicated task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?

Given a *n* × *n* checkerboard. Each cell of the board has either character 'x', or character 'o', or nothing. How many ways to fill all the empty cells with 'x' or 'o' (each cell must contain only one character in the end) are there, such that for each cell the number of adjacent cells with 'o' will be even? Find the number of ways modulo 1000000007 (10^{9} + 7). Two cells of the board are adjacent if they share a side.

Input

The first line contains two integers *n*, *k* (1 ≤ *n*, *k* ≤ 10^{5}) — the size of the board, and the number of cells that has characters initially.

Then *k* lines follows. The *i*-th line contains two integers and a character: *a*_{i}, *b*_{i}, *c*_{i} (1 ≤ *a*_{i}, *b*_{i} ≤ *n*; *c*_{i} is either 'o' or 'x'). This line means: there is a character *c*_{i} in the cell that is located on the intersection of the *a*_{i}-th row and *b*_{i}-th column. All the given cells are distinct.

Consider that the rows are numbered from 1 to *n* from top to bottom. Analogically, the columns are numbered from 1 to *n* from left to right.

Output

Print a single integer — the answer to the problem.

Examples

Input

3 2

1 1 x

2 2 o

Output

2

Input

4 3

2 4 x

3 4 x

3 2 x

Output

2

Note

In the first example there are two ways:

xxo xoo

xox ooo

oxx oox

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/14/2024 15:22:34 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|