1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <cstdio>
#include <math.h>

using namespace std;

int fac(int n)
{
	int i = 1;
	for (int j = 1; i <= n; i++)
		i *= j;
	return i;
}

int main()
{
	int n = 0;
	int m = 0;

	unsigned long long int out = 0;

	scanf("%d %d", &n, &m);

	out = pow(m, n) - (2 * m) - (fac(n)/(fac(n-m))) - 1;

	out = out % 1000000007;

	printf("%d", out);

	return 0;
}