#include<bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MOD = 1e9+7;

signed main(){
  lint N, K; cin >> N >> K;
  lint ans = 0;
  for(lint i = N - K + 2; i <= N + 1; i++){
    ans += i;
    ans %= MOD;
  }
  lint ans1 = 0;
  for(lint i = 1; i <= K; i++){
    ans1 += i; ans1 %= MOD;
  }
  lint ans2 = 0;
  ans2 += (ans - ans1 + 1) % MOD;
  if(ans2 < 0) ans2 += MOD;
  
  for(lint i = 1; i <= N - K + 1; i++){
    ans1 += K + i;
    ans += (N - K - i + 2);
    ans1 %= MOD; ans %= MOD;
    ans2 += (ans - ans1 + 1);
    ans2 %= MOD;
    if(ans2 < 0) ans2 += MOD;
  }
  cout << ans2 << endl;
}