#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize "trapv"
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define drep(i,a,b) for(int i=a; i>b; i--)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define inf 1e+18L
#define mod 1000000007

const auto pi = 3.14159265358979;

template <typename T>
T numdigits(T n)
{
    return (floor(log10(n)) + 1);
}

template <typename T>
T modpower(T x, T y, T m=mod)
{
    T res = 1;
    x %= m;
    if(x == 0) return 0;
    while(y > 0)
    {
        if(y&1) res = (res*x)%m;
        y >>= 1;
        x = (x*x)%m;
    }
    return res;
}

void solve()
{
    //code
    ll n, k;
    cin >> n >> k;
    cout << ((2*k*k*k-3*k*k*n-6*k*k+3*k*n-2*k+n*n*n+3*n*n+8*n+12)/6)%mod;
}

int main()
{
    FASTIO
//    int t;
//    cin >> t;
//    while(t--)
        solve();
    return 0;
}
