#include<bits/stdc++.h>

using namespace std;


typedef long long ll;

ll M=1e9+7;

int main(){
  ll n,m;
  cin>>n>>m;


  ll ans=(m+1)%M; // d=0

  n--;

  if(n){
    ll t=(m/n)%M;
    
    ans=(ans+t*2)%M; // a0=0 d!=0

    ans=(ans+2*t*((m%n)%M)%M)%M;
    
    n%=M;

    ans=(ans+((t-1)*t%M)*(n)%M)%M;

  }

  cout<<ans<<endl;

  return 0;
}