#include <bits/stdc++.h>
using namespace std;
namespace IO {
const unsigned int Buffsize = 1 << 15, Output = 1 << 23;
static char Ch[Buffsize], *S = Ch, *T = Ch;
inline char getc() {
  return ((S == T) && (T = (S = Ch) + fread(Ch, 1, Buffsize, stdin), S == T)
              ? 0
              : *S++);
}
static char Out[Output], *nowps = Out;
inline void flush() {
  fwrite(Out, 1, nowps - Out, stdout);
  nowps = Out;
}
template <typename T>
inline void read(T& x) {
  x = 0;
  static char ch;
  T f = 1;
  for (ch = getc(); !isdigit(ch); ch = getc())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getc()) x = x * 10 + (ch ^ 48);
  x *= f;
}
template <typename T>
inline void write(T x, char ch = '\n') {
  if (!x) *nowps++ = '0';
  if (x < 0) *nowps++ = '-', x = -x;
  static unsigned int sta[111], tp;
  for (tp = 0; x; x /= 10) sta[++tp] = x % 10;
  for (; tp; *nowps++ = sta[tp--] ^ 48)
    ;
  *nowps++ = ch;
}
}  // namespace IO
using namespace IO;
inline void file() {}
const int MAXN = 1e6 + 7;
static int n, k;
inline void init() {
  read(n);
  read(k);
}
const int mod = 1e9 + 7;
inline int ad(int u, int v) { return (u += v) >= mod ? u - mod : u; }
inline int power(int u, int v) {
  static int sm;
  for (sm = 1; v; v >>= 1, u = (unsigned long long)u * u % mod)
    if (v & 1) sm = (unsigned long long)sm * u % mod;
  return sm;
}
static int pri[MAXN], e, y[MAXN], is[MAXN], inv[MAXN];
inline void predone(int lim) {
  static int z;
  y[1] = 1;
  inv[0] = inv[1] = 1;
  for (register int i = (2); i <= (lim); ++i) {
    if (!is[i]) y[i] = power(i, lim - 1), inv[i] = power(i, mod - 2);
    for (register int j = 1; j <= e && (z = i * pri[j]) <= lim; ++j) {
      is[z] = 1;
      y[z] = (unsigned long long)y[i] * y[pri[j]] % mod;
      inv[z] = (unsigned long long)inv[i] * inv[pri[j]] % mod;
      if (i % pri[j] == 0) break;
    }
  }
  for (register int i = (2); i <= (lim); ++i)
    y[i] = ad(y[i], y[i - 1]),
    inv[i] = (unsigned long long)inv[i] * inv[i - 1] % mod;
}
static int pre[MAXN], suf[MAXN];
inline int Lagrange(int x) {
  if (x <= k + 1) return y[x];
  pre[0] = x;
  suf[k + 2] = 1;
  for (register int i = (1); i <= (k); ++i)
    pre[i] = (unsigned long long)pre[i - 1] * (x - i) % mod;
  for (register int i = (k + 1); i >= (1); --i)
    suf[i] = (unsigned long long)suf[i + 1] * (x - i) % mod;
  static int sm, sp;
  sm = 0;
  for (register int i = (1); i <= (k + 1); ++i) {
    sp = (unsigned long long)pre[i - 1] * suf[i + 1] % mod * inv[i] % mod *
         inv[k + 1 - i] % mod * y[i] % mod;
    sm = (k + 1 - i) & 1 ? ad(sm, mod - sp) : ad(sm, sp);
  }
  return sm;
}
inline void solve() {
  predone(k + 1);
  printf("%d\n", Lagrange(n));
}
int main() {
  init();
  solve();
  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;
namespace IO {
const unsigned int Buffsize = 1 << 15, Output = 1 << 23;
static char Ch[Buffsize], *S = Ch, *T = Ch;
inline char getc() {
  return ((S == T) && (T = (S = Ch) + fread(Ch, 1, Buffsize, stdin), S == T)
              ? 0
              : *S++);
}
static char Out[Output], *nowps = Out;
inline void flush() {
  fwrite(Out, 1, nowps - Out, stdout);
  nowps = Out;
}
template <typename T>
inline void read(T& x) {
  x = 0;
  static char ch;
  T f = 1;
  for (ch = getc(); !isdigit(ch); ch = getc())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getc()) x = x * 10 + (ch ^ 48);
  x *= f;
}
template <typename T>
inline void write(T x, char ch = '\n') {
  if (!x) *nowps++ = '0';
  if (x < 0) *nowps++ = '-', x = -x;
  static unsigned int sta[111], tp;
  for (tp = 0; x; x /= 10) sta[++tp] = x % 10;
  for (; tp; *nowps++ = sta[tp--] ^ 48)
    ;
  *nowps++ = ch;
}
}  // namespace IO
using namespace IO;
inline void file() {}
const int MAXN = 1e6 + 7;
static int n, k;
inline void init() {
  read(n);
  read(k);
}
const int mod = 1e9 + 7;
inline int ad(int u, int v) { return (u += v) >= mod ? u - mod : u; }
inline int power(int u, int v) {
  static int sm;
  for (sm = 1; v; v >>= 1, u = (unsigned long long)u * u % mod)
    if (v & 1) sm = (unsigned long long)sm * u % mod;
  return sm;
}
static int pri[MAXN], e, y[MAXN], is[MAXN], inv[MAXN];
inline void predone(int lim) {
  static int z;
  y[1] = 1;
  inv[0] = inv[1] = 1;
  for (register int i = (2); i <= (lim); ++i) {
    if (!is[i]) y[i] = power(i, lim - 1), inv[i] = power(i, mod - 2);
    for (register int j = 1; j <= e && (z = i * pri[j]) <= lim; ++j) {
      is[z] = 1;
      y[z] = (unsigned long long)y[i] * y[pri[j]] % mod;
      inv[z] = (unsigned long long)inv[i] * inv[pri[j]] % mod;
      if (i % pri[j] == 0) break;
    }
  }
  for (register int i = (2); i <= (lim); ++i)
    y[i] = ad(y[i], y[i - 1]),
    inv[i] = (unsigned long long)inv[i] * inv[i - 1] % mod;
}
static int pre[MAXN], suf[MAXN];
inline int Lagrange(int x) {
  if (x <= k + 1) return y[x];
  pre[0] = x;
  suf[k + 2] = 1;
  for (register int i = (1); i <= (k); ++i)
    pre[i] = (unsigned long long)pre[i - 1] * (x - i) % mod;
  for (register int i = (k + 1); i >= (1); --i)
    suf[i] = (unsigned long long)suf[i + 1] * (x - i) % mod;
  static int sm, sp;
  sm = 0;
  for (register int i = (1); i <= (k + 1); ++i) {
    sp = (unsigned long long)pre[i - 1] * suf[i + 1] % mod * inv[i] % mod *
         inv[k + 1 - i] % mod * y[i] % mod;
    sm = (k + 1 - i) & 1 ? ad(sm, mod - sp) : ad(sm, sp);
  }
  return sm;
}
inline void solve() {
  predone(k + 1);
  printf("%d\n", Lagrange(n));
}
int main() {
  init();
  solve();
  return 0;
}

```