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<bits/stdc++.h>

using namespace std;

typedef long long LL;
#define M 10000500
#define N 5200

const LL mod=1000000007;
LL n,m,ans,f[N][N],fac[M],ifac[M];

void upd(LL &x,LL y){
	x=(x+y)%mod;
}

LL pw(LL x,LL k){
	if (!k) return 1;
	LL tmp=pw(x*x%mod,k>>1);
	return k&1?tmp*x%mod:tmp;
}

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

LL C(LL x,LL y){
	return x<y||y<0?0:fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}

void calc(LL i,LL j){
	LL k=n-i-j;
	upd(ans,f[i][j]*C(m-n+k-1,k-1)%mod*fac[m-n]%mod*(i?fac[i-1]:1));
}

int main(){
	scanf("%lld%lld",&m,&n);
	fac[0]=1; for (LL i=1;i<=m;++i) fac[i]=fac[i-1]*i%mod;
	ifac[m]=inv(fac[m]); for (LL i=m-1;~i;--i) ifac[i]=ifac[i+1]*(i+1)%mod;
	f[n][0]=1;
	for (LL i=n-1;~i;--i){
		for (LL j=0;j<=n-i;++j){
			f[i+1][j]=(f[i+1][j]*fac[i]%mod+f[i+2][j])%mod;
		}
		for (LL j=0;j<=n-i;++j){
			f[i][j]=f[i+1][j]*ifac[i]%mod;
			if (j) upd(f[i][j],-(f[i+1][j-1]-f[i+2][j-1])*ifac[i]);
			calc(i,j);
		}
	}
	upd(ans,mod);
	printf("%lld\n",ans);
	
	return 0;
}