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;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 1000000007;
constexpr long double eps = 1e-6;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
  os << to_string(p.first) << " " << to_string(p.second);
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (ll i = (0); i < (ll)(v.size()); i++) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
struct modint {
  ll n;

 public:
  modint(const ll n = 0) : n((n % mod + mod) % mod) {}
  static modint pow(modint a, int m) {
    modint r = 1;
    while (m > 0) {
      if (m & 1) {
        r *= a;
      }
      a = (a * a);
      m /= 2;
    }
    return r;
  }
  modint& operator++() {
    *this += 1;
    return *this;
  }
  modint& operator--() {
    *this -= 1;
    return *this;
  }
  modint operator++(int) {
    modint ret = *this;
    *this += 1;
    return ret;
  }
  modint operator--(int) {
    modint ret = *this;
    *this -= 1;
    return ret;
  }
  modint operator~() const { return (this->pow(n, mod - 2)); }
  friend bool operator==(const modint& lhs, const modint& rhs) {
    return lhs.n == rhs.n;
  }
  friend bool operator<(const modint& lhs, const modint& rhs) {
    return lhs.n < rhs.n;
  }
  friend bool operator>(const modint& lhs, const modint& rhs) {
    return lhs.n > rhs.n;
  }
  friend modint& operator+=(modint& lhs, const modint& rhs) {
    lhs.n += rhs.n;
    if (lhs.n >= mod) lhs.n -= mod;
    return lhs;
  }
  friend modint& operator-=(modint& lhs, const modint& rhs) {
    lhs.n -= rhs.n;
    if (lhs.n < 0) lhs.n += mod;
    return lhs;
  }
  friend modint& operator*=(modint& lhs, const modint& rhs) {
    lhs.n = (lhs.n * rhs.n) % mod;
    return lhs;
  }
  friend modint& operator/=(modint& lhs, const modint& rhs) {
    lhs.n = (lhs.n * (~rhs).n) % mod;
    return lhs;
  }
  friend modint operator+(const modint& lhs, const modint& rhs) {
    return modint(lhs.n + rhs.n);
  }
  friend modint operator-(const modint& lhs, const modint& rhs) {
    return modint(lhs.n - rhs.n);
  }
  friend modint operator*(const modint& lhs, const modint& rhs) {
    return modint(lhs.n * rhs.n);
  }
  friend modint operator/(const modint& lhs, const modint& rhs) {
    return modint(lhs.n * (~rhs).n);
  }
};
istream& operator>>(istream& is, modint m) {
  is >> m.n;
  return is;
}
ostream& operator<<(ostream& os, modint m) {
  os << m.n;
  return os;
}
using mi = modint;
ll mod_pow(ll a, ll n, ll m = mod) {
  ll ret = 1;
  ll tmp = a;
  while (n > 0) {
    if (n % 2) ret *= tmp;
    ret %= m;
    tmp = tmp * tmp;
    tmp %= m;
    n /= 2;
  }
  return ret % m;
}
constexpr int MAX_N = 2020202;
mi mod_fact[MAX_N + 1];
mi mod_fact_i[MAX_N + 1];
mi mod_comb(long long n, long long k) {
  static bool initialized = false;
  if (n < 0 || k < 0 || n < k) return 0;
  if (not initialized) {
    mod_fact[0] = 1;
    for (int i = 1; i <= MAX_N; ++i) {
      mod_fact[i] = i * mod_fact[i - 1];
    }
    mod_fact_i[MAX_N] = mod_pow(mod_fact[MAX_N].n, mod - 2);
    for (int i = MAX_N - 1; i >= 0; --i) {
      mod_fact_i[i] = mod_fact_i[i + 1] * (i + 1);
    }
    initialized = true;
  }
  return mod_fact[n] * mod_fact_i[n - k] * mod_fact_i[k];
}
struct union_find {
  union_find(int n) : par_(n, -1) {}
  void init(int n) { par_.assign(n, -1); }
  int root(int x) { return par_[x] < 0 ? x : par_[x] = root(par_[x]); }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par_[x] < par_[y]) {
      par_[x] += par_[y];
      par_[y] = x;
    } else {
      par_[y] += par_[x];
      par_[x] = y;
    }
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -par_[root(x)]; }
  vector<int> par_;
};
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll N = 202020;
ll bit[202020];
void add(ll a, ll w) {
  a++;
  for (ll x = a; x <= N; x += x & -x) bit[x] += w;
}
ll sum(ll a) {
  a++;
  ll ret = 0;
  for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
  return ret;
}
ll sum(ll a, ll b) {
  ll ret = 0;
  if (b == 0) return 0;
  ret += sum(b - 1);
  if (a) ret -= sum(a - 1);
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  mod_comb(1, 1);
  ll k, w;
  cin >> k >> w;
  mi ans = 0;
  for (int i = w + 1; i <= w + k; ++i) {
    ll rem = i - w;
    mi tmp = 0;
    if (2 * rem < i) {
      tmp = mod_pow(k, i - 2 * rem);
      tmp *= mod_pow((mod_comb(k, rem) * mod_fact[rem]).n, 2) -
             mod_pow((mod_comb(k - 1, rem) * mod_fact[rem]).n, 2);
      ans += tmp;
    } else {
      int cross = 2 * rem - i;
      tmp = k;
      tmp *= mod_comb(k - 1, cross) * mod_fact[cross];
      tmp *= mod_pow(
          (mod_comb(k - 1 - cross, rem - cross - 1) * mod_fact[rem - cross - 1])
              .n,
          2);
      ans += tmp;
      tmp = 0;
      tmp = k * (k - 1);
      tmp *= mod_comb(k - 2, cross) * mod_fact[cross];
      tmp *= mod_pow((mod_comb(k - 1 - cross, rem - cross - 1) *
                      mod_fact[rem - cross - 1])
                         .n,
                     2) -
             mod_pow((mod_comb(k - 2 - cross, rem - cross - 1) *
                      mod_fact[rem - cross - 1])
                         .n,
                     2);
      ans += tmp;
    }
  }
  cout << ans << endl;
  return 0;
}