#include<cstdio>
const int mod=1000000007;
int N,A,f[5010][5010][2],fac[10000010],ifac[10000010];
long long C(int n,int m){return m<0||m>n?0:1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
int main(){
	scanf("%d%d",&N,&A);
	for(int i=*fac=1;i<=N;i++)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[N]=inv(fac[N]);
	for(int i=N;i;i--)ifac[i-1]=1ll*ifac[i]*i%mod;
	for(int i=A;i>=0;i--){
		for(int j=i;j>=0;j--){
			f[i][j][0]=(C(N-A+i-j-1,i-1)*(i<A?fac[A-i-1]:1)+f[i+1][j+1][0]+f[i+1][j][1]*(A-i-1ll))%mod;
			f[i][j][1]=(f[i+1][j][0]+f[i+1][j][1]*(A-i-1ll))%mod;
		}
	}
	int s=***f*1ll*fac[N-A]%mod;
	printf("%d\n",s);
}