Problem: Little Petya very much likes strings. Recently he has received a voucher to purchase a string as a gift from his mother. The string can be bought in the local shop. One can consider that the shop has all sorts of strings over the alphabet of fixed size. The size of the alphabet is equal to k. However, the voucher has a string type limitation: specifically, the voucher can be used to purchase string s if the length of string's longest substring that is also its weak subsequence (see the definition given below) equals w.

String a with the length of n is considered the weak subsequence of the string s with the length of m, if there exists such a set of indexes 1 ≤ i1 < i2 < ... < in ≤ m, that has the following two properties: 

  * ak = sik for all k from 1 to n; 
  * there exists at least one such k (1 ≤ k < n), for which ik + 1 – ik > 1. 



Petya got interested how many different strings are available for him to purchase in the shop. As the number of strings can be very large, please find it modulo 1000000007 (109 + 7). If there are infinitely many such strings, print "-1".

Input

The first line contains two integers k (1 ≤ k ≤ 106) and w (2 ≤ w ≤ 109) — the alphabet size and the required length of the maximum substring that also is the weak subsequence, correspondingly.

Output

Print a single number — the number of strings Petya can buy using the voucher, modulo 1000000007 (109 + 7). If there are infinitely many such strings, print "-1" (without the quotes).

Examples

Input

2 2


Output

10


Input

3 5


Output

1593


Input

2 139


Output

717248223

Note

In the first sample Petya can buy the following strings: aaa, aab, abab, abb, abba, baa, baab, baba, bba, bbb.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
namespace mine {
long long qread() {
  long long ans = 0, f = 1;
  char c = getchar();
  while (c < '0' or c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans * f;
}
void write(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) write(num / 10);
  putchar('0' + num % 10);
}
void write1(long long num) {
  write(num);
  putchar(' ');
}
void write2(long long num) {
  write(num);
  putchar('\n');
}
template <typename T>
void chmax(T &x, const T y) {
  x = (x > y ? x : y);
}
template <typename T>
void chmin(T &x, const T y) {
  x = (x < y ? x : y);
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
inline int mm(const int x) { return x >= MOD ? x - MOD : x; }
template <typename T>
inline void add(T &x, const T y) {
  x = mm(x + y);
}
inline long long qpower(long long x, long long e) {
  long long ans = 1;
  if (e < 0) puts("error");
  while (e) {
    if (e & 1) ans = ans * x % MOD;
    x = x * x % MOD;
    e >>= 1;
  }
  return ans;
}
long long invm(long long x) { return qpower(x, MOD - 2); }
const int N = 2e6 + 10;
long long fac[N], facinv[N];
long long P(int n, int m) {
  return (n < m or n < 0 or m < 0) ? 0 : fac[n] * facinv[n - m] % MOD;
}
long long C(int n, int m) {
  return (n < m or n < 0 or m < 0)
             ? 0
             : fac[n] * facinv[m] % MOD * facinv[n - m] % MOD;
}
long long sqr(long long x) { return x * x % MOD; }
void main() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % MOD;
  facinv[N - 1] = invm(fac[N - 1]);
  for (int i = N - 2; i >= 0; i--) facinv[i] = facinv[i + 1] * (i + 1) % MOD;
  int k = qread(), w = qread();
  long long ans = 0;
  for (int n = w + 1; n <= w + k; n++) {
    if (n - w < w) {
      ans = mm(ans + sqr(P(k, n - w)) * (n - w) % MOD *
                         qpower(k, w - (n - w) - 1) * 2 % MOD);
      if (w - (n - w) > 1)
        ans = mm(ans + MOD -
                 sqr(P(k, n - w) * (n - w) % MOD) * qpower(k, w - (n - w) - 2) %
                     MOD);
      else
        for (int i = 1; i <= k; i++)
          ans = mm(ans + MOD -
                   C(k, i) * i % MOD * C(k - i, 2 * (n - w - i)) % MOD *
                       C(2 * (n - w - i), n - w - i) % MOD * sqr(fac[n - w]) %
                       MOD);
    } else if (n - w > w) {
      int mid = n - w - w;
      ans = mm(ans + P(k, n - w) * P(k - mid, w) % MOD);
      ans = mm(ans + MOD -
               P(k, n - w) % MOD * (k + MOD - (n - w)) % MOD *
                   P(k - (mid + 2), w - 1) % MOD);
    } else
      ans =
          mm(ans + P(k, w) % MOD *
                       (P(k, w) + MOD - P(k - 2, w - 1) * (k - w) % MOD) % MOD);
  }
  write(ans);
}
};  // namespace mine
int main() {
  srand(time(0));
  mine::main();
}