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>
long long fac[1000005];
long long inv[1000005];
long long w, k;
long long qp(long long b, long long e) {
  long long ans, t;
  ans = 1, t = b;
  while (e) {
    if (e & 1) {
      ans *= t;
      ans %= 1000000007;
    }
    t *= t;
    t %= 1000000007;
    e >>= 1;
  }
  return ans;
}
long long P(long long m, long long n) {
  if (m > n) return 0;
  if (m < 0 || n < 0) return 0;
  return fac[n] * inv[n - m] % 1000000007;
}
long long work() {
  long long l, d, t1, t2, t3, ans = 0;
  for (l = 1; l <= k; ++l) {
    if (w - l >= 2) {
      t1 = qp(k, (l + w) - l * 2 - 2) % 1000000007;
      t2 = (P(l, k) * P(l, k)) % 1000000007;
      t2 = (t2 * k) % 1000000007 * k % 1000000007;
      t3 = (P(l + 1, k) * P(l + 1, k)) % 1000000007;
      ans += (t2 - t3 + 1000000007) % 1000000007 * t1 % 1000000007;
      ans %= 1000000007;
    }
    if (w - l == 1) {
      t1 = (P(l, k) * P(l, k)) % 1000000007;
      t1 = t1 * k % 1000000007;
      t2 = (P(l + 1, k) * P(l, k - 1)) % 1000000007;
      ans += (t1 - t2 + 1000000007) % 1000000007;
      ans %= 1000000007;
    }
    if (w <= l) {
      d = l - w;
      t1 = (P(d, k) * P(w, k - d)) % 1000000007 * P(w, k - d) % 1000000007;
      t2 = (P(d + 2, k) * P(w - 1, k - d - 2)) % 1000000007 *
           P(w - 1, k - d - 2) % 1000000007;
      ans += (t1 - t2 + 1000000007) % 1000000007;
      ans %= 1000000007;
    }
  }
  return (ans + 1000000007) % 1000000007;
}
int main() {
  int i;
  scanf("%I64d%I64d", &k, &w);
  fac[0] = inv[0] = 1;
  for (i = 1; i <= k; ++i) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= 1000000007;
    inv[i] = qp(fac[i], 1000000007 - 2) % 1000000007;
  }
  printf("%I64d\n", work());
  return 0;
}