#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void read(Tp &x) {
  static char c;
  static bool neg;
  x = 0, c = getchar(), neg = false;
  for (; !isdigit(c); c = getchar()) {
    if (c == '-') {
      neg = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (neg) {
    x = -x;
  }
}
const int MOD = 1e9 + 7;
const int K = 1e6 + 5;
int n, k;
inline void fit(int &x) {
  if (x >= MOD) {
    x -= MOD;
  }
}
inline int power(int base, int exp) {
  base %= MOD;
  int res = 1;
  while (exp > 0) {
    if (exp & 1) {
      res = (long long)res * base % MOD;
    }
    base = (long long)base * base % MOD;
    exp >>= 1;
  }
  return res % MOD;
}
inline int inv(int x) { return power(x, MOD - 2); }
int y[K];
inline void calcY() {
  for (int i = 1; i <= k + 2; ++i) {
    y[i] = y[i - 1] + power(i, k);
    fit(y[i]);
  }
}
int front[K], back[K];
inline void calcFrontBack() {
  front[0] = 1;
  for (int i = 1; i <= k + 2; ++i) {
    front[i] = (long long)front[i - 1] * (n - i) % MOD;
  }
  back[k + 3] = 1;
  for (int i = k + 2; i >= 1; --i) {
    back[i] = (long long)back[i + 1] * (n - i) % MOD;
  }
}
int fact[K];
inline void calcFact() {
  fact[0] = 1;
  for (int i = 1; i <= k + 2; ++i) {
    fact[i] = (long long)fact[i - 1] * i % MOD;
  }
}
inline int calc() {
  calcY();
  calcFrontBack();
  calcFact();
  int res = 0;
  for (int i = 1, up, down; i <= k + 2; ++i) {
    up = (long long)y[i] * front[i - 1] % MOD * back[i + 1] % MOD;
    down = (long long)fact[i - 1] * fact[k + 2 - i] % MOD;
    if ((k + 2 - i) % 2 != 0) {
      down = -down + MOD;
      fit(down);
    }
    res += (long long)up * inv(down) % MOD;
    fit(res);
  }
  return res;
}
inline int bruteForce() {
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    res += power(i, k);
    fit(res);
  }
  return res;
}
int main() {
  read(n), read(k);
  if (n <= k + 2) {
    printf("%d\n", bruteForce());
  } else {
    printf("%d\n", calc());
  }
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

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;
template <typename Tp>
inline void read(Tp &x) {
  static char c;
  static bool neg;
  x = 0, c = getchar(), neg = false;
  for (; !isdigit(c); c = getchar()) {
    if (c == '-') {
      neg = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (neg) {
    x = -x;
  }
}
const int MOD = 1e9 + 7;
const int K = 1e6 + 5;
int n, k;
inline void fit(int &x) {
  if (x >= MOD) {
    x -= MOD;
  }
}
inline int power(int base, int exp) {
  base %= MOD;
  int res = 1;
  while (exp > 0) {
    if (exp & 1) {
      res = (long long)res * base % MOD;
    }
    base = (long long)base * base % MOD;
    exp >>= 1;
  }
  return res % MOD;
}
inline int inv(int x) { return power(x, MOD - 2); }
int y[K];
inline void calcY() {
  for (int i = 1; i <= k + 2; ++i) {
    y[i] = y[i - 1] + power(i, k);
    fit(y[i]);
  }
}
int front[K], back[K];
inline void calcFrontBack() {
  front[0] = 1;
  for (int i = 1; i <= k + 2; ++i) {
    front[i] = (long long)front[i - 1] * (n - i) % MOD;
  }
  back[k + 3] = 1;
  for (int i = k + 2; i >= 1; --i) {
    back[i] = (long long)back[i + 1] * (n - i) % MOD;
  }
}
int fact[K];
inline void calcFact() {
  fact[0] = 1;
  for (int i = 1; i <= k + 2; ++i) {
    fact[i] = (long long)fact[i - 1] * i % MOD;
  }
}
inline int calc() {
  calcY();
  calcFrontBack();
  calcFact();
  int res = 0;
  for (int i = 1, up, down; i <= k + 2; ++i) {
    up = (long long)y[i] * front[i - 1] % MOD * back[i + 1] % MOD;
    down = (long long)fact[i - 1] * fact[k + 2 - i] % MOD;
    if ((k + 2 - i) % 2 != 0) {
      down = -down + MOD;
      fit(down);
    }
    res += (long long)up * inv(down) % MOD;
    fit(res);
  }
  return res;
}
inline int bruteForce() {
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    res += power(i, k);
    fit(res);
  }
  return res;
}
int main() {
  read(n), read(k);
  if (n <= k + 2) {
    printf("%d\n", bruteForce());
  } else {
    printf("%d\n", calc());
  }
}

```