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
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.