#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int pre[N], suf[N], inv[N];
inline int power(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) res = 1ll * res * a % mod;
  return res;
}
int main() {
  int n, m, s = 0, ans = 0;
  scanf("%d%d", &n, &m);
  if (m == 0) {
    printf("%d\n", n);
    return 0;
  }
  inv[1] = 1;
  for (int i = 2; i <= m + 1; i++)
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  inv[0] = 1;
  for (int i = 1; i <= m + 1; i++) inv[i] = 1ll * inv[i] * inv[i - 1] % mod;
  pre[0] = n;
  for (int i = 1; i <= m + 1; i++) pre[i] = 1ll * pre[i - 1] * (n - i) % mod;
  suf[m + 1] = n - (m + 1);
  for (int i = m; i >= 0; i--) suf[i] = 1ll * suf[i + 1] * (n - i) % mod;
  for (int i = 0; i <= m + 1; i++) {
    s = (s + power(i, m)) % mod;
    int delta =
        1ll * (i == 0 ? 1 : pre[i - 1]) * (i == m + 1 ? 1 : suf[i + 1]) % mod;
    delta = 1ll * delta * inv[i] % mod * inv[m + 1 - i] % mod;
    if ((m + 1 - i) & 1) delta = mod - delta;
    ans = (ans + 1ll * s * delta % mod) % mod;
  }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Your challenge is to write 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 pre[N], suf[N], inv[N];
inline int power(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) res = 1ll * res * a % mod;
  return res;
}
int main() {
  int n, m, s = 0, ans = 0;
  scanf("%d%d", &n, &m);
  if (m == 0) {
    printf("%d\n", n);
    return 0;
  }
  inv[1] = 1;
  for (int i = 2; i <= m + 1; i++)
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  inv[0] = 1;
  for (int i = 1; i <= m + 1; i++) inv[i] = 1ll * inv[i] * inv[i - 1] % mod;
  pre[0] = n;
  for (int i = 1; i <= m + 1; i++) pre[i] = 1ll * pre[i - 1] * (n - i) % mod;
  suf[m + 1] = n - (m + 1);
  for (int i = m; i >= 0; i--) suf[i] = 1ll * suf[i + 1] * (n - i) % mod;
  for (int i = 0; i <= m + 1; i++) {
    s = (s + power(i, m)) % mod;
    int delta =
        1ll * (i == 0 ? 1 : pre[i - 1]) * (i == m + 1 ? 1 : suf[i + 1]) % mod;
    delta = 1ll * delta * inv[i] % mod * inv[m + 1 - i] % mod;
    if ((m + 1 - i) & 1) delta = mod - delta;
    ans = (ans + 1ll * s * delta % mod) % mod;
  }
  printf("%d\n", ans);
  return 0;
}

```