#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const long long MOD = 1e9 + 7;
long long fac[MAXN], nxl[MAXN], nxr[MAXN], fun[MAXN];
long long qpow(long long a, long long n) {
  a %= MOD;
  long long res = 1;
  for (; n; n >>= 1) {
    if (n & 1) {
      res = res * a % MOD;
    }
    a = a * a % MOD;
  }
  return res;
}
long long inv(long long x) { return qpow(x, MOD - 2); }
int main() {
  int n, k;
  cin >> n >> k;
  fac[0] = 1;
  nxl[0] = n;
  nxr[k + 2] = 1;
  for (int i = 1; i <= k + 1; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    nxl[i] = nxl[i - 1] * (n - i) % MOD;
    fun[i] = qpow(i, k) + fun[i - 1] % MOD;
  }
  for (int i = k + 1; i >= 0; i--) {
    nxr[i] = nxr[i + 1] * (n - i) % MOD;
  }
  long long ans = 0;
  for (int i = 1; i <= k + 1; i++) {
    long long op = (k + 1 - i) & 1 == 1 ? -1 : 1;
    ans = (ans + op * fun[i] * nxl[i - 1] % MOD * nxr[i + 1] % MOD *
                     inv(fac[i]) % MOD * inv(fac[k + 1 - i]) % MOD) %
          MOD;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Your task is to create 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 MAXN = 1e6 + 5;
const long long MOD = 1e9 + 7;
long long fac[MAXN], nxl[MAXN], nxr[MAXN], fun[MAXN];
long long qpow(long long a, long long n) {
  a %= MOD;
  long long res = 1;
  for (; n; n >>= 1) {
    if (n & 1) {
      res = res * a % MOD;
    }
    a = a * a % MOD;
  }
  return res;
}
long long inv(long long x) { return qpow(x, MOD - 2); }
int main() {
  int n, k;
  cin >> n >> k;
  fac[0] = 1;
  nxl[0] = n;
  nxr[k + 2] = 1;
  for (int i = 1; i <= k + 1; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    nxl[i] = nxl[i - 1] * (n - i) % MOD;
    fun[i] = qpow(i, k) + fun[i - 1] % MOD;
  }
  for (int i = k + 1; i >= 0; i--) {
    nxr[i] = nxr[i + 1] * (n - i) % MOD;
  }
  long long ans = 0;
  for (int i = 1; i <= k + 1; i++) {
    long long op = (k + 1 - i) & 1 == 1 ? -1 : 1;
    ans = (ans + op * fun[i] * nxl[i - 1] % MOD * nxr[i + 1] % MOD *
                     inv(fac[i]) % MOD * inv(fac[k + 1 - i]) % MOD) %
          MOD;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}

```