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 int mod = 1000000007;
int f[1000005];
int re[1000005];
int g[1000005];
int r[] = {
    1,         682498929, 491101308, 76479948,  723816384, 67347853,  27368307,
    625544428, 199888908, 888050723, 927880474, 281863274, 661224977, 623534362,
    970055531, 261384175, 195888993, 66404266,  547665832, 109838563, 933245637,
    724691727, 368925948, 268838846, 136026497, 112390913, 135498044, 217544623,
    419363534, 500780548, 668123525, 128487469, 30977140,  522049725, 309058615,
    386027524, 189239124, 148528617, 940567523, 917084264, 429277690, 996164327,
    358655417, 568392357, 780072518, 462639908, 275105629, 909210595, 99199382,
    703397904, 733333339, 97830135,  608823837, 256141983, 141827977, 696628828,
    637939935, 811575797, 848924691, 131772368, 724464507, 272814771, 326159309,
    456152084, 903466878, 92255682,  769795511, 373745190, 606241871, 825871994,
    957939114, 435887178, 852304035, 663307737, 375297772, 217598709, 624148346,
    671734977, 624500515, 748510389, 203191898, 423951674, 629786193, 672850561,
    814362881, 823845496, 116667533, 256473217, 627655552, 245795606, 586445753,
    172114298, 193781724, 778983779, 83868974,  315103615, 965785236, 492741665,
    377329025, 847549272, 698611116, 0};
int k, w;
int po(int a, int b) {
  if (b <= 0) return 1;
  long long x = po(a, b / 2);
  x = x * x % mod;
  if (b % 2 == 1) x = x * a % mod;
  return x;
}
inline int sqr(int x) { return (long long)x * x % mod; }
int work(int k, int w, int u) {
  long long ans = 0;
  int t = po(k, w - k);
  for (int n = w + k; n > u; n--) {
    if (w + w - n <= 0) t = po(k, w + w - n);
    if (n <= 2 * w)
      ans += t * (long long)sqr(f[k]) % mod * sqr(re[k - n + w]) % mod;
    else
      ans += f[k] *
             (long long)(k - n + w + w - u == -1 ? f[k - n + w + w]
                                                 : g[k - n + w + w - u]) %
             mod * sqr(re[k - n + w]) % mod;
    t = t * (long long)k % mod;
  }
  return ans % mod;
}
int main() {
  f[0] = 1;
  for (int i = 1; i <= 1000000; i++) f[i] = f[i - 1] * (long long)i % mod;
  cin >> k >> w;
  g[0] = r[w / 10000000];
  for (int i = w / 10000000 * 10000000 + 1; i <= w; i++)
    g[0] = g[0] * (long long)i % mod;
  for (int i = 1; i <= 1000000; i++) g[i] = g[i - 1] * (long long)(w + i) % mod;
  for (int i = 0; i <= k; i++) re[i] = po(f[i], mod - 2);
  cout << (work(k, w, w) - work(k, w - 1, w) + mod) % mod << endl;
  return 0;
}