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 JAVA):

Solution:
import java.io.*;

import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	final String filename = "";

	final int MAX = 2000001;

	long[] factK;
	int k;

	void init() {
		factK = new long[MAX];
		factK[0] = 1;
		for (int i = 1; i < MAX; i++)
			factK[i] = ((factK[i - 1] * (long) (k - i + 1)) % mod);
	}

	public void solve() throws Exception {
		// test();
		k = iread();
		init();
		int w = iread();
		long ans = solve(w + 1) - solve(w);
		ans %= mod;
		ans += mod;
		ans %= mod;
		out.write(ans + "\n");
	}

	public void test() throws Exception {
		k = 1;
		while (k <= 10) {
			init();
			for (int w = 1; w <= 20; w++) {
				long ans = solve(w + 1) - solve(w);
				ans %= mod;
				ans += mod;
				ans %= mod;
				System.out.println(k + " " + w + " ans=" + ans);
			}
			k++;
		}
	}

	public long solve(int w) {
		int[][] A = new int[2][2];
		A[0][0] = k;
		A[1][0] = 1;
		A[1][1] = 1;
		int[][] B = pow(A, w + 1);
		long ans = B[1][0];

		ans = (ans + mod - 1) % mod;
		long prev = -1;
		for (int a = k; a >= 2; a--) {
			int n = w - 1 + a;
			long cur = 0;
			if (2 * a > n) {
				cur = factK[a];
				cur %= mod;
				cur *= factK[a];
				cur %= mod;
				cur *= pow(factK[2 * a - n], mod - 2);
				cur %= mod;
			} else {
				if (prev < 0)
					prev = pow(k, n - 2 * a);
				else {
					prev = (prev * k) % mod;
				}
				cur = prev;
				cur *= factK[a];
				cur %= mod;
				cur *= factK[a];
				cur %= mod;
			}
			ans += cur;
			ans %= mod;
		}
		return ans;
	}

	final int mod = 1000000007;

	int[][] mul(int[][] a, int[][] b) {
		int n = a.length;
		int[][] c = new int[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				for (int k = 0; k < n; k++) {
					c[i][j] = (int) ((c[i][j] + (long) a[i][k] * b[k][j]) % mod);
				}
		return c;
	}

	int pow(long x, int k) {
		long y = 1;
		while (k > 0) {
			if (k % 2 == 1) {
				y = (y * x) % mod;
			}
			k /= 2;
			x = (x * x) % mod;
		}
		return (int) y;
	}

	int[][] pow(int[][] a, long k) {
		int n = a.length;
		int[][] b = new int[n][n];
		for (int i = 0; i < n; i++)
			b[i][i] = 1;
		while (k > 0) {
			if (k % 2 == 1)
				b = mul(b, a);
			a = mul(a, a);
			k /= 2;
		}
		return b;
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {
		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		// new Thread(new Main()).start();
		new Thread(null, new Main(), "1", 1 << 25).start();
	}
}