#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, P = 1000000007;
int n, m, i, j, v[N], p[N], tot, f[N], r[N], b[N], A[N], B[N], ret, tmp;
int pow(int a, int b) {
  int t = 1;
  for (; b; b >>= 1, a = 1LL * a * a % P)
    if (b & 1) t = 1LL * t * a % P;
  return t;
}
int main() {
  scanf("%d%d", &n, &m);
  m++;
  for (f[1] = 1, i = 2; i <= m; i++) {
    if (!v[i]) f[i] = pow(i, m - 1), p[tot++] = i;
    for (j = 0; j < tot; j++) {
      if (i * p[j] > m) break;
      v[i * p[j]] = 1, f[i * p[j]] = 1LL * f[i] * f[p[j]] % P;
      if (i % p[j] == 0) break;
    }
  }
  for (i = 2; i <= m; i++) f[i] = (f[i - 1] + f[i]) % P;
  if ((n %= P) <= m) return printf("%d", f[n]), 0;
  for (r[0] = r[1] = 1, i = 2; i <= m; i++)
    r[i] = 1LL * (P - r[P % i]) * (P / i) % P;
  for (i = 2; i <= m; i++) r[i] = 1LL * r[i - 1] * r[i] % P;
  for (i = 1; i <= m + 1; i++) b[i] = (n - i + 1 + P) % P;
  for (A[0] = B[m + 2] = i = 1; i <= m + 1; i++)
    A[i] = 1LL * A[i - 1] * b[i] % P;
  for (i = m + 1; i; i--) B[i] = 1LL * B[i + 1] * b[i] % P;
  for (i = 0; i <= m; i++) {
    tmp = 1LL * f[i] * r[m - i] % P * r[i] % P * A[i] % P * B[i + 2] % P;
    if ((m - i) & 1)
      ret = (ret - tmp + P) % P;
    else
      ret = (ret + tmp) % P;
  }
  printf("%d", ret);
}

### Prompt

Please provide a Cpp coded solution 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 N = 1000010, P = 1000000007;
int n, m, i, j, v[N], p[N], tot, f[N], r[N], b[N], A[N], B[N], ret, tmp;
int pow(int a, int b) {
  int t = 1;
  for (; b; b >>= 1, a = 1LL * a * a % P)
    if (b & 1) t = 1LL * t * a % P;
  return t;
}
int main() {
  scanf("%d%d", &n, &m);
  m++;
  for (f[1] = 1, i = 2; i <= m; i++) {
    if (!v[i]) f[i] = pow(i, m - 1), p[tot++] = i;
    for (j = 0; j < tot; j++) {
      if (i * p[j] > m) break;
      v[i * p[j]] = 1, f[i * p[j]] = 1LL * f[i] * f[p[j]] % P;
      if (i % p[j] == 0) break;
    }
  }
  for (i = 2; i <= m; i++) f[i] = (f[i - 1] + f[i]) % P;
  if ((n %= P) <= m) return printf("%d", f[n]), 0;
  for (r[0] = r[1] = 1, i = 2; i <= m; i++)
    r[i] = 1LL * (P - r[P % i]) * (P / i) % P;
  for (i = 2; i <= m; i++) r[i] = 1LL * r[i - 1] * r[i] % P;
  for (i = 1; i <= m + 1; i++) b[i] = (n - i + 1 + P) % P;
  for (A[0] = B[m + 2] = i = 1; i <= m + 1; i++)
    A[i] = 1LL * A[i - 1] * b[i] % P;
  for (i = m + 1; i; i--) B[i] = 1LL * B[i + 1] * b[i] % P;
  for (i = 0; i <= m; i++) {
    tmp = 1LL * f[i] * r[m - i] % P * r[i] % P * A[i] % P * B[i + 2] % P;
    if ((m - i) & 1)
      ret = (ret - tmp + P) % P;
    else
      ret = (ret + tmp) % P;
  }
  printf("%d", ret);
}

```