#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e6 + 5;
long long inv[N + 5], s[N + 5], p[N + 5], y[N + 5];
long long qm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
void init() {
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= N; i++) inv[i] = inv[i - 1] * i % mod;
  inv[N] = qm(inv[N], mod - 2);
  for (int i = N - 1; i >= 2; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
long long lag(int n, int k) {
  for (int i = 1; i <= k + 1; i++) y[i] = (y[i - 1] + qm(i, k)) % mod;
  k++;
  p[0] = n;
  s[k + 1] = 1;
  for (int i = 1; i <= k - 1; i++) p[i] = (n - i) * p[i - 1] % mod;
  for (int i = k; i >= 1; i--) s[i] = (n - i) * s[i + 1] % mod;
  long long ans = 0;
  for (int i = 1; i <= k; i++)
    ans = (ans + y[i] * p[i - 1] % mod * s[i + 1] % mod * inv[i] % mod *
                     (((k - i) & 1) ? -1 : 1) * inv[k - i]) %
          mod;
  return (ans + mod) % mod;
}
int main() {
  init();
  int n, k;
  scanf("%d%d", &n, &k);
  printf("%lld\n", lag(n, k));
  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;
const int mod = 1e9 + 7, N = 1e6 + 5;
long long inv[N + 5], s[N + 5], p[N + 5], y[N + 5];
long long qm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
void init() {
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= N; i++) inv[i] = inv[i - 1] * i % mod;
  inv[N] = qm(inv[N], mod - 2);
  for (int i = N - 1; i >= 2; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
long long lag(int n, int k) {
  for (int i = 1; i <= k + 1; i++) y[i] = (y[i - 1] + qm(i, k)) % mod;
  k++;
  p[0] = n;
  s[k + 1] = 1;
  for (int i = 1; i <= k - 1; i++) p[i] = (n - i) * p[i - 1] % mod;
  for (int i = k; i >= 1; i--) s[i] = (n - i) * s[i + 1] % mod;
  long long ans = 0;
  for (int i = 1; i <= k; i++)
    ans = (ans + y[i] * p[i - 1] % mod * s[i + 1] % mod * inv[i] % mod *
                     (((k - i) & 1) ? -1 : 1) * inv[k - i]) %
          mod;
  return (ans + mod) % mod;
}
int main() {
  init();
  int n, k;
  scanf("%d%d", &n, &k);
  printf("%lld\n", lag(n, k));
  return 0;
}

```