#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long nr = 1e6 + 500;
long long n, k;
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
long long inv(long long x) { return power(x, mod - 2); }
long long y[nr];
long long zheng[nr];
long long fu[nr];
long long fz;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k + 2; i++) {
    y[i] = power(i, k) + y[i - 1];
    y[i] %= mod;
  }
  zheng[0] = 1;
  fu[0] = 1;
  for (int i = 1; i <= k + 2; i++) {
    long long z = i % mod;
    long long f = (-i + mod) % mod;
    zheng[i] = zheng[i - 1] * z % mod;
    fu[i] = fu[i - 1] * f % mod;
  }
  fz = 1;
  for (int i = 1; i <= k + 2; i++) {
    if (n - i == 0) continue;
    fz = fz * (n - i) % mod;
    fz = (fz + mod) % mod;
  }
  long long ans = 0;
  for (int i = 1; i <= k + 2; i++) {
    if (k + 2 >= n && i != n) continue;
    long long FM = zheng[i - 1] * fu[k + 2 - i] % mod;
    FM = (FM + mod) % mod;
    long long FZ = fz * inv(n - i) % mod;
    FZ = (FZ + mod) % mod;
    if (k + 2 >= n) FZ = fz;
    ans += y[i] * FZ % mod * inv(FM) % mod;
    ans = (ans + mod) % mod;
  }
  cout << ans;
  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 long long mod = 1e9 + 7;
const long long nr = 1e6 + 500;
long long n, k;
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
long long inv(long long x) { return power(x, mod - 2); }
long long y[nr];
long long zheng[nr];
long long fu[nr];
long long fz;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k + 2; i++) {
    y[i] = power(i, k) + y[i - 1];
    y[i] %= mod;
  }
  zheng[0] = 1;
  fu[0] = 1;
  for (int i = 1; i <= k + 2; i++) {
    long long z = i % mod;
    long long f = (-i + mod) % mod;
    zheng[i] = zheng[i - 1] * z % mod;
    fu[i] = fu[i - 1] * f % mod;
  }
  fz = 1;
  for (int i = 1; i <= k + 2; i++) {
    if (n - i == 0) continue;
    fz = fz * (n - i) % mod;
    fz = (fz + mod) % mod;
  }
  long long ans = 0;
  for (int i = 1; i <= k + 2; i++) {
    if (k + 2 >= n && i != n) continue;
    long long FM = zheng[i - 1] * fu[k + 2 - i] % mod;
    FM = (FM + mod) % mod;
    long long FZ = fz * inv(n - i) % mod;
    FZ = (FZ + mod) % mod;
    if (k + 2 >= n) FZ = fz;
    ans += y[i] * FZ % mod * inv(FM) % mod;
    ans = (ans + mod) % mod;
  }
  cout << ans;
  return 0;
}

```