#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
const ll MOD = 1e9 + 7, SZ = 5002;

ll n, k, dp[SZ][SZ * 2];

int main() {
	fastInp;

	cin >> n >> k;

	dp[0][0] = 1;
	ll pw = 1;
	for (int i = 0; i < n - 1; i++) {
		pw *= (k + 1);
		pw %= MOD;
	}
	ll add = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= k; j++) {
			add += (j * pw);
			add %= MOD;
			for (int curs = 0; curs < SZ * 2; curs++) {
				ll s = 0;
				if (j > (n - i)) {
					s = curs;
				}
				else {
					s = curs + (curs + j) / (n - i);
				}
				dp[i + 1][s] += dp[i][curs];
				dp[i + 1][s] %= MOD;
			}
		}
	}

	ll dis = 0;
	for (int j = 0; j < SZ * 2; j++) {
		dis += dp[n][j] * j;
		dis %= MOD;
	}
	cout << (add - dis + MOD) % MOD;

	return 0;
}