#include <bits/stdc++.h>
const int MARX = 1e6 + 10;
const long long mod = 1e9 + 7;
long long N, K, tmp, ans, pre[MARX], suf[MARX], fac[MARX];
inline int read() {
  int f = 1, w = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) w = (w << 3) + (w << 1) + (ch ^ '0');
  return f * w;
}
long long qpow(long long x, long long y, long long Mod) {
  long long ret = 1;
  for (; y; x = x * x % Mod, y >>= 1)
    if (y & 1) ret = ret * x % Mod;
  return ret;
}
int main() {
  N = read(), K = read();
  pre[0] = suf[K + 3] = fac[0] = 1;
  for (long long i = 1; i <= K + 2; i++) pre[i] = pre[i - 1] * (N - i) % mod;
  for (long long i = K + 2; i >= 1; i--) suf[i] = suf[i + 1] * (N - i) % mod;
  for (long long i = 1; i <= K + 2; i++) fac[i] = fac[i - 1] * i % mod;
  for (int i = 1; i <= K + 2; i++) {
    tmp = (tmp + qpow(i, K, mod)) % mod;
    long long a = pre[i - 1] * suf[i + 1] % mod;
    long long b = fac[i - 1] * ((K - i) & 1 ? -1 : 1) * fac[K + 2 - i] % mod;
    ans = (ans + tmp * a % mod * qpow(b, mod - 2, mod) % mod) % mod;
  }
  printf("%lld\n", (ans + mod) % mod);
  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>
const int MARX = 1e6 + 10;
const long long mod = 1e9 + 7;
long long N, K, tmp, ans, pre[MARX], suf[MARX], fac[MARX];
inline int read() {
  int f = 1, w = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) w = (w << 3) + (w << 1) + (ch ^ '0');
  return f * w;
}
long long qpow(long long x, long long y, long long Mod) {
  long long ret = 1;
  for (; y; x = x * x % Mod, y >>= 1)
    if (y & 1) ret = ret * x % Mod;
  return ret;
}
int main() {
  N = read(), K = read();
  pre[0] = suf[K + 3] = fac[0] = 1;
  for (long long i = 1; i <= K + 2; i++) pre[i] = pre[i - 1] * (N - i) % mod;
  for (long long i = K + 2; i >= 1; i--) suf[i] = suf[i + 1] * (N - i) % mod;
  for (long long i = 1; i <= K + 2; i++) fac[i] = fac[i - 1] * i % mod;
  for (int i = 1; i <= K + 2; i++) {
    tmp = (tmp + qpow(i, K, mod)) % mod;
    long long a = pre[i - 1] * suf[i + 1] % mod;
    long long b = fac[i - 1] * ((K - i) & 1 ? -1 : 1) * fac[K + 2 - i] % mod;
    ans = (ans + tmp * a % mod * qpow(b, mod - 2, mod) % mod) % mod;
  }
  printf("%lld\n", (ans + mod) % mod);
  return 0;
}

```