#P2817. 宋荣子的城堡

宋荣子的城堡

Description

saruka owns a big castle. There are nn rooms in the castle, and each room has a number pip_i written on it. One day, saruka invited his friends LYL and MagHSK to play in the castle. They agreed that if someone is currently standing in room ii, then on the next step they must go to room pip_i, and on the following step to room ppip_{p_i}.

To make it more interesting, saruka decides to rewrite each pip_i to satisfy the following:

  • If you start from any room numbered from 1k1 \sim k and follow the rule, you must be able to return to room 11. In particular, if you start from room 11, you must return to room 11 as well (you must take at least one step; if p1=1p_1 = 1, moving from 11 to 11 is also considered valid).

  • If you start from any room with a number greater than kk and follow the rule, you must never reach room 11.

saruka wants to know how many assignments of pip_i satisfy the requirements. Output the answer modulo 109+710 ^ 9 + 7.

Input Format

A single line containing two integers n,kn, k, as described.

Output Format

Output a single integer, the number of valid assignments. The answer is taken modulo 109+710 ^ 9 + 7.

5 2
54
7 4
1728

Hint

Constraints: For 100%100 \% of the testdata, 1n1018,1kmin(n,8)1 \le n \le 10 ^ {18}, 1 \le k \le \min(n, 8).

Translated by ChatGPT 5