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 lol;
const int N = 1e7 + 5;
const int M = 5e3 + 5;
const int mod = 1e9 + 7;
inline int pls( int a , int b ) { a += b - mod; return a + ( a >> 31 & mod ); }
inline int mns( int a , int b ) { a -= b; return a + ( a >> 31 & mod ); }
inline void inc( int & a , int b ) { a += b - mod; a += a >> 31 & mod; }
inline void dec( int & a , int b ) { a -= b; a += a >> 31 & mod; }
inline int fpow( int base , int k ) {
  int res = 1;
  while( k ) {
    if( k & 1 ) res = (long long)res * base % mod;
    base = (long long)base * base % mod; k >>= 1;
  }
  return res;
}

int n , A , fac[N] , ifac[N] , inv[N];

inline int binom( int n , int m ) { return (lol)fac[n]*ifac[m]%mod*ifac[n-m]%mod; }

int main( void ) {
  cin >> n >> A;
  fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
  for( int i = 2 ; i <= n ; ++i ) {
    fac[i] = (lol)fac[i - 1] * i % mod;
    inv[i] = (lol)(mod-mod/i)*inv[mod%i]%mod;
    ifac[i] = (lol)ifac[i - 1] * inv[i] % mod;
  }
  int ans = 0 , tmp;
  for( int i = 2 , a , b , c ; i <= A + 1 ; ++i ) {
    a = i - 1 , b = n - A , c = max( 0 , A - i );
    for( int j = 0 ; j < i ; ++j ) {
      tmp = (lol)binom( i - 1 , j ) * (a-j) % mod * inv[a+b-j] % mod * fac[a+b+c-j] % mod;
      if( j & 1 ) dec( ans , tmp );
      else inc( ans , tmp );
    }
  }
  printf("%d",ans);
  return 0;
}