#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void chkmin(T &a, T b) {
  a < b ? a : a = b;
}
template <typename T>
inline void chkmax(T &a, T b) {
  a < b ? a = b : a;
}
namespace fast_IO {
inline int read_int() {
  register int ret = 0, f = 1;
  register char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = (ret << 1) + (ret << 3) + int(c - 48);
    c = getchar();
  }
  return ret * f;
}
}  // namespace fast_IO
using namespace fast_IO;
int N, K;
long long pl[1000005], pr[1000005], fac[1000005];
inline long long fast_power(long long x, long long k) {
  long long res = 1;
  while (k) {
    if (k & 1) res *= x, res %= 1000000007;
    x *= x, x %= 1000000007, k >>= 1;
  }
  return res;
}
inline long long inv(long long x) { return fast_power(x, 1000000007 - 2); }
inline void init() {
  N = read_int(), K = read_int();
  long long ans = 0, y = 0;
  pl[0] = pr[K + 3] = fac[0] = 1;
  for (register int i = 1; i <= K + 2; i++)
    pl[i] = pl[i - 1] * (N - i) % 1000000007;
  for (register int i = K + 2; i >= 1; i--)
    pr[i] = pr[i + 1] * (N - i) % 1000000007;
  for (register int i = 1; i <= K + 2; i++)
    fac[i] = fac[i - 1] * i % 1000000007;
  for (register int i = 1; i <= K + 2; i++) {
    y = (y + fast_power(i, K)) % 1000000007;
    long long a = pl[i - 1] * pr[i + 1] % 1000000007;
    long long b =
        fac[i - 1] * ((K - i) & 1 ? -1ll : 1ll) * fac[K + 2 - i] % 1000000007;
    ans = (ans + 1ll * y * a % 1000000007 * inv(b) % 1000000007) % 1000000007;
  }
  printf("%lld\n", (ans + 1000000007) % 1000000007);
}
int main() {
  init();
  return 0;
}

### Prompt

In Cpp, your task is to solve 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;
template <typename T>
inline void chkmin(T &a, T b) {
  a < b ? a : a = b;
}
template <typename T>
inline void chkmax(T &a, T b) {
  a < b ? a = b : a;
}
namespace fast_IO {
inline int read_int() {
  register int ret = 0, f = 1;
  register char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = (ret << 1) + (ret << 3) + int(c - 48);
    c = getchar();
  }
  return ret * f;
}
}  // namespace fast_IO
using namespace fast_IO;
int N, K;
long long pl[1000005], pr[1000005], fac[1000005];
inline long long fast_power(long long x, long long k) {
  long long res = 1;
  while (k) {
    if (k & 1) res *= x, res %= 1000000007;
    x *= x, x %= 1000000007, k >>= 1;
  }
  return res;
}
inline long long inv(long long x) { return fast_power(x, 1000000007 - 2); }
inline void init() {
  N = read_int(), K = read_int();
  long long ans = 0, y = 0;
  pl[0] = pr[K + 3] = fac[0] = 1;
  for (register int i = 1; i <= K + 2; i++)
    pl[i] = pl[i - 1] * (N - i) % 1000000007;
  for (register int i = K + 2; i >= 1; i--)
    pr[i] = pr[i + 1] * (N - i) % 1000000007;
  for (register int i = 1; i <= K + 2; i++)
    fac[i] = fac[i - 1] * i % 1000000007;
  for (register int i = 1; i <= K + 2; i++) {
    y = (y + fast_power(i, K)) % 1000000007;
    long long a = pl[i - 1] * pr[i + 1] % 1000000007;
    long long b =
        fac[i - 1] * ((K - i) & 1 ? -1ll : 1ll) * fac[K + 2 - i] % 1000000007;
    ans = (ans + 1ll * y * a % 1000000007 * inv(b) % 1000000007) % 1000000007;
  }
  printf("%lld\n", (ans + 1000000007) % 1000000007);
}
int main() {
  init();
  return 0;
}

```