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 m, n, k;
long long ans, p[1000005], _inv[1000005], inv[1000005];
long long f1, f2;
long long qpow(long long x, long long k) {
  long long ret = 1;
  while (k) {
    if (k & 1) ret = ret * x % 1000000007;
    k >>= 1;
    x = x * x % 1000000007;
  }
  return ret;
}
long long calc(int n, int m, int k) {
  int t1 = m - n + 1, t2 = n;
  long long x1 = 0, x2 = 0, x3 = 0;
  if (t1 < t2) {
    if (t1 <= k) x1 = p[k] * inv[k - t1] % 1000000007;
    if (m - t2 + 1 <= k) x2 = p[k] * inv[k - (m - t2 + 1)] % 1000000007;
    return x1 * x2 % 1000000007 * qpow(k, t2 - t1 - 1) % 1000000007;
  } else {
    int t3 = t1 - t2 + 1;
    if (t3 <= k) x1 = p[k] * inv[k - t3] % 1000000007;
    if (t2 - 1 <= k - t3) x2 = p[k - t3] * inv[k - t3 - (t2 - 1)] % 1000000007;
    if (m - t1 <= k - t3) x3 = p[k - t3] * inv[k - t3 - (m - t1)] % 1000000007;
    return x1 * x2 % 1000000007 * x3 % 1000000007;
  }
}
int main() {
  cin >> k >> n;
  m = n + k;
  p[0] = inv[0] = _inv[0] = 1;
  p[1] = inv[1] = _inv[1] = 1;
  for (int i = 2; i <= k; i++) {
    p[i] = p[i - 1] * i % 1000000007;
    _inv[i] = (1000000007 - 1000000007 / i) * _inv[1000000007 % i] % 1000000007;
    inv[i] = inv[i - 1] * _inv[i] % 1000000007;
  }
  for (int i = n + 2; i <= min(m, n + k); i++)
    f1 = (f1 - calc(n + 1, i, k) + 1000000007) % 1000000007;
  for (int i = n + 1; i <= min(m, n + k); i++)
    f2 = (f2 - calc(n, i, k) + 1000000007) % 1000000007;
  printf("%I64d\n", (f2 - f1 + qpow(k, n + 1) + 1000000007) % 1000000007);
}