/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 105;

int n, m, ans;
int f[maxn][maxn * maxn];

inline int add(int a, int b){return (a + b) % INF;}
inline void uadd(int &a, int b){(a += b) %= INF;}
inline int mul(int a, int b){return (1ll * a * b) % INF;}
inline void umul(int &a, int b){a = mul(a, b);}

inline int qpow(int a, int b){
	int ret = 1;
	for(; b; b >>= 1){
		if(b & 1){
			umul(ret, a);
		}
		umul(a, a);
	}
	return ret;
}

int main(){
	scanf("%d%d", &n, &m);
	f[n][0] = 1;
	for(int i = n; i > 0; --i) FOR(j, 0, maxn * maxn) if(f[i][j] >= 0){
		REP(k, 0, m){
			if(k > i){
				if(f[i - 1][j] < 0)
					f[i - 1][j] = 0;
				uadd(f[i - 1][j], f[i][j]);
				continue;
			}
			if(j + (j + k) / i < maxn * maxn){
				uadd(f[i - 1][j + (j + k) / i], f[i][j]);
			}
		}
	}
	//for(int i = n; i >= 0; --i) FOR(j, 0, maxn * maxn) if(f[i][j])
		//printf("dp[%d][%d] = %d\n", i, j, f[i][j]);
	FOR(j, 0, maxn * maxn) if(f[0][j] >= 0)
		uadd(ans, mul(f[0][j], j));
	ll res = 0;
	res = mul(n, mul((m * (m + 1) / 2), qpow(m + 1, n - 1)));
	//printf("%d %d %d\n", res, ans, (res - ans + INF) % INF);
	printf("%d\n", (res - ans + INF) % INF);
	return 0;
}