atcoder#AGC045D. [AGC045D] Lamps and Buttons

[AGC045D] Lamps and Buttons

Score : 12001200 points

Problem Statement

We have NN lamps numbered 11 to NN, and NN buttons numbered 11 to NN. Initially, Lamp 1,2,,A1, 2, \cdots, A are on, and the other lamps are off.

Snuke and Ringo will play the following game.

  • First, Ringo generates a permutation (p1,p2,,pN)(p_1,p_2,\cdots,p_N) of (1,2,,N)(1,2,\cdots,N). The permutation is chosen from all N!N! possible permutations with equal probability, without being informed to Snuke.
  • Then, Snuke does the following operation any number of times he likes:
    • Choose a lamp that is on at the moment. (The operation cannot be done if there is no such lamp.) Let Lamp ii be the chosen lamp. Press Button ii, which switches the state of Lamp pip_i. That is, Lamp pip_i will be turned off if it is on, and vice versa.
  • Choose a lamp that is on at the moment. (The operation cannot be done if there is no such lamp.) Let Lamp ii be the chosen lamp. Press Button ii, which switches the state of Lamp pip_i. That is, Lamp pip_i will be turned off if it is on, and vice versa.

At every moment, Snuke knows which lamps are on. Snuke wins if all the lamps are on, and he will surrender when it turns out that he cannot win. What is the probability of winning when Snuke plays optimally?

Let ww be the probability of winning. Then, w×N!w \times N! will be an integer. Compute w×N!w \times N! modulo (109+7)(10^9+7).

Constraints

  • 2N1072 \leq N \leq 10^7
  • 1Amin(N1,5000)1 \leq A \leq \min(N-1,5000)

Input

Input is given from Standard Input in the following format:

NN AA

Output

Print w×N!w \times N! modulo (109+7)(10^9+7), where ww is the probability of Snuke's winning.

3 1
2

First, Snuke will press Button 11. If Lamp 11 turns off, he loses. Otherwise, he will press the button that he can now press. If the remaining lamp turns on, he wins; if Lamp 11 turns off, he loses. The probability of winning in this game is 1/31/3, so we should print (1/3)×3!=2(1/3)\times 3!=2.

3 2
3
8 4
16776
9999999 4999
90395416