#include <bits/stdc++.h>

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;


template <typename T, T mod = static_cast<T>(1000000007)>
class ModNum
{
    static_assert(mod > 0, "Modulo should be positive.");

public:
    ModNum() : value{0} {}

    ModNum(const T val) : value{((val % mod) + mod) % mod} {}

    ModNum(const ModNum<T, mod>& n) : value{n()} {}

    ModNum<T, mod>& operator=(const ModNum<T, mod>& n)
    {
        value = n();
        return (*this);
    }
    ModNum<T, mod>& operator=(const T v)
    {
        value = ((v % mod) + mod) % mod;
        return (*this);
    }

    ModNum<T, mod> operator-() const
    {
        return ModNum{(-value + mod) % mod};
    }
    ModNum<T, mod> operator+(const ModNum<T, mod>& val) const
    {
        return ModNum{(value + val()) % mod};
    }
    ModNum<T, mod> operator-(const ModNum<T, mod>& val) const
    {
        return ModNum{(value - val() + mod) % mod};
    }
    ModNum<T, mod> operator*(const ModNum<T, mod>& val) const
    {
        return ModNum{(value * val()) % mod};
    }
    ModNum<T, mod>& operator+=(const ModNum<T, mod>& val)
    {
        value = (value + val()) % mod;
        return (*this);
    }
    ModNum<T, mod>& operator-=(const ModNum<T, mod>& val)
    {
        value = (value - val() + mod) % mod;
        return (*this);
    }
    ModNum<T, mod>& operator*=(const ModNum<T, mod>& val)
    {
        value = (value * val()) % mod;
        return (*this);
    }
    ModNum<T, mod> operator+(const T val) const
    {
        return ModNum{(value + val) % mod};
    }
    ModNum<T, mod> operator-(const T val) const
    {
        return ModNum{(value - val + mod) % mod};
    }
    ModNum<T, mod> operator*(const T val) const
    {
        return ModNum{(value * val) % mod};
    }
    ModNum<T, mod>& operator+=(const T val)
    {
        value = (value + val) % mod;
        return (*this);
    }
    ModNum<T, mod>& operator-=(const T val)
    {
        value = (value - val + mod) % mod;
        return (*this);
    }
    ModNum<T, mod>& operator*=(const T val)
    {
        value = (value * val) % mod;
        return (*this);
    }
    T operator()() const
    {
        return value;
    }

private:
    T value;
};
template <typename T, T mod>
ModNum<T, mod> operator+(const T val, const ModNum<T, mod>& n)
{
    return ModNum<T, mod>{(n() + val) % mod};
}
template <typename T, T mod>
ModNum<T, mod> operator-(const T val, const ModNum<T, mod>& n)
{
    return ModNum<T, mod>{(n() - val + mod) % mod};
}
template <typename T, T mod>
ModNum<T, mod> operator*(const T val, const ModNum<T, mod>& n)
{
    return ModNum<T, mod>{(n() * val) % mod};
}
template <typename T, T mod>
istream& operator>>(istream& is, ModNum<T, mod>& n)
{
    T v;
    auto& i = (is >> v);
    n = v;
    return i;
}
template <typename T, T mod>
ostream& operator<<(ostream& os, const ModNum<T, mod>& n)
{
    os << n();
    return os;
}

using mint = ModNum<int, static_cast<int>(MOD)>;
using mll = ModNum<ll, MOD>;

mll power(const mll& p, const ll n)
{
    if (n == 0) {
        return mll{1};
    }
    if (n % 2 == 1) {
        return power(p, n - 1) * p;
    } else {
        const auto& pp = power(p, n / 2);
        return pp * pp;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    const ll MAX = N * K;
    auto a = mll{K + 1};
    const mll total = power(a, N - 1) * (K * (K + 1) / 2) * N;

    vector<vector<mll>> dp(N + 1, vector<mll>(MAX + 1, 0));  //最後からiマス分でj回操作するパターン数
    dp[0][0] = 1;
    for (ll i = 1; i <= N; i++) {
        for (ll j = 0; j <= MAX; j++) {
            dp[i][j] += dp[i - 1][j] * max(0LL, K - N + i - 1);
        }
        for (ll j = 0; j <= MAX; j++) {
            if (dp[i - 1][j]() == 0) {
                continue;
            }
            for (ll a = 0; a <= min(K, N - i + 1); a++) {
                const ll tot = (a + j) / (N - i + 1) + j;
                dp[i][tot] += dp[i - 1][j];
            }
        }
    }
    mll use{0};
    for (ll j = 1; j <= MAX; j++) {
        use += dp[N][j] * j;
    }
    cout << total - use << endl;

    return 0;
}


Measured memory_bytes: 8192