#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (1LL << 20) + 10, MOD = 1e9 + 7,
                INF = 0x3f3f3f3f3f3f3f3f;
long long N, K, ans, S[MAXN], pre[MAXN], suf[MAXN], fac[MAXN];
long long ks(long long, long long);
int main() {
  scanf("%lld%lld", &N, &K);
  pre[0] = suf[K + 3] = fac[0] = 1;
  for (long long i = 1; i <= K + 2; i++) S[i] = (S[i - 1] + ks(i, K)) % MOD;
  for (long long i = 1; i <= K + 2; i++) pre[i] = pre[i - 1] * (N - i) % MOD;
  for (long long i = K + 2; i; 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 (long long i = 1; i <= K + 2; i++) {
    long long fm = ks(fac[i - 1], MOD - 2) * ks(fac[K + 2 - i], MOD - 2) % MOD;
    long long fz = pre[i - 1] * suf[i + 1] % MOD;
    (ans += S[i] * fz % MOD * fm % MOD * ((K - i) & 1 ? -1 : 1) % MOD) %= MOD;
  }
  printf("%lld\n", (ans + MOD) % MOD);
  return 0;
}
long long ks(long long n, long long tim) {
  long long ret = 1;
  while (tim) {
    if (tim & 1) ret = ret * n % MOD;
    n = n * n % MOD;
    tim >>= 1;
  }
  return ret % MOD;
}

### 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 long long MAXN = (1LL << 20) + 10, MOD = 1e9 + 7,
                INF = 0x3f3f3f3f3f3f3f3f;
long long N, K, ans, S[MAXN], pre[MAXN], suf[MAXN], fac[MAXN];
long long ks(long long, long long);
int main() {
  scanf("%lld%lld", &N, &K);
  pre[0] = suf[K + 3] = fac[0] = 1;
  for (long long i = 1; i <= K + 2; i++) S[i] = (S[i - 1] + ks(i, K)) % MOD;
  for (long long i = 1; i <= K + 2; i++) pre[i] = pre[i - 1] * (N - i) % MOD;
  for (long long i = K + 2; i; 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 (long long i = 1; i <= K + 2; i++) {
    long long fm = ks(fac[i - 1], MOD - 2) * ks(fac[K + 2 - i], MOD - 2) % MOD;
    long long fz = pre[i - 1] * suf[i + 1] % MOD;
    (ans += S[i] * fz % MOD * fm % MOD * ((K - i) & 1 ? -1 : 1) % MOD) %= MOD;
  }
  printf("%lld\n", (ans + MOD) % MOD);
  return 0;
}
long long ks(long long n, long long tim) {
  long long ret = 1;
  while (tim) {
    if (tim & 1) ret = ret * n % MOD;
    n = n * n % MOD;
    tim >>= 1;
  }
  return ret % MOD;
}

```