atcoder#WTF19B. Multiple of Nine

Multiple of Nine

Score : 14001400 points

Problem Statement

Count the number of strings SS that satisfy the following constraints, modulo 109+710^9 + 7.

  • The length of SS is exactly NN.
  • SS consists of digits (0...9).
  • You are given QQ intervals. For each i(1iQ)i (1 \leq i \leq Q), the integer represented by S[liri]S[l_i \ldots r_i] (the substring of SS between the lil_i-th (11-based) character and the rir_i-th character, inclusive) must be a multiple of 99.

Here, the string SS and its substrings may have leading zeroes. For example, 002019 represents the integer 20192019.

Constraints

  • 1N1091 \leq N \leq 10^9
  • 1Q151 \leq Q \leq 15
  • 1liriN1 \leq l_i \leq r_i \leq N

Input

Input is given from Standard Input in the following format:

NN

QQ

l1l_1 r1r_1

::

lQl_Q rQr_Q

Output

Print the number of strings that satisfy the conditions, modulo 109+710^9 + 7.

4
2
1 2
2 4
136

For example, S=S =9072 satisfies the conditions because both S[12]=S[1 \ldots 2] =90 and S[24]=S[2 \ldots 4] =072 represent multiples of 99.

6
3
2 5
3 5
1 3
2720
20
10
2 15
5 6
1 12
7 9
2 17
5 15
2 4
16 17
2 12
8 17
862268030