#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> K;
	vector<vector<long long int>>dp(N + 1, vector<long long int>(N*N + 1));
	dp[N][0] = 1;
	vector<vector<long long int>>ans(N + 1, vector<long long int>(N*N + 1));
	for (int i = N; i > 0; i--) {
		for (int j = 0; j <= N * N; j++) {
			for (int k = 0; k <= K; k++) {
				int nxj = j;
				long long int amari = 0;
				if (k > i) {
					amari = k+j;
				}
				else {
					amari = (k + j) % i;
					nxj += (k + j) / i;
				}
				if (nxj > N*N)continue;
				dp[i - 1][nxj] += dp[i][j];
				dp[i - 1][nxj] %= MOD;
				ans[i - 1][nxj] += ans[i][j] + amari * dp[i][j];
				ans[i - 1][nxj] %= MOD;
			}
		}
	}
	M = accumulate(ans.front().begin(), ans.front().end(), 0LL);
	cout << M % MOD << endl;
}