#include <bits/stdc++.h>
using namespace std;
int n, k;
long long y, L[2000000], R[2000000], jc[2000000], ans;
long long ksm(int x, int y) {
  long long ans = 1, now = x;
  for (int i = y; i; i >>= 1, now = now * now % 1000000007)
    if (i & 1) ans = ans * now % 1000000007;
  return ans;
}
long long rev(long long x) {
  if (x == 1) return 1;
  return (1000000007 - 1000000007 / x) * rev(1000000007 % x) % 1000000007;
}
int main() {
  scanf("%d%d", &n, &k);
  L[0] = R[k + 3] = jc[0] = 1;
  for (int i = 1; i <= k + 2; i++) L[i] = L[i - 1] * (n - i) % 1000000007;
  for (int i = k + 2; i >= 1; i--) R[i] = R[i + 1] * (n - i) % 1000000007;
  for (int i = 1; i <= k + 2; i++) jc[i] = jc[i - 1] * i % 1000000007;
  for (int i = 1; i <= k + 2; i++) {
    y = (y + ksm(i, k)) % 1000000007;
    long long A = L[i - 1] * R[i + 1] % 1000000007;
    long long B = jc[i - 1] * jc[k + 2 - i] % 1000000007;
    ans = (ans +
           A * rev(B) % 1000000007 * y % 1000000007 *
               (((k - i) & 1) ? -1ll : 1ll) +
           1000000007) %
          1000000007;
  }
  printf("%lld", ans);
  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;
int n, k;
long long y, L[2000000], R[2000000], jc[2000000], ans;
long long ksm(int x, int y) {
  long long ans = 1, now = x;
  for (int i = y; i; i >>= 1, now = now * now % 1000000007)
    if (i & 1) ans = ans * now % 1000000007;
  return ans;
}
long long rev(long long x) {
  if (x == 1) return 1;
  return (1000000007 - 1000000007 / x) * rev(1000000007 % x) % 1000000007;
}
int main() {
  scanf("%d%d", &n, &k);
  L[0] = R[k + 3] = jc[0] = 1;
  for (int i = 1; i <= k + 2; i++) L[i] = L[i - 1] * (n - i) % 1000000007;
  for (int i = k + 2; i >= 1; i--) R[i] = R[i + 1] * (n - i) % 1000000007;
  for (int i = 1; i <= k + 2; i++) jc[i] = jc[i - 1] * i % 1000000007;
  for (int i = 1; i <= k + 2; i++) {
    y = (y + ksm(i, k)) % 1000000007;
    long long A = L[i - 1] * R[i + 1] % 1000000007;
    long long B = jc[i - 1] * jc[k + 2 - i] % 1000000007;
    ans = (ans +
           A * rev(B) % 1000000007 * y % 1000000007 *
               (((k - i) & 1) ? -1ll : 1ll) +
           1000000007) %
          1000000007;
  }
  printf("%lld", ans);
  return 0;
}

```