#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
int inv1[maxn], inv2[maxn], fac[maxn];
int quickpow(int a, int b) {
  int ans = 1;
  for (; b >= 1; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * ans * a % mod;
  return ans;
}
int main() {
  int n, k, y = 0, ans = 0;
  cin >> n >> k;
  inv1[0] = inv2[k + 3] = fac[0] = 1;
  for (int i = 1; i <= k + 2; i++) inv1[i] = 1ll * inv1[i - 1] * (n - i) % mod;
  for (int i = k + 2; i >= 1; i--) inv2[i] = 1ll * inv2[i + 1] * (n - i) % mod;
  for (int i = 1; i <= k + 2; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  for (int i = 1; i <= k + 2; i++) {
    y = (y + quickpow(i, k)) % mod;
    int a = inv1[i - 1] * 1ll * inv2[i + 1] % mod;
    int b = fac[i - 1] * ((k - i) & 1 ? -1ll : 1ll) * fac[k + 2 - i] % mod;
    ans = (ans + 1ll * y * a % mod * quickpow(b, mod - 2) % mod) % mod;
  }
  cout << (ans + mod) % mod;
  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 mod = 1e9 + 7;
const int maxn = 1e6 + 10;
int inv1[maxn], inv2[maxn], fac[maxn];
int quickpow(int a, int b) {
  int ans = 1;
  for (; b >= 1; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * ans * a % mod;
  return ans;
}
int main() {
  int n, k, y = 0, ans = 0;
  cin >> n >> k;
  inv1[0] = inv2[k + 3] = fac[0] = 1;
  for (int i = 1; i <= k + 2; i++) inv1[i] = 1ll * inv1[i - 1] * (n - i) % mod;
  for (int i = k + 2; i >= 1; i--) inv2[i] = 1ll * inv2[i + 1] * (n - i) % mod;
  for (int i = 1; i <= k + 2; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  for (int i = 1; i <= k + 2; i++) {
    y = (y + quickpow(i, k)) % mod;
    int a = inv1[i - 1] * 1ll * inv2[i + 1] % mod;
    int b = fac[i - 1] * ((k - i) & 1 ? -1ll : 1ll) * fac[k + 2 - i] % mod;
    ans = (ans + 1ll * y * a % mod * quickpow(b, mod - 2) % mod) % mod;
  }
  cout << (ans + mod) % mod;
  return 0;
}

```