#include <bits/stdc++.h>
using namespace std;
template <typename T>
void readv(vector<T> &a) {
  for (long long i = (0); i < (a.size()); i++) cin >> a[i];
}
void readi(vector<long long> &a) {
  for (long long i = (0); i < (a.size()); i++) {
    cin >> a[i];
    a[i]--;
  }
}
void debug(vector<vector<long long> > m) {
  for (long long i = (0); i < (m.size()); i++) {
    for (long long j = (0); j < (m[0].size()); j++) {
      cout << m[i][j] << ",";
    }
    cout << endl;
  }
}
long long modpow(long long x, long long n, long long m) {
  long long a = 1;
  for (long long i = (64) - 1; i >= (0); i--) {
    a = (a * a) % m;
    if (((n >> i) & 1) == 1) a = (a * x) % m;
  }
  return a;
}
signed main() {
  long long N, K;
  cin >> N >> K;
  long long mod = 1000000007;
  vector<vector<long long> > dp(N + 1, vector<long long>(3300 + 1, 0));
  if (K >= N) dp[N][1] = 1;
  dp[N][0] = K + 1 - dp[N][1];
  for (long long i = (N)-1; i >= (1); i--) {
    long long d = K - i;
    if (d > 0)
      for (long long j = (0); j < (3300 + 1); j++) {
        dp[i][j] += d * dp[i + 1][j];
        dp[i][j] %= mod;
      }
    for (long long a = (0); a < (min(K, i) + 1); a++) {
      for (long long j = (0); j < (3300 + 1); j++) {
        long long s = j + (a + j) / i;
        if (s <= 3300) {
          dp[i][s] += dp[i + 1][j];
          dp[i][s] %= mod;
        }
      }
    }
  }
  long long ans = K * (K - 1) % mod;
  ans = (ans * modpow(2, mod - 2, mod)) % mod;
  ans = (ans * N) % mod;
  ans = (ans * modpow(K + 1, N, mod)) % mod;
  for (long long i = (0); i < (3300 + 1); i++) {
    ans -= i * dp[1][i];
    ans = (ans % mod + mod) % mod;
  }
  cout << ans << endl;
  return 0;
}
