#include <bits/stdc++.h>
using namespace std;
namespace lgr {
short factor[1000010];
long long P[1000010], S[1000010], ar[1000010], inv[1000010];
inline long long expo(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (long long)res * a % 1000000007;
    a = (long long)a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
long long lagrange(long long n, long long k) {
  if (!k) return (n % 1000000007);
  long long i, j, x, res = 0;
  if (!inv[0]) {
    for (i = 2, x = 1; i < 1000010; i++) x = (long long)x * i % 1000000007;
    inv[1000010 - 1] = expo(x, 1000000007 - 2);
    for (i = 1000010 - 2; i >= 0; i--)
      inv[i] = ((long long)inv[i + 1] * (i + 1)) % 1000000007;
  }
  k++;
  for (i = 0; i <= k; i++) factor[i] = 0;
  for (i = 4; i <= k; i += 2) factor[i] = 2;
  for (i = 3; (i * i) <= k; i += 2) {
    if (!factor[i]) {
      for (j = (i * i), x = i << 1; j <= k; j += x) {
        factor[j] = i;
      }
    }
  }
  for (ar[1] = 1, ar[0] = 0, i = 2; i <= k; i++) {
    if (!factor[i])
      ar[i] = expo(i, k - 1);
    else
      ar[i] = ((long long)ar[factor[i]] * ar[i / factor[i]]) % 1000000007;
  }
  for (i = 1; i <= k; i++) {
    ar[i] += ar[i - 1];
    if (ar[i] >= 1000000007) ar[i] -= 1000000007;
  }
  if (n <= k) return ar[n];
  P[0] = 1, S[k] = 1;
  for (i = 1; i <= k; i++)
    P[i] = ((long long)P[i - 1] * ((n - i + 1) % 1000000007)) % 1000000007;
  for (i = k - 1; i >= 0; i--)
    S[i] = ((long long)S[i + 1] * ((n - i - 1) % 1000000007)) % 1000000007;
  for (i = 0; i <= k; i++) {
    x = (long long)ar[i] * P[i] % 1000000007 * S[i] % 1000000007 * inv[k - i] %
        1000000007 * inv[i] % 1000000007;
    if ((k - i) & 1) {
      res -= x;
      if (res < 0) res += 1000000007;
    } else {
      res += x;
      if (res >= 1000000007) res -= 1000000007;
    }
  }
  return (res % 1000000007);
}
}  // namespace lgr
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  cout << lgr::lagrange(n, k) << '\n';
}

### Prompt

Please create a solution in Cpp 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 lgr {
short factor[1000010];
long long P[1000010], S[1000010], ar[1000010], inv[1000010];
inline long long expo(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (long long)res * a % 1000000007;
    a = (long long)a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
long long lagrange(long long n, long long k) {
  if (!k) return (n % 1000000007);
  long long i, j, x, res = 0;
  if (!inv[0]) {
    for (i = 2, x = 1; i < 1000010; i++) x = (long long)x * i % 1000000007;
    inv[1000010 - 1] = expo(x, 1000000007 - 2);
    for (i = 1000010 - 2; i >= 0; i--)
      inv[i] = ((long long)inv[i + 1] * (i + 1)) % 1000000007;
  }
  k++;
  for (i = 0; i <= k; i++) factor[i] = 0;
  for (i = 4; i <= k; i += 2) factor[i] = 2;
  for (i = 3; (i * i) <= k; i += 2) {
    if (!factor[i]) {
      for (j = (i * i), x = i << 1; j <= k; j += x) {
        factor[j] = i;
      }
    }
  }
  for (ar[1] = 1, ar[0] = 0, i = 2; i <= k; i++) {
    if (!factor[i])
      ar[i] = expo(i, k - 1);
    else
      ar[i] = ((long long)ar[factor[i]] * ar[i / factor[i]]) % 1000000007;
  }
  for (i = 1; i <= k; i++) {
    ar[i] += ar[i - 1];
    if (ar[i] >= 1000000007) ar[i] -= 1000000007;
  }
  if (n <= k) return ar[n];
  P[0] = 1, S[k] = 1;
  for (i = 1; i <= k; i++)
    P[i] = ((long long)P[i - 1] * ((n - i + 1) % 1000000007)) % 1000000007;
  for (i = k - 1; i >= 0; i--)
    S[i] = ((long long)S[i + 1] * ((n - i - 1) % 1000000007)) % 1000000007;
  for (i = 0; i <= k; i++) {
    x = (long long)ar[i] * P[i] % 1000000007 * S[i] % 1000000007 * inv[k - i] %
        1000000007 * inv[i] % 1000000007;
    if ((k - i) & 1) {
      res -= x;
      if (res < 0) res += 1000000007;
    } else {
      res += x;
      if (res >= 1000000007) res -= 1000000007;
    }
  }
  return (res % 1000000007);
}
}  // namespace lgr
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  cout << lgr::lagrange(n, k) << '\n';
}

```