Expected Nice Numbers

Time limit: 0.5s Memory limit: 64MB Input: Output:

A number is called "nice" if it contains 6969 as a subsequence. In other words, if in that number, immediately after the digit 66 there is a digit 99, then the number is "nice".

For example, the number 369 420369 \ 420 is "nice", while the number 684 920684 \ 920 is not "nice".

Task

Given the positive natural numbers NN and KK, find the expected number of "nice" numbers in a randomly generated sequence containing NN numbers with at most KK digits, modulo 1 000 000 0071 \ 000 \ 000 \ 007.

Input data

The program reads from the keyboard the numbers NN and KK, separated by a newline. The number KK is given in base 22.

Output data

The program will display on the screen the number ansans, representing the required answer in the form PQ1P \cdot {Q}^{-1}, modulo 1 000 000 0071 \ 000 \ 000 \ 007.

Constraints and clarifications

  • 1N1091 \le N \le {10}^{9}
  • 0log2(K)<1060 \le \log_2(K) < {10}^{6}
  • The number KK is given in base 22.
  • The use of fastio is recommended.
  • For tests worth 1010 points, N10N \le 10, log2(K)3\log_2(K) \le 3.
  • For other tests worth 2020 points, N1 000N \le 1 \ 000, log2(K)20\log_2(K) \le 20.
  • For other tests worth 2020 points, N1 000 000N \le 1 \ 000 \ 000, log2(K)20\log_2(K) \le 20.
  • For other tests worth 3030 points, N1 000 000N \le 1 \ 000 \ 000;
  • For other tests, no additional restrictions.

Example 1

stdin

1
10

stdout

570000004

Explanation

For simplicity, N=1N = 1, K=2K = 2, so the only allowed nice number is 6969.
There are 9999 sequences with 00 "nice" numbers, 11 sequence with 11 "nice" number.
Therefore, the answer is 1÷100=11001=570 000 004(mod1 000 000 007)1 \div 100 = 1 \cdot {100}^{-1} = 570 \ 000 \ 004 \pmod{1 \ 000 \ 000 \ 007}.

Example 2

stdin

5
10

stdout

850000006

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