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;
int cond = 1;
const int Q = (int(1e9)) + 7;
const int M = 1001013;
int sil[M], od[M];
inline int odwrot(int x, long long ret) { return ret * od[x] % Q; }
int odwr(int x, int ret) {
  int n = Q - 2;
  while (n) {
    if (n % 2) ret = ((long long)ret) * x % Q;
    x = ((long long)x) * x % Q;
    n /= 2;
  }
  return ret;
}
int ff(int k, int n, int x) {
  int ret = odwrot(k - x, sil[k]);
  ret = ((long long)ret) * ret % Q;
  n -= x;
  while (n) {
    if (n % 2) ret = ((long long)ret) * k % Q;
    k = ((long long)k) * k % Q;
    n /= 2;
  }
  return ret;
}
int f(int k, int n, int x) {
  int ret = odwrot(k - x, sil[k]);
  ret = ((long long)ret) * ret % Q;
  return ret;
}
int main() {
  int k, w;
  scanf("%d %d", &k, &w);
  sil[0] = 1;
  for (typeof(1) i = (1); i <= (k + 5); ++i)
    sil[i] = ((long long)i) * sil[i - 1] % Q;
  od[k + 4] = odwr(sil[k + 4], 1);
  for (typeof(k + 3) i = (k + 3); i >= (0); --i)
    od[i] = ((long long)(i + 1)) * od[i + 1] % Q;
  int ret = 0;
  int potk = 1, kk = k;
  int uu = w - 3;
  while (uu) {
    if (uu % 2) potk = ((long long)potk) * kk % Q;
    kk = ((long long)kk) * kk % Q;
    uu /= 2;
  }
  int odk = odwr(k, 1);
  for (typeof(1) x = (1); x <= (min(k, w - 2)); ++x) {
    ret += (f(k, w, x) * ((long long)k) % Q * ((long long)k) % Q -
            f(k, w - 1, x + 1) + Q) %
           Q * ((long long)potk) % Q;
    potk = ((long long)potk) * odk % Q;
    ret = (ret % Q + Q) % Q;
  }
  if (w - 1 <= k) {
    ret += ff(k, w, w - 1) - odwr(k, ff(k, w, w));
    ret = (ret % Q + Q) % Q;
  }
  for (typeof(w) x = (w); x <= (k); ++x) {
    int u = ((long long)(((long long)odwrot(k - x, sil[k])) * w % Q)) *
            odwrot(k - x, sil[k - x + w - 1]) % Q;
    ret = (ret + u) % Q;
    if (x < k) {
      u = ((long long)odwrot(k - x - 1, sil[k])) *
          odwrot(k - x, sil[k - x + w - 2]) % Q * ((long long)(w - 1)) % Q;
      ret = (ret + u) % Q;
    }
  }
  printf("%d\n", ret);
  return 0;
}