QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 512 MB Total points: 100

#13066. Equations And Inequations

統計

You are given an equation $x_1$ + $x_2$ + $x_3$ + ... + $x_k$ = $s$. And also $m$ inequations such as $x_i = x_j$, $x_i \leq x_j$, $x_i \geq x_j$, $x_i \neq x_j$, $x_i < x_j$ and $x_i > x_j$.

Count the number of positive solutions satisfying all the constraints.

Input

The input will consist of multiple test cases.

Each case begins with three integers $s$, $k$, and $m$ ($1 \leq k \leq 12$, $1 \leq s \leq 10^9$, $1 \leq m \leq 100$). The following $m$ lines describe the inequations in such format: "i op j" (without quotes), where "op" is one of the following signs("=", "!=", "<=", ">=", "<", ">").

The number of test cases is less than $1500$. For 95% of the test cases, $k \leq 7$.

Output

For each test case print the answer (number of solutions modulo $10^9+7$) in one line.

Example

Input

3 2 1
1 != 2
3 2 1
1 = 2
50 6 5
1 < 2
1 != 3
3 <= 2
2 = 4
5 >= 6
1000000000 8 12
8 >= 8
2 >= 6
6 != 2
4 = 4
2 < 7
4 <= 1
4 <= 5
1 >= 1
6 <= 1
7 >= 6
8 < 4
4 <= 2

Output

2
0
7700
396619262

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.