#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
Int dp[111][11111];
Int po[111];
const Int MOD = 1e9+7;
Int dfs(Int n,Int k,Int d){
  if(n==0) return 0;
  Int &res=dp[n][d];
  if(~res) return res;
  res=0;
  for(Int i=0;i<=k;i++){
    if(i<=n) res+=dfs(n-1,k,d+(d+i)/n)+((d+i)%n)*po[n-1];
    else res+=dfs(n-1,k,d)+(d+i)*po[n-1];
    res%=MOD;
  }
  //cout<<n<<" "<<d<<":"<<res<<endl;
  return res;
}
signed main(){
  Int n,k;
  cin>>n>>k;
  
  po[0]=1;
  for(Int i=0;i<n;i++) po[i+1]=po[i]*(k+1)%MOD;
  
  memset(dp,-1,sizeof(dp));
  cout<<dfs(n,k,0)<<endl;
  return 0;
}
