#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000008;
int n, k, pp;
long long A[maxn];
long long y[maxn];
long long inv[maxn];
long long w[maxn];
long long quickpow(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = 1ll * res * x % 1000000007;
    x = 1ll * x * x % 1000000007;
    n >>= 1;
  }
  return res;
}
void init() {
  A[0] = pp = 1;
  for (long long i = 1; i <= min(n, k + 2); ++i) {
    A[i] = 1ll * A[i - 1] * i % 1000000007;
    inv[i] = quickpow(n - i, 1000000007 - 2);
    pp = (1ll * pp * (n - i) % 1000000007 + 1000000007) % 1000000007;
    y[i] = (y[i - 1] + quickpow(i, k)) % 1000000007;
  }
  for (long long i = 1; i <= min(n, k + 2); ++i) {
    w[i] = 1ll * A[i - 1] * A[k + 2 - i] % 1000000007;
    if ((k + 2 - i) & 1) w[i] = 1000000007 - w[i];
    w[i] = quickpow(w[i], 1000000007 - 2);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  init();
  if (n <= k + 2) {
    printf("%lld\n", y[n]);
    return 0;
  }
  long long ans = 0;
  for (long long i = 1; i <= (k + 2); ++i) {
    ans = (ans + 1ll * pp * y[i] % 1000000007 * w[i] % 1000000007 * inv[i] %
                     1000000007) %
          1000000007;
  }
  printf("%lld\n", ans);
  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 long long maxn = 1000008;
int n, k, pp;
long long A[maxn];
long long y[maxn];
long long inv[maxn];
long long w[maxn];
long long quickpow(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = 1ll * res * x % 1000000007;
    x = 1ll * x * x % 1000000007;
    n >>= 1;
  }
  return res;
}
void init() {
  A[0] = pp = 1;
  for (long long i = 1; i <= min(n, k + 2); ++i) {
    A[i] = 1ll * A[i - 1] * i % 1000000007;
    inv[i] = quickpow(n - i, 1000000007 - 2);
    pp = (1ll * pp * (n - i) % 1000000007 + 1000000007) % 1000000007;
    y[i] = (y[i - 1] + quickpow(i, k)) % 1000000007;
  }
  for (long long i = 1; i <= min(n, k + 2); ++i) {
    w[i] = 1ll * A[i - 1] * A[k + 2 - i] % 1000000007;
    if ((k + 2 - i) & 1) w[i] = 1000000007 - w[i];
    w[i] = quickpow(w[i], 1000000007 - 2);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  init();
  if (n <= k + 2) {
    printf("%lld\n", y[n]);
    return 0;
  }
  long long ans = 0;
  for (long long i = 1; i <= (k + 2); ++i) {
    ans = (ans + 1ll * pp * y[i] % 1000000007 * w[i] % 1000000007 * inv[i] %
                     1000000007) %
          1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}

```