#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int p = 1e9 + 7;
int n, k, suf[N], pre[N], fac[N];
void read(int &x) {
  int flg = 1;
  x = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') flg = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= flg;
}
int pow(int x, int y) {
  long long a = x, ret = 1;
  for (; y; y >>= 1, a = a * a % p)
    if (y & 1) ret = ret * a % p;
  return ret;
}
int main() {
  read(n), read(k);
  suf[k + 3] = pre[0] = fac[0] = 1;
  for (int i = 1; i <= k + 2; ++i) pre[i] = 1ll * pre[i - 1] * (n - i) % p;
  for (int i = k + 2; i >= 1; --i) suf[i] = 1ll * suf[i + 1] * (n - i) % p;
  for (int i = 1; i <= k + 2; ++i) fac[i] = 1ll * fac[i - 1] * i % p;
  int y = 0, f, s, ans = 0;
  for (int i = 1; i <= k + 2; ++i) {
    y = (1ll * y + pow(i, k)) % p;
    s = 1ll * pre[i - 1] * suf[i + 1] % p;
    f = 1ll * fac[i - 1] * ((k - i) & 1 ? -1ll : 1ll) * fac[k + 2 - i] % p;
    ans = (1ll * ans + 1ll * y * s % p * pow(f, p - 2) % p) % p;
  }
  printf("%d\n", (ans + p) % p);
  return 0;
}

### Prompt

Please formulate 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 + 5;
const int p = 1e9 + 7;
int n, k, suf[N], pre[N], fac[N];
void read(int &x) {
  int flg = 1;
  x = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') flg = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= flg;
}
int pow(int x, int y) {
  long long a = x, ret = 1;
  for (; y; y >>= 1, a = a * a % p)
    if (y & 1) ret = ret * a % p;
  return ret;
}
int main() {
  read(n), read(k);
  suf[k + 3] = pre[0] = fac[0] = 1;
  for (int i = 1; i <= k + 2; ++i) pre[i] = 1ll * pre[i - 1] * (n - i) % p;
  for (int i = k + 2; i >= 1; --i) suf[i] = 1ll * suf[i + 1] * (n - i) % p;
  for (int i = 1; i <= k + 2; ++i) fac[i] = 1ll * fac[i - 1] * i % p;
  int y = 0, f, s, ans = 0;
  for (int i = 1; i <= k + 2; ++i) {
    y = (1ll * y + pow(i, k)) % p;
    s = 1ll * pre[i - 1] * suf[i + 1] % p;
    f = 1ll * fac[i - 1] * ((k - i) & 1 ? -1ll : 1ll) * fac[k + 2 - i] % p;
    ans = (1ll * ans + 1ll * y * s % p * pow(f, p - 2) % p) % p;
  }
  printf("%d\n", (ans + p) % p);
  return 0;
}

```