Codeforces Round 263 (Div. 1)
D
Appleman and Complicated Task
Codeforces
2800
原题
← CE →
翻译中…

Toastman 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.

翻译中…

Note

翻译中…

In the first example there are two ways:

翻译中…

    xxo          xoo
    xox          ooo
    oxx          oox

翻译中…

样例

Input #1
3 2
1 1 x
2 2 o
Output #1
2
InputCopy OutputCopy
Input #2
4 3
2 4 x
3 4 x
3 2 x
Output #2
2
InputCopy OutputCopy
题目信息
题号
461D
时间限制
2 s
内存限制
256 MB
标签
并查集
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。