#include <bits/stdc++.h>
using namespace std;
long long n;
int k;
long long sum[1000002], fact[1000002];
long long modpow(long long a, long long p) {
  return p ? ((p & 1) ? a * modpow(a, p ^ 1) % 1000000007
                      : modpow(a * a % 1000000007, p >> 1))
           : 1;
}
long long invmod(long long a) { return modpow(a, 1000000007 - 2); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i < k + 2; i++) {
    sum[i] = (sum[i - 1] + modpow(i, k)) % 1000000007;
  }
  fact[0] = 1;
  for (int i = 1; i < k + 2; i++) {
    fact[i] = (fact[i - 1] * i) % 1000000007;
  }
  if (n < k + 2) {
    cout << sum[n] << endl;
    return 0;
  }
  long long res = 0;
  long long prod = 1;
  for (int i = 0; i < k + 2; i++) {
    prod = (prod * (n - i)) % 1000000007;
  }
  for (int i = 0; i < k + 2; i++) {
    long long num = prod * invmod(n - i) % 1000000007;
    long long den = fact[i];
    if (i - (k + 1) > 0) {
      den = den * invmod(fact[i - (k + 1) - 1]) % 1000000007;
    } else if (i - (k + 1) < 0) {
      den = den * fact[(k + 1) - i] % 1000000007;
      if ((k + 1 - i) % 2 == 1) {
        den = 1000000007 - den;
      }
    }
    long long frac = num * invmod(den) % 1000000007;
    res = (res + (frac * sum[i]) % 1000000007) % 1000000007;
  }
  cout << res << endl;
  return 0;
}

### 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;
long long n;
int k;
long long sum[1000002], fact[1000002];
long long modpow(long long a, long long p) {
  return p ? ((p & 1) ? a * modpow(a, p ^ 1) % 1000000007
                      : modpow(a * a % 1000000007, p >> 1))
           : 1;
}
long long invmod(long long a) { return modpow(a, 1000000007 - 2); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i < k + 2; i++) {
    sum[i] = (sum[i - 1] + modpow(i, k)) % 1000000007;
  }
  fact[0] = 1;
  for (int i = 1; i < k + 2; i++) {
    fact[i] = (fact[i - 1] * i) % 1000000007;
  }
  if (n < k + 2) {
    cout << sum[n] << endl;
    return 0;
  }
  long long res = 0;
  long long prod = 1;
  for (int i = 0; i < k + 2; i++) {
    prod = (prod * (n - i)) % 1000000007;
  }
  for (int i = 0; i < k + 2; i++) {
    long long num = prod * invmod(n - i) % 1000000007;
    long long den = fact[i];
    if (i - (k + 1) > 0) {
      den = den * invmod(fact[i - (k + 1) - 1]) % 1000000007;
    } else if (i - (k + 1) < 0) {
      den = den * fact[(k + 1) - i] % 1000000007;
      if ((k + 1 - i) % 2 == 1) {
        den = 1000000007 - den;
      }
    }
    long long frac = num * invmod(den) % 1000000007;
    res = (res + (frac * sum[i]) % 1000000007) % 1000000007;
  }
  cout << res << endl;
  return 0;
}

```