#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30), N = 1001000, mod = 1e9 + 7;
long long n, k, fac[N], inv[N], c, p[N];
inline int in() {
  char ch = getchar();
  int f = 1, tmp = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    tmp = (tmp << 1) + (tmp << 3) + (ch - '0');
    ch = getchar();
  }
  return tmp * f;
}
long long ksm(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= k + 2; i++) p[i] = (p[i - 1] + ksm(i, k)) % mod;
  if (n <= k + 2) {
    printf("%lld", p[n]);
    return 0;
  }
  fac[0] = inv[0] = c = 1;
  for (int i = 1; i <= k + 2; i++) fac[i] = fac[i - 1] * i % mod;
  inv[k + 2] = ksm(fac[k + 2], mod - 2);
  for (int i = k + 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  for (int i = 1; i <= k + 2; i++) c = c * (n - i) % mod;
  long long ans = 0;
  for (int i = 1; i <= k + 2; i++)
    ans += p[i] * c % mod * ksm(n - i, mod - 2) % mod * inv[i - 1] % mod *
           inv[k + 2 - i] % mod * ((k + 2 - i) % 2 == 0 ? 1 : -1) % mod;
  ans = ans % mod;
  printf("%lld\n", (ans + mod) % mod);
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

There are well-known formulas: <image>, <image>, <image>. Also mathematicians found similar formulas for higher degrees.

Find the value of the sum <image> modulo 109 + 7 (so you should find the remainder after dividing the answer by the value 109 + 7).

Input

The only line contains two integers n, k (1 ≤ n ≤ 109, 0 ≤ k ≤ 106).

Output

Print the only integer a — the remainder after dividing the value of the sum by the value 109 + 7.

Examples

Input

4 1


Output

10


Input

4 2


Output

30


Input

4 3


Output

100


Input

4 0


Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30), N = 1001000, mod = 1e9 + 7;
long long n, k, fac[N], inv[N], c, p[N];
inline int in() {
  char ch = getchar();
  int f = 1, tmp = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    tmp = (tmp << 1) + (tmp << 3) + (ch - '0');
    ch = getchar();
  }
  return tmp * f;
}
long long ksm(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= k + 2; i++) p[i] = (p[i - 1] + ksm(i, k)) % mod;
  if (n <= k + 2) {
    printf("%lld", p[n]);
    return 0;
  }
  fac[0] = inv[0] = c = 1;
  for (int i = 1; i <= k + 2; i++) fac[i] = fac[i - 1] * i % mod;
  inv[k + 2] = ksm(fac[k + 2], mod - 2);
  for (int i = k + 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  for (int i = 1; i <= k + 2; i++) c = c * (n - i) % mod;
  long long ans = 0;
  for (int i = 1; i <= k + 2; i++)
    ans += p[i] * c % mod * ksm(n - i, mod - 2) % mod * inv[i - 1] % mod *
           inv[k + 2 - i] % mod * ((k + 2 - i) % 2 == 0 ? 1 : -1) % mod;
  ans = ans % mod;
  printf("%lld\n", (ans + mod) % mod);
  return 0;
}

```