#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;

int main(void)
{
	ll N,K;
	cin>>N>>K;
	ll ans=0;
	if(K<0){
		K*=-1;
	}
	for(ll i=2;i<=2*N-K;i++){
		ll j=i+K;
		if(i<=N && j<=N){
			ans+=(i-1)*(j-1);
		}else if(i>N && j>N){
			ans+=(2*N-i+1)*(2*N-j+1);
		}else if(i>N){
			ans+=(2*N-i+1)*(j-1);
		}else if(j>N){
			ans+=(i-1)*(2*N-j+1);
		}
		
	}
	printf("%lld\n",ans);
	
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll pow_mod(ll x, ll n, ll mod) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ret;
}

int main(){
  ll n, p;
  cin >> n >> p;
  ll mod = pow(10,9)+7;
  ll ans = ((p-1)*pow_mod(p-2, n-1, mod))%mod;
  cout << ans << endl;
  return 0;
}