#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int n, k;
long long tot = 1, ans = 0;
long long y[N], fac[N], fav[N], inv[N];
long long Qpow(long long x, int p) {
  x %= mod;
  long long ans = 1;
  while (p) {
    if (p & 1) ans = ans * x % mod;
    p >>= 1;
    x = x * x % mod;
  }
  return ans;
}
long long Inv(long long x) {
  if (x < 0) x += mod;
  return Qpow(x, mod - 2);
}
void Solve() {
  for (int i = 0; i <= k + 1; ++i) {
    tot = tot * (n - i) % mod;
  }
  for (int i = 0; i <= k + 1; ++i) {
    long long up = tot * Inv(n - i) % mod;
    long long down = fac[i] * fac[k + 1 - i] * (((k + 1 - i) & 1) ? -1 : 1);
    long long tmp = up * Inv(down) % mod;
    if (tmp < 0) tmp += mod;
    ans += tmp * y[i];
    ans %= mod;
  }
}
int main() {
  cin >> n >> k;
  fac[0] = fav[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = (-mod / i * inv[mod % i] % mod) + mod;
    fav[i] = fav[i - 1] * inv[i] % mod;
  }
  y[0] = 0;
  for (int i = 1; i <= k + 1; ++i) {
    long long tmp = Qpow(i, k);
    y[i] = (y[i - 1] + tmp) % mod;
  }
  if (k + 1 >= n) return 0 * printf("%lld\n", y[n]);
  Solve();
  cout << ans << endl;
  return 0;
}

### Prompt

Generate a cpp solution to 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>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int n, k;
long long tot = 1, ans = 0;
long long y[N], fac[N], fav[N], inv[N];
long long Qpow(long long x, int p) {
  x %= mod;
  long long ans = 1;
  while (p) {
    if (p & 1) ans = ans * x % mod;
    p >>= 1;
    x = x * x % mod;
  }
  return ans;
}
long long Inv(long long x) {
  if (x < 0) x += mod;
  return Qpow(x, mod - 2);
}
void Solve() {
  for (int i = 0; i <= k + 1; ++i) {
    tot = tot * (n - i) % mod;
  }
  for (int i = 0; i <= k + 1; ++i) {
    long long up = tot * Inv(n - i) % mod;
    long long down = fac[i] * fac[k + 1 - i] * (((k + 1 - i) & 1) ? -1 : 1);
    long long tmp = up * Inv(down) % mod;
    if (tmp < 0) tmp += mod;
    ans += tmp * y[i];
    ans %= mod;
  }
}
int main() {
  cin >> n >> k;
  fac[0] = fav[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = (-mod / i * inv[mod % i] % mod) + mod;
    fav[i] = fav[i - 1] * inv[i] % mod;
  }
  y[0] = 0;
  for (int i = 1; i <= k + 1; ++i) {
    long long tmp = Qpow(i, k);
    y[i] = (y[i - 1] + tmp) % mod;
  }
  if (k + 1 >= n) return 0 * printf("%lld\n", y[n]);
  Solve();
  cout << ans << endl;
  return 0;
}

```