#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int mod = 1e9 + 7;
inline int ksm(int x, int k) {
  int s = 1;
  for (; k; k >>= 1, x = 1ll * x * x % mod)
    if (k & 1) s = 1ll * s * x % mod;
  return s;
}
int n, k, f[1000005], fac[1000005];
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= k + 2; i++) f[i] = (f[i - 1] + ksm(i, k)) % mod;
  if (n <= k + 2) {
    cout << f[n] << "\n";
    return 0;
  }
  fac[0] = 1;
  for (int i = 1; i <= k + 2; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  int L = 1, ans = 0;
  for (int i = 1; i <= k + 2; i++) L = 1ll * L * (n - i) % mod;
  for (int i = 1; i <= k + 2; i++) {
    int div = ksm(n - i, mod - 2),
        w = ksm(1ll * fac[i - 1] * fac[k + 2 - i] % mod, mod - 2);
    int sign = (k + 2 - i) % 2 ? -1 : 1;
    ans = (ans + 1ll * sign * w * div % mod * f[i] % mod) % mod;
  }
  ans = (ans + mod) % mod;
  ans = 1ll * ans * L % mod;
  cout << ans << "\n";
  return 0;
}

### Prompt

Your task is to create 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;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int mod = 1e9 + 7;
inline int ksm(int x, int k) {
  int s = 1;
  for (; k; k >>= 1, x = 1ll * x * x % mod)
    if (k & 1) s = 1ll * s * x % mod;
  return s;
}
int n, k, f[1000005], fac[1000005];
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= k + 2; i++) f[i] = (f[i - 1] + ksm(i, k)) % mod;
  if (n <= k + 2) {
    cout << f[n] << "\n";
    return 0;
  }
  fac[0] = 1;
  for (int i = 1; i <= k + 2; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  int L = 1, ans = 0;
  for (int i = 1; i <= k + 2; i++) L = 1ll * L * (n - i) % mod;
  for (int i = 1; i <= k + 2; i++) {
    int div = ksm(n - i, mod - 2),
        w = ksm(1ll * fac[i - 1] * fac[k + 2 - i] % mod, mod - 2);
    int sign = (k + 2 - i) % 2 ? -1 : 1;
    ans = (ans + 1ll * sign * w * div % mod * f[i] % mod) % mod;
  }
  ans = (ans + mod) % mod;
  ans = 1ll * ans * L % mod;
  cout << ans << "\n";
  return 0;
}

```