Problem:
Score : 1200 points

Problem Statement

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

Snuke and Ringo will play the following game.

First, Ringo generates a permutation (p_1,p_2,\cdots,p_N) of (1,2,\cdots,N).
The permutation is chosen from all 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 i be the chosen lamp.
Press Button i, which switches the state of Lamp p_i. That is, Lamp p_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 w be the probability of winning. Then, w \times N! will be an integer.
Compute w \times N! modulo (10^9+7).

Constraints

2 \leq N \leq 10^7

1 \leq A \leq \min(N-1,5000)

Input

Input is given from Standard Input in the following format:

N A

Output

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

Sample Input 1

3 1

Sample Output 1

2

First, Snuke will press Button 1.
If Lamp 1 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 1 turns off, he loses.
The probability of winning in this game is 1/3, so we should print (1/3)\times 3!=2.

Sample Input 2

3 2

Sample Output 2

3

Sample Input 3

8 4

Sample Output 3

16776

Sample Input 4

9999999 4999

Sample Output 4

90395416

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, K;
long long F[10100000], Inv[10100], Mod = 1000000007;
int Comb[5010][5010];
long long Pow(long long a, long long b){
    long long r=1;
    while(b){
        if(b&1)r=r*a%Mod;
        a=a*a%Mod;b>>=1;
    }
    return r;
}
long long Calc(int B){
    int i;
    long long r=0;
    int m = n-K;
    for(i=0;i<B;i++){
        long long t;
        if(B!=K) t = Comb[B][i]*F[n-i-1]%Mod*Inv[n-(B-i+m)]%Mod*(B-i)%Mod;
        else t = Comb[B][i]*F[n-i-1]%Mod*(B-i)%Mod;
        if(i&1)r+=Mod-t;
        else r+=t;
    }
    r%=Mod;
    //printf("%d %lld\n",B,r);
    return r;
}
int main(){
    scanf("%d%d",&n,&K);
    int i;
    F[0]=1;
    for(i=0;i<=5000;i++){
        Comb[i][0]=1;
        for(int j=1;j<=i;j++)Comb[i][j]=(Comb[i-1][j-1]+Comb[i-1][j])%Mod;
    }
    for(i=1;i<=n;i++)F[i]=F[i-1]*i%Mod;
    for(i=0;i<=10000;i++)Inv[i]=Pow(n-i,Mod-2);
    long long res=0;
    for(i=0;i<=K;i++){
        res+=Calc(i);
        res%=Mod;
    }
    printf("%lld\n",res);
}