#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
long long inf = sizeof(long long) == sizeof(long long) ? 2e18 : 1e9 + 10;
long long dx[] = {0, 1, 0, -1};
long long dy[] = {1, 0, -1, 0};
vector<long long> fact;
bool h = false;
void init() {
  h = true;
  fact = vector<long long>(1000000);
  fact[0] = fact[1] = 1;
  for (long long i = 2; i < 1000000; i++)
    fact[i] = fact[i - 1] * i % 1000000007;
}
long long powmod(long long a, long long b, long long m = 1000000007) {
  long long out = 1;
  long long p = a % m;
  while (b) {
    if (b & 1) out = out * p % m;
    p = p * p % m;
    b >>= 1;
  }
  return out;
}
signed main() {
  long long n, k;
  cin >> n >> k;
  long long out = 0;
  vector<vector<long long> > dp(n + 1, vector<long long>(4000));
  dp[0][0] = 1;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < 4000; j++)
      if (dp[i][j])
        for (long long l = 0; l < k + 1; l++) {
          if (l <= n - i)
            dp[i + 1][j + (l + j) / (n - i)] += dp[i][j];
          else
            dp[i + 1][j] += dp[i][j];
        }
  for (long long i = 0; i < 4000; i++)
    (out += dp[n][i] * i % 1000000007) %= 1000000007;
  (out = n * k * (k + 1) / 2 % 1000000007 * powmod(k + 1, n - 1) % 1000000007 -
         out + 1000000007) %= 1000000007;
  cout << out << endl;
}
