#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long mod(long long &x) { x = (1ll * MOD * MOD + x) % MOD; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long dp[n + 2][n * k + 1];
  memset(dp, 0, sizeof dp);
  long long curmax = 0;
  dp[n + 1][0] = 1;
  for (long long i = n; i >= 1; --i) {
    long long newmax = curmax;
    for (long long j = 0; j <= curmax; ++j) {
      long long j1 = j - (j % i) + i;
      long long l = j, r = j + min(i, k);
      dp[i][j + j / i] += (1ll * dp[i + 1][j] * (min(j1 - 1, r) - j + 1)) % MOD;
      dp[i][j + j / i] %= MOD;
      dp[i][j + j / i + 1] +=
          (1ll * dp[i + 1][j] * (r - min(j1, r + 1) + 1)) % MOD;
      dp[i][j + j / i + 1] %= MOD;
      newmax = ((newmax) > (j + j / i + 1) ? (newmax) : (j + j / i + 1));
    }
    for (long long j = 0; j <= curmax; ++j) {
      dp[i][j] += (1ll * dp[i + 1][j] * ((k - i) > (0) ? (k - i) : (0))) % MOD;
      dp[i][j] %= MOD;
    }
    curmax = newmax;
  }
  long long t2 = 0;
  for (long long j = 0; j <= curmax; ++j) {
    t2 += dp[1][j] * j;
    t2 %= MOD;
  }
  long long t1 = 1;
  for (long long i = 0; i < n - 1; ++i) {
    t1 = (1ll * t1 * (k + 1)) % MOD;
  }
  t1 = (1ll * t1 * n) % MOD;
  t1 = (1ll * t1 * k * (k + 1) / 2) % MOD;
  long long ans = t1 - t2;
  mod(ans);
  cout << ans << endl;
}
