#include <bits/stdc++.h>
using namespace std;
const int p = 1000000007;
int qpow(int a, int k) {
  int ans = 1;
  while (k) {
    if (k & 1) ans = 1LL * ans * a % p;
    a = 1LL * a * a % p;
    k >>= 1;
  }
  return ans;
}
int typ;
int Y[1000005], inv[1000005], ifac[1000005];
int N, K;
int main() {
  scanf("%d%d", &N, &K);
  if (N <= K + 1) {
    int ans = 0;
    for (int i = 1; i <= N; i++) ans = (ans + qpow(i, K)) % p;
    printf("%d\n", ans);
    return 0;
  }
  Y[0] = 0, ifac[0] = 1;
  for (int i = 1; i <= K + 1; i++)
    Y[i] = (Y[i - 1] + qpow(i, K)) % p,
    inv[i] = (i == 1 ? 1 : 1LL * (p - p / i) * inv[p % i] % p),
    ifac[i] = 1LL * ifac[i - 1] * inv[i] % p;
  int D = 1;
  for (int i = 0; i <= K + 1; i++) D = 1LL * D * ((N - i) % p) % p;
  int ans = 0;
  for (int i = 0; i <= K + 1; i++)
    if ((K + 1 - i) & 1)
      ans = (ans -
             1LL * D * qpow((N - i) % p, p - 2) % p * ifac[i] % p *
                 ifac[K + 1 - i] % p * Y[i] % p +
             p) %
            p;
    else
      ans = (ans + 1LL * D * qpow((N - i) % p, p - 2) % p * ifac[i] % p *
                       ifac[K + 1 - i] % p * Y[i] % p) %
            p;
  printf("%d\n", ans);
  return 0;
}

### Prompt

Create a solution in cpp for 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 p = 1000000007;
int qpow(int a, int k) {
  int ans = 1;
  while (k) {
    if (k & 1) ans = 1LL * ans * a % p;
    a = 1LL * a * a % p;
    k >>= 1;
  }
  return ans;
}
int typ;
int Y[1000005], inv[1000005], ifac[1000005];
int N, K;
int main() {
  scanf("%d%d", &N, &K);
  if (N <= K + 1) {
    int ans = 0;
    for (int i = 1; i <= N; i++) ans = (ans + qpow(i, K)) % p;
    printf("%d\n", ans);
    return 0;
  }
  Y[0] = 0, ifac[0] = 1;
  for (int i = 1; i <= K + 1; i++)
    Y[i] = (Y[i - 1] + qpow(i, K)) % p,
    inv[i] = (i == 1 ? 1 : 1LL * (p - p / i) * inv[p % i] % p),
    ifac[i] = 1LL * ifac[i - 1] * inv[i] % p;
  int D = 1;
  for (int i = 0; i <= K + 1; i++) D = 1LL * D * ((N - i) % p) % p;
  int ans = 0;
  for (int i = 0; i <= K + 1; i++)
    if ((K + 1 - i) & 1)
      ans = (ans -
             1LL * D * qpow((N - i) % p, p - 2) % p * ifac[i] % p *
                 ifac[K + 1 - i] % p * Y[i] % p +
             p) %
            p;
    else
      ans = (ans + 1LL * D * qpow((N - i) % p, p - 2) % p * ifac[i] % p *
                       ifac[K + 1 - i] % p * Y[i] % p) %
            p;
  printf("%d\n", ans);
  return 0;
}

```