#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-6;
const long long mod = 1000000007;
inline string getstr(string &s, long long l, long long r) {
  string ret = "";
  for (long long i = l; i <= r; i++) ret.push_back(s[i]);
  return ret;
}
long long modpow(long long x, long long y, long long md = mod) {
  if (y == 0) return 1;
  long long ret = modpow(x, y >> 1, md);
  ret = (long long)ret * ret % md;
  if (y & 1) ret = (long long)ret * x % md;
  return ret;
}
long long n, k;
inline long long inv(long long x) { return modpow(x, mod - 2, mod); }
long long dp[105][205 * 105];
long long sum;
inline void add(long long &x, long long y) { (x += y) %= mod; }
inline void sub(long long &x, long long y) {
  (x -= y) %= mod;
  (x += mod) %= mod;
}
signed main() {
  cin >> n >> k;
  sum = n * modpow(k + 1, n - 1, mod) % mod * k % mod * (k + 1) % mod * inv(2) %
        mod;
  dp[k + 1][0] = 1;
  for (long long i = k + 1; i > 1; i--) {
    for (long long j = 0; j <= 200 * 100; j++) {
      for (long long v = 0; v <= k; v++) {
        if (v > i - 1)
          add(dp[i - 1][j], dp[i][j]);
        else
          add(dp[i - 1][j + (j + v) / (i - 1)], dp[i][j]);
      }
    }
  }
  for (long long i = 1; i <= 200 * 100; i++) {
    sub(sum, dp[1][i] * i * modpow(k + 1, n - k, mod) % mod);
  }
  cout << sum << endl;
  return 0;
}
