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

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  unsigned v;
  modular(long long a = 0) : v((a %= M) < 0 ? a + M : a) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m r) { if ((v += r.v) >= M) v -= M; return *this; }
  m& operator-=(m r) { if (v < r.v) v += M; v -= r.v; return *this; }
  m& operator*=(m r) { v = (uint64_t)v * r.v % M; return *this; }
  m& operator/=(m r) { return *this *= power(r, M - 2); }
  friend m operator+(m l, m r) { return l += r; }
  friend m operator-(m l, m r) { return l -= r; }
  friend m operator*(m l, m r) { return l *= r; }
  friend m operator/(m l, m r) { return l /= r; }
  friend bool operator==(m l, m r) { return l.v == r.v; }
  friend string to_string(m a) { return to_string(a.v); }
};

constexpr long long mod = 1e9 + 7;
using mint = modular<mod>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int mx = 0;
  vector<mint> dp(mx + 1, 0), way(mx + 1, 1);
  for (int i = n; i; --i) {
    mx += 1 + mx / i;
    vector<mint> ndp(mx + 1), nway(mx + 1);
    for (int j = 0; j < (int)dp.size(); ++j) {
      for (int x = 0; x <= m; ++x) {
        if (x <= i) {
          int nj = j + (x + j) / i;
          ndp[nj] += (x + j) / i * way[j] + dp[j];
          nway[nj] += way[j];
        } else {
          ndp[j] += dp[j];
          nway[j] += way[j];
        }
      }
    }
    swap(dp, ndp);
    swap(way, nway);
  }
  mint res = power(mint(m + 1), n) * n * m / 2 - accumulate(begin(dp), end(dp), mint(0));
  cout << res.v << '\n';
}
