#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <class A, class B>
ostream &operator<<(ostream &out, vector<pair<A, B>> a);
template <class A>
ostream &operator<<(ostream &out, vector<A> a);
template <class A, class B>
ostream &operator<<(ostream &out, pair<A, B> a) {
  out << a.first << " " << a.second;
  return out;
}
template <class A, class B>
ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
  for (pair<A, B> x : a) out << x.first << " " << x.second << '\n';
  return out;
}
template <class A>
ostream &operator<<(ostream &out, vector<A> a) {
  for (A x : a) out << x << ' ';
  return out;
}
template <class A, class B>
istream &operator>>(istream &in, pair<A, B> &a) {
  in >> a.first >> a.second;
  return in;
}
template <class A>
istream &operator>>(istream &in, vector<A> &a) {
  for (A &x : a) in >> x;
  return in;
}
}  // namespace IO
using namespace IO;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long M = 1e9 + 7;
long long bp(long long a, long long b) {
  if (b == 0) return 1;
  long long x = bp(a, b / 2);
  x = (x * x) % M;
  if (b % 2) x = x * a % M;
  return x;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<vector<long long>> dp(n + 1, vector<long long>(1e4, 0));
  for (long long i = (1); i < (long long)(n + 1); ++i)
    for (long long j = (0); j < (long long)(dp[i].size()); ++j) {
      for (long long m = (0); m < (long long)(k + 1); ++m) {
        long long incr = (m > i ? 0 : (m + j) / i);
        if (j + incr < dp[i].size()) {
          dp[i][j] += dp[i - 1][j + incr] +
                      (m > i ? m + j : (m + j) % i) * bp(k + 1, i - 1);
          dp[i][j] %= M;
        }
      }
    }
  cout << (dp[n][0]) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(30);
  long long q = 1;
  while (q--) solve();
}
