#include "bits/stdc++.h"
using namespace std;
 
#define int long long

template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string&);

string to_string(const char* s);

string to_string(bool b);

template <typename A>
string to_string(A v);

template <typename A, typename B>
string to_string(pair<A, B> p);

void debug_out(); 

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T);

vector<string> vec_splitter(string s);
void debug_var(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 

template <typename Head, typename... Tail>
void debug_var(vector<string>, int, int, Head, Tail...);

#ifndef ONLINE_JUDGE
#define var(...) debug_var(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define stl(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define var(x...)
#define stl(...) 
#endif

const int mod = 1e9 + 7;
const int N = 1e6 + 5; 

// Warning: Change mod and N according to the question

inline int add(int x, int y, int mod = ::mod) {
  x += y;
  if (x >= mod or x < 0) x %= mod;
  if (x >= 0) return x;
  return x + mod;
} 
inline int mul(int x, int y, int mod = ::mod) {
  if (x >= mod or x + mod < 0) x %= mod;
  if (y >= mod or y + mod < 0) y %= mod;
  x *= y;
  if (x >= mod or x + mod < 0) x %= mod;
  if (x >= 0) return x;
  return x + mod;
}
inline int sub(int x, int y, int mod = ::mod) {
  x -= y;
  if (x + mod < 0 or x >= mod) {
    x %= mod;
  }
  if (x >= 0) return x;
  return x + mod;
}
int po(int x, int n, int mod = ::mod) {
  int res = 1;
  for (;n > 0;) {
    if (n & 1) {
      res = mul(res, x, mod);
    }
    x = mul(x, x, mod);
    n /= 2;
  }
  return res;
}

int fact[N], invFact[N];

void pre(){
  fact[0] = invFact[0] = invFact[1] = 1;

  for(int i = 1 ; i < N ; i++) {
   fact[i] = mul(fact[i-1], i);
  }

  for(int i = 2 ; i < N ; i++) {
   invFact[i] = mul((mod - mod / i), invFact[mod % i]);
  }

  for(int i = 1; i < N ; i++) {
   invFact[i] = mul(invFact[i-1], invFact[i]);
  }
}
int ncr(int n, int r){
  return mul(mul(fact[n], invFact[r]), invFact[n-r]);
} 

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> ans(n + 3);
	iota(ans.begin(), ans.end(), -1);
	// stl(ans);
	ans[n + 1] = n;	
	for (int i = n; i > 0; --i) {
		ans[i] = add(ans[i], ans[i + 1]);
	}
	// for (int i = 1; i <= n + 1; i++) {
	// 	cout << ans[i] << ' ';
	// }
	// cout << '\n';
	int sum = 0;
	for (int i = k; i <= 1 + n; ++i) {
		int min = mul(mul(i, i - 1), po(2, mod - 2));
		int max = ans[n + 2 - i];
		// cout << min << ' ' << max << '\n';
		sum = add(sum + 1, sub(max, min));
	}
	cout << sum << '\n';
}

signed main() {
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  // int T = 1; cin >> T; for (int i = 1; i <= T; ++i)
  solve();
  return 0;
}

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "T" : "F");
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename Head, typename... Tail>
void debug_var(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << "): ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_var(args, idx + 1, LINE_NUM, T...);
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}

Measured memory_bytes: 4788