#include <bits/stdc++.h>
long long const mod = 1000000007;
int const maxk = 1000007;
long long n = 0, k = 0;
long long y[maxk], inv[maxk], infact[maxk];
long long pow(long long x, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = r * x % mod;
    x = x * x % mod;
    b >>= 1;
  }
  return r;
}
long long sL[maxk], sR[maxk];
inline long long sign(long long x) { return x & 1 ? -1 : +1; }
long long ell[maxk];
int main() {
  scanf("%lld %lld", &n, &k);
  for (int i = 1; i <= k + 2; ++i) {
    y[i] = pow(i, k);
    y[i] = (y[i] + y[i - 1]) % mod;
  }
  infact[0] = infact[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= k + 2; ++i)
    inv[i] = (-inv[mod % i] * (mod / i) % mod + mod) % mod;
  for (int i = 1; i <= k + 2; ++i) infact[i] = infact[i - 1] * inv[i] % mod;
  sL[0] = 1;
  sR[k + 3] = 1;
  for (int i = 1; i <= k + 2; ++i) sL[i] = sL[i - 1] * (n - i) % mod;
  for (int i = k + 2; i >= 0; --i) sR[i] = sR[i + 1] * (n - i) % mod;
  for (int i = 1; i <= k + 2; ++i) {
    ell[i] = sL[i - 1] * sR[i + 1] % mod * infact[i - 1] % mod *
             infact[k + 2 - i] % mod * sign(k + 2 - i) % mod;
  }
  long long ans = 0;
  for (int i = 1; i <= k + 2; ++i) ans = (ans + y[i] * ell[i] % mod) % mod;
  ans = (ans + mod) % mod;
  printf("%lld", ans);
  return 0;
}

### Prompt

In Cpp, your task is to solve the following problem:

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>
long long const mod = 1000000007;
int const maxk = 1000007;
long long n = 0, k = 0;
long long y[maxk], inv[maxk], infact[maxk];
long long pow(long long x, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = r * x % mod;
    x = x * x % mod;
    b >>= 1;
  }
  return r;
}
long long sL[maxk], sR[maxk];
inline long long sign(long long x) { return x & 1 ? -1 : +1; }
long long ell[maxk];
int main() {
  scanf("%lld %lld", &n, &k);
  for (int i = 1; i <= k + 2; ++i) {
    y[i] = pow(i, k);
    y[i] = (y[i] + y[i - 1]) % mod;
  }
  infact[0] = infact[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= k + 2; ++i)
    inv[i] = (-inv[mod % i] * (mod / i) % mod + mod) % mod;
  for (int i = 1; i <= k + 2; ++i) infact[i] = infact[i - 1] * inv[i] % mod;
  sL[0] = 1;
  sR[k + 3] = 1;
  for (int i = 1; i <= k + 2; ++i) sL[i] = sL[i - 1] * (n - i) % mod;
  for (int i = k + 2; i >= 0; --i) sR[i] = sR[i + 1] * (n - i) % mod;
  for (int i = 1; i <= k + 2; ++i) {
    ell[i] = sL[i - 1] * sR[i + 1] % mod * infact[i - 1] % mod *
             infact[k + 2 - i] % mod * sign(k + 2 - i) % mod;
  }
  long long ans = 0;
  for (int i = 1; i <= k + 2; ++i) ans = (ans + y[i] * ell[i] % mod) % mod;
  ans = (ans + mod) % mod;
  printf("%lld", ans);
  return 0;
}

```