Lucky Numbers

Time limit: 0.25s Memory limit: 256MB Input: Output:

It's a well known fact that in some cultures the number 1313 brings bad luck.

Task

You are given a number XX consisting of NN digits. You are to compute how many numbers smaller than or equal to XX don't contain 1313 as a substring in their base 1010 representation. Since the answer can be quite large, you are to print it modulo 1 000 000 0071 \ 000 \ 000 \ 007.

In addition, you are to process QQ queries of two possible types:

  • Query(radixL, radixR): you are to compute how many numbers smaller than or equal to substr(X,radixL,radixR)substr(X, radixL, radixR) don't contain 1313 as a substring in their base 1010 representation. Since the answer can be quite large, you are to print it modulo 1 000 000 007. substr(X,L,R)1 \ 000 \ 000 \ 007. \ substr(X, L, R) stands for the substring of XX starting from the LL-th digit and ending with the RR-th digit counting from left to right
  • Update(radix, newDigit): one of XX's digits is replaced. In particular, digit numbered radixradix counting from left to right is changed to newDigitnewDigit.

Input data

The first line of input contains two integers NN and QQ - the number of digits of number XX and the number of queries that need to be processed.

The second line of input contains the number XX.

The next QQ lines describe the queries that need to be processed. Each line starts with an integer tt - the type of query that needs to be processed.

If t=1t = 1 , then the line describes a QueryQuery and two integers radixLradixL and radixRradixR follow - the left and right ends of the substring that you need to consider as bounds for the query.

Otherwise (t=2)(t = 2), the line describes an Update and two integers radixradix and newDigitnewDigit follow - the position of the digit that needs to be changed and the new value of the digit.

Output data

The first line of the output contains a single integer - how many numbers smaller than or equal to XX don't contain 1313 as a substring in their base 1010 representation. Since the answer can be quite large, you are to print it modulo 1 000 000 0071 \ 000 \ 000 \ 007.

Then, for each query of the first type, print the answer modulo 1 000 000 0071 \ 000 \ 000 \ 007 on a separate line.

Constraints and clarifications

  • 1N100 0001 \leq N \leq 100 \ 000
  • 0Q10 0000 \leq Q \leq 10 \ 000
  • 1t21 \leq t \leq 2
  • If t=1t = 1 then 1radixLradixRN1 \leq radixL \leq radixR \leq N
  • If t=2t = 2, then 1radixN, 0newDigit91 \leq radix \leq N, \ 0 \leq newDigit \leq 9
# Points Restrictions
1 14 1N6, Q=01 \leq N \leq 6, \ Q = 0
2 14 1N18, Q=01 \leq N \leq 18, \ Q = 0
3 9 1N10 000, 0Q10 0001 \leq N \leq 10 \ 000, \ 0 \leq Q \leq 10 \ 000, all queries will be of the first type
4 27 1N100 000, 0Q10 0001 \leq N \leq 100 \ 000, \ 0 \leq Q \leq 10 \ 000, all queries will be of the first type
5 9 1N10 000, 0Q10 0001 \leq N \leq 10 \ 000, \ 0 \leq Q \leq 10 \ 000
6 27 No further restrictions.

Example

stdin

6 10
560484
2 6 4
2 1 4
2 5 6
2 6 1
2 3 6
1 3 6
1 1 3
1 6 6
1 2 6
2 1 7

stdout

528145
6228
452
2
63454

Explanation

There are 528145528145 non-negative integers smaller than or equal to 560484560484 not containing digits 1313 as a substring in their base 1010 representation. Note that this includes the number 00.

  • XX is initially 560 484560 \ 484.
  • After update 2 6 4, XX becomes 56048456048\fbox{4}.
  • After update 2 1 4, XX becomes 460484\fbox{4}60484.
  • After update 2 5 6, XX becomes 4604644604\fbox{6}4.
  • After update 2 6 1, XX becomes 46046146046\fbox{1}.
  • After update 2 3 6, XX becomes 46646146\fbox{6}461.
  • Query 1 3 6 asks us how many non-negative integers smaller than or equal to 466461\cancel{46} 6461 don't contain substring 1313 - there are 62286228 such numbers.
  • Query 1 1 3 asks us how many non-negative integers smaller than or equal to 466461466\cancel{461} not containing substring 1313 - there are 452452 such numbers.
  • Query 1 6 6 asks us how many non-negative integers smaller than or equal to 466461\cancel{46646} 1 not containing substring 1313 - there are 22 such numbers: 00 and 11.
  • Query 1 2 6 asks us how many non-negative integers smaller than or equal to 466461\cancel{4} 66461 not containing substring 1313 - there are 6345463454 such numbers.
  • After update 2 1 7, XX becomes 766461\fbox{7} 66461.

Log in or sign up to be able to send submissions!