#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 1000000007;

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

ll dp[101][5000];

ll naive(ll n, ll k){
    ll ret = 0;
    REP(x,powll(k+1,n)){
        VI a(n);
        ll tmp = x;
        REP(i,n){
            a[i] = tmp % (k+1);
            tmp /= k+1;
        }
        while (1){
            bool found = false;
            REP(i,n){
                if (a[i] == i+1){
                    a[i] = 0;
                    REP(j,i) a[j]++;
                    found = true;
                    break;
                }
            }
            if (!found) break;
        }
        REP(i,n) ret += a[i];
    }
    return ret;
}

int main() {
    ll n, k;
    cin >> n >> k;

    ll all = k * n;
    REP(i,n) all = (all * (k+1)) % mod;
    all = divll(all, 2);

    dp[n][0] = 1;
    FORR(i,n,1){
        REP(j,5000){
            if (dp[i][j] == 0) continue;
            REP(x,k+1){
                if (x > i) dp[i-1][j] = (dp[i-1][j] + dp[i][j]) % mod;
                else dp[i-1][j+(j+x)/i] = (dp[i-1][j+(j+x)/i] + dp[i][j]) % mod;
            }
        }
    }

    ll ans = all;
    REP(j,5000) ans = (ans - j * dp[0][j] + 50000 * mod) % mod;

    // cout << all << endl;

    // REP(i,n+1){
    //     REP(j,10) cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    cout << ans << endl;

    // cout << naive(n,k) << endl;
    return 0;
}


