QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#2793. Kawaii

统计

A large number of length $n$ is represented as $S_1S_2S_3...S_n$, where $S_i$ represents the $i$-th digit of the number, and $S_1$ is the most significant digit.

You are given some constraints. Each constraint is represented by four numbers $l_1, r_1, l_2, r_2$, which define two intervals of the same length. This means the substring $S_{l_1}S_{l_1+1}S_{l_1+2}...S_{r_1}$ must be identical to the substring $S_{l_2}S_{l_2+1}S_{l_2+2}...S_{r_2}$.

For example, when $n = 6$, if a constraint is $l_1 = 1, r_1 = 3, l_2 = 4, r_2 = 6$, then $123123$ and $351351$ satisfy the condition, but $12012$ and $131141$ do not. The former does not have a length of $6$, and in the latter, the second digit is different from the fifth digit.

Find the number of such integers that satisfy all the given conditions.

Input

The first line contains two integers $n$ and $m$, representing the length of the large number and the number of constraints, respectively.

The next $m$ lines each contain four integers $l_1, r_1, l_2, r_2$, representing the two intervals for each constraint.

Output

A single integer representing the number of large numbers of length $n$ that satisfy all conditions. Since the answer may be very large, output the result modulo $10^9 + 7$.

Examples

Input 1

4 2
1 2 3 4
3 3 3 3

Output 1

90

Constraints

  • $30\%$ of the data: $1 \le n \le 2000, 1 \le m \le 2000$
  • $100\%$ of the data: $1 \le n \le 10^5, 1 \le m \le 10^5, 1 \le l_1, r_1, l_2, r_2 \le n$
  • It is guaranteed that $r_1 - l_1 = r_2 - l_2$

Discussions

About Discussions

The discussion section is only for posting: 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.
  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.