#include <bits/stdc++.h>
#include <random>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
const ll INF = LLONG_MAX / 2;
const int MOD = 1e9 + 7;

int pow_mod(ll x, ll n, int M) {
	ll ans = 1;
	for (; n; n>>=1) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
	}
	return ans;
}

int inv_mod(int x, int p) {
	return pow_mod(x, p - 2, p);
}

int main() {
	int N, K; cin >> N >> K;
	vector<int> dp(10001);
	dp[0] = 1;
	for (int i = N; i >= 1; i--) {
		vector<int> _dp(10001);
		rep(x, 10001) if (dp[x]) rep(k, K + 1) {
			int _x = x;
			if (k <= i) _x += (k + x) / i;
			_dp[_x] = (_dp[_x] + dp[x]) % MOD;
		}
		dp = _dp;
	}
	ll ans = (ll)K * inv_mod(2, MOD) % MOD * N % MOD * pow_mod(K + 1, N, MOD) % MOD;
	// cout << ans << endl;
	rep(x, 10001) ans = (ans - (ll)dp[x] * x) % MOD;
	cout << (ans + MOD) % MOD << endl;
}
