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

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }
const int MOD = 1e9 + 7;
typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const long long& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator<<(ostream& os, const mi& a) { return os << a.val; }
    friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
    friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
    mi operator-() const { return mi(-val); }
    mi& operator+=(const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator-=(const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator*=(const mi& m) { val = (long long) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, long long p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator/=(const mi& m) { return (*this) *= inv(m); }
    friend mi operator+(mi a, const mi& b) { return a += b; }
    friend mi operator-(mi a, const mi& b) { return a -= b; }
    friend mi operator*(mi a, const mi& b) { return a *= b; }
    friend mi operator/(mi a, const mi& b) { return a /= b; }
};
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<vector<mi>> dp(n, vector<mi>(n * n + 1, 0));
    for (int i = n - 1; i >= 0; i--) {
        if (i == n - 1) {
            dp[i][0] = 1;
        } else {
            // how much i+1 pushes back
            for (int a = 0; a <= n * n; a++) {
                if (dp[i + 1][a] == 0) {
                    continue;
                }
                // how much i+1 has
                for (int b = 0; b <= k; b++) {
                    if (b <= i + 2) {
                        dp[i][a + (a + b) / (i + 2)] += dp[i + 1][a];
                    } else {
                        dp[i][a] += dp[i + 1][a];
                    }
                   
                }
            }
        }
    }
    vector<mi> po(n + 5);
    po[0] = 1;
    for (int i = 1; i < n + 5; i++) {
        po[i] = po[i - 1] * (k + 1);
    }
    mi ans = 0;
    for (int i = 0; i < n; i++) {
        for (int a = 0; a <= min(i + 1, k); a++) {
            for (int b = 0; b <= n * n; b++) {
                if (dp[i][b] == 0) {
                    continue;
                }
                int times = (a + b) / (i + 1);
                ans += times * dp[i][b] * po[i];
            }
        }
    }
    mi tot = k * (k + 1) / 2 * po[n - 1] * n;
    ans = tot - ans;
    cout << ans << '\n';
    return 0;
}
