#include <algorithm>
#include <iostream>

using namespace std;

const int MD = 1000000007;

int main() {
	long long n, k; cin >> n >> k;
	long long x = n - (k - 1) + 1;
	// cout << x * (k * 3 * (k - 2 + x) + x * (x - 3) + 2) / 6 << '\n';
	/*
	n * x
	(n - 1) * x
	...
	(n - k + 1) * x
	(n - k - 0) * (x - 1) = n * x - 1n - k(x - 1) - 0x + 0 + 0
	(n - k - 1) * (x - 2) = n * x - 2n - k(x - 2) - 1x + 1 + 1
	(n - k - 2) * (x - 3) = n * x - 3n - k(x - 3) - 2x + 4 + 2
	(n - k - 3) * (x - 4) = n * x - 4n - k(x - 4) - 3x + 9 + 3
	...
	*/
	/*
	x(3nx + 6nk - 3n - 3kk + 3k - xx + 2x - 3xk + x - 2 + 3k - 3kk + 6k - 3xk - xx - 2 + 3x)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
                                        6


																				*/
	// cout << x * (3 * (n * (n + x) - (n - k) * (n - k + 1)) + (x - 1) * (-x + 2 - 3 * k)) / 6 << '\n';
	// cout << x * (3 * n * x + 6 * n * k - 3 * n - 3 * k * k + 3 * k - x * x + 2 * x - 3 * x * k + x - 2 + 3 * k - 3 * k * k + 6 * k - 3 * x * k - x * x - 2 + 3 * x) / 6 << '\n';
	cout << x * (3 * n * x + 6 * k * n - 3 * n - 6 * k * k + 12 * k - 2 * x * x + 6 * x - 6 * k * x + 2) / 6 % MD << '\n';
	// cout << x * (((x - k * (x + n - k + 2)) * 2 + n * (x - 1)) * 3 - (x * x - 5) * 2) / 6 << '\n';
	return 0;
}
