#include <bits/stdc++.h>
using namespace std;
long long int n, K;
long long int dp[105][1005];
long long int dat[10];
long long int td[10];
long long int greed(int no) {
  long long int res = 0;
  if (no == n) {
    for (int i = 0; i < ((int)(n)); i++) td[i] = dat[i];
    for (;;) {
      bool fd = false;
      for (int i = 0; i < ((int)(n)); i++) {
        if (td[i] == i + 1) {
          fd = true;
          td[i] = 0;
          for (int j = 0; j < ((int)(i)); j++) td[j]++;
          break;
        }
      }
      if (!fd) break;
    }
    for (int i = 0; i < ((int)(n)); i++) res += td[i];
  } else {
    for (int i = ((int)(0)); i <= ((int)(K)); i++) {
      dat[no] = i;
      res += greed(no + 1);
    }
  }
  return res;
}
int nps[105] = {};
int main(void) {
  scanf("%lld%lld", &n, &K);
  nps[n] = 0;
  for (int i = ((int)(n - 1)); i >= ((int)(1)); i--) {
    nps[i] = 1 + nps[i + 1] + nps[i + 1] / (i + 1);
    nps[i];
  }
  long long int nk = 1;
  for (int i = ((int)(1)); i <= ((int)(n)); i++) {
    for (int p = ((int)(0)); p <= ((int)(nps[i])); p++) {
      long long int s = 0;
      for (int t = ((int)(0)); t <= ((int)(K)); t++) {
        long long int ds;
        if (i == 1) {
          if (t <= 1) {
            ds = 0;
          } else
            ds = t + p;
        } else {
          int tn = p;
          long long int c = t + p;
          if (t <= i) {
            tn += (t + p) / i;
            c = (t + p) % i;
          }
          ds = ((c * nk) % (1000000007LL) + dp[i - 1][tn]) % (1000000007LL);
        }
        s = (s + ds) % (1000000007LL);
      }
      dp[i][p] = s;
    }
    nk = (nk * (K + 1)) % (1000000007LL);
  }
  printf("%lld\n", dp[n][0]);
  return 0;
}
