#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long inf = 1000000001;
const long long INF = (long long)1e18 + 1;
const long long MOD = 1000000007;
const double pi = 3.14159265358979323846;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
long long mod_pow(long long x, long long p, long long M = MOD) {
  long long a = 1;
  while (p) {
    if (p % 2) a = a * x % M;
    x = x * x % M;
    p /= 2;
  }
  return a;
}
long long mod_inverse(long long a, long long M = MOD) {
  return mod_pow(a, M - 2, M);
}
int n, k;
int m = 600;
int main() {
  cin >> n >> k;
  vector<vector<long long>> p(n + 1, vector<long long>(m)),
      dp(n + 1, vector<long long>(m));
  vector<vector<vector<pair<long long, long long>>>> zen(
      n + 1, vector<vector<pair<long long, long long>>>(m));
  zen[n][0].push_back(pair<long long, long long>(1, 0));
  for (int i = n; i >= 0; i--) {
    for (int j = 0; j < (m); j++) {
      if (zen[i][j].size() == 0) continue;
      for (int l = 0; l < (zen[i][j].size()); l++) {
        (p[i][j] += zen[i][j][l].first) %= MOD;
        ;
      }
      for (int l = 0; l < (zen[i][j].size()); l++) {
        (dp[i][j] += zen[i][j][l].second *
                     (zen[i][j][l].first * mod_inverse(p[i][j] % MOD)) % MOD) %=
            MOD;
      }
      if (i == 0) {
        continue;
      }
      for (int x = 0; x < (k + 1); x++) {
        long long nj, add;
        if (x > i) {
          nj = j;
          add = 0;
        } else {
          int ma = x + j;
          nj = j + ma / i;
          add = ma / i;
        }
        pair<long long, long long> pdp;
        pdp.first = p[i][j] * mod_inverse(k + 1) % MOD;
        pdp.second = (dp[i][j] + add * i % MOD) % MOD;
        zen[i - 1][nj].push_back(pdp);
      }
    }
  }
  long long ans = 0;
  for (int j = 0; j < (m); j++) {
    ans += p[0][j] * j % MOD;
    ans %= MOD;
  }
  ans = ans * mod_pow(k + 1, n) % MOD;
  long long al = 0;
  for (int x = 0; x < (k + 1); x++) {
    al += x * mod_pow(k + 1, n - 1) % MOD;
    al %= MOD;
  }
  al = al * n % MOD;
  ans = (al - ans + MOD) % MOD;
  cout << ans << endl;
}
