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;
const long long pri = 1000000007LL;
long long n, m, ans;
long long jie[1000005], nijie[1000005];
long long ksm(long long x, long long y) {
  if (y > pri - 2) y %= pri - 1;
  if (!y) return 1;
  long long t = ksm(x, y / 2);
  if (y & 1) return t * t % pri * x % pri;
  return t * t % pri;
}
long long pow(long long x) { return x * x % pri; }
long long p(long long b, long long a) {
  long long x1 = jie[a], x2;
  if (a - b == -1)
    x2 = 0;
  else
    x2 = nijie[a - b];
  return x1 * x2 % pri;
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  jie[0] = 1;
  for (int i = 1; i <= n; i++) jie[i] = jie[i - 1] * i % pri;
  nijie[n] = ksm(jie[n], pri - 2);
  for (int i = n; i; i--) nijie[i - 1] = nijie[i] * i % pri;
  for (int l = 1; l <= n; l++)
    if (m - l > 1)
      ans = (ans + ksm(n, l + m - 2 * l - 2) *
                       (pow(p(l, n)) * pow(n) % pri - pow(p(l + 1, n)) + pri) %
                       pri) %
            pri;
    else if (m - l == 1)
      ans = (ans + pow(p(l, n)) * n % pri - p(l + 1, n) * p(l, n - 1) % pri +
             pri) %
            pri;
    else
      ans = (ans + p(l - m, n) * pow(p(m, n - l + m)) % pri -
             p(l - m + 2, n) * pow(p(m - 1, n - l + m - 2)) % pri + pri) %
            pri;
  printf("%I64d", ans);
  return 0;
}