#include "bits/stdc++.h"
using namespace std;
using lint = int64_t;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < (n); ++i)
#define rep1(i, n) for (lint i = 1; i < (n); ++i)
#define Rep(i, n) for (lint i = (n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { lint to, cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1'000'000'007LL;
constexpr lint inf = 7LL * mod * mod;
const double Pi = acos(-1.0);

template<class T> inline bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[3000000];
void f_init(lint n) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * modpow(fact[n - r], mod - 2, mod) % mod * modpow(fact[r], mod - 2, mod) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (i == 0 || j == 0) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

lint xor128() {
	static lint x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	lint t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

double dis(D a, D b) {
	double x = a.first - b.first, y = a.second - b.second;
	return hypot(x, y);
}

bool kousa(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy) {
	double  ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
	double  tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
	double  tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
	double  td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);

	return tc * td < -1e-12 && ta * tb < -1e-12;
}

class unionfind {
private:
	lint par[2 * 100010], ranks[2 * 100010], sizeth[2 * 100010];
public:
	void init(lint n) noexcept {
		for (lint i = 0; i < n; ++i) {
			par[i] = i;
			ranks[i] = 0;
			sizeth[i] = 1;
		}
	}

	lint root(lint x) noexcept {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	lint size(lint x) const noexcept { return sizeth[x]; }

	bool same(lint x, lint y) noexcept { return root(x) == root(y); }

	void unite(lint x, lint y) noexcept {
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (ranks[x] < ranks[y]) {
			par[x] = y;
			sizeth[y] += sizeth[x];
		}
		else {
			par[y] = x;
			if (ranks[x] == ranks[y]) ++ranks[x];
			sizeth[x] += sizeth[y];
		}
	}
};

class BIT {
private:
	lint n;
	lint bit[500010];
public:
	void init(lint n_) noexcept { n = n_; }

	void add(lint a, lint w) noexcept {
		for (lint x = a; x <= n; x += (x & -x)) bit[x] += w;
	}
	lint sum(lint a) const noexcept {
		lint ret = 0;
		for (lint x = a; x > 0; x -= (x & -x)) ret += bit[x];
		return ret;
	}
};

lint n, k, sum;
int main() {
	cin >> n >> k;
	sum += n * (n + 1) * (n + 2) / 6 % mod;
	sum += k * (k - 1) * (2 * k - 3 * n - 4) / 6 % mod;
	sum %= mod;
	sum += n - k + 2;
	sum %= mod;
	if (sum < 0) sum += mod;
	cout << sum << endl;
}

Measured memory_bytes: 3720