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;
using namespace rel_ops;
const double PI = acos((double)-1);
int ts, ts2, ts3, ts4;
long long gcd(long long x, long long y) {
  long long i;
  for (; y != 0;) {
    i = x % y;
    x = y;
    y = i;
  }
  return x;
}
double sqr(double x) { return x * x; }
template <class T>
void mn(T& x, T y) {
  x = min(x, y);
}
template <class T>
void mx(T& x, T y) {
  x = max(x, y);
}
long long K, w, out;
long long mul(long long x, long long y) {
  long long t1 = 1, t2;
  for (; y; y /= 2) {
    if (y & 1) {
      y--;
      t1 = t1 * x % 1000000007;
    }
    x = x * x % 1000000007;
  }
  return t1;
}
long long jc[1000005], rev[1000005], jcrev[1000005], tp[1000005];
long long sqr(long long x) { return x * x % 1000000007; }
void work() {
  long long i, j, l, t1, t2, t3, t4, t5, t6, t7, t8, t9, nw;
  for (i = 1; i <= K; i++) {
    if (i <= w - 1) {
      out += sqr(jc[K] * jcrev[K - i] % 1000000007) % 1000000007 * i %
             1000000007 * tp[i] % 1000000007;
      out %= 1000000007;
    } else {
      out += (jc[K] * jcrev[K - i] % 1000000007) *
             (jc[K - i + w - 1] * jcrev[K - i] % 1000000007) % 1000000007 * w %
             1000000007;
      out %= 1000000007;
    }
    if (i < K) {
      if (i + 1 <= w - 1) {
        out += jc[K] * jcrev[K - i] % 1000000007 * jc[K] % 1000000007 *
               jcrev[K - i - 1] % 1000000007 * i % 1000000007 * tp[i + 1] %
               1000000007;
        out %= 1000000007;
      } else {
        out += jc[K] * jcrev[K - i] % 1000000007 * jc[K - i + w - 2] %
               1000000007 * jcrev[K - i - 1] % 1000000007 * (w - 1);
        out %= 1000000007;
      }
    }
  }
}
int main() {
  long long i, j, l, t1, t2, t3, t4, t5, t6, t7, t8, t9, nw;
  int tt1, tt2, tt3, tt4;
  double u1, u2, u3, u4, u5, u6, u7, u8, u9;
  char c1, c2, c3;
  srand((unsigned)time(0));
  cin >> K >> w;
  rev[1] = 1;
  for (i = 2; i <= K; i++)
    rev[i] = 1000000007 - ((1000000007 / i * rev[1000000007 % i] % 1000000007) +
                           1000000007) %
                              1000000007;
  for (i = 0; i <= K; i++) {
    if (i == 0)
      jc[i] = jcrev[i] = 1;
    else {
      jc[i] = jc[i - 1] * i % 1000000007;
      jcrev[i] = jcrev[i - 1] * rev[i] % 1000000007;
    }
  }
  tp[1] = mul(K, w - 2);
  for (j = 2; j <= K; j++) tp[j] = tp[j - 1] * rev[K] % 1000000007;
  work();
  out = (out % 1000000007 + 1000000007) % 1000000007;
  ;
  cout << out << endl;
  return 0;
}