#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = long long;

i64 MOD = 1000000007;

i64 N, M;

int main() {
    cin >> N >> M;
    if (N == 1) {
        cout << (M+1)%MOD << endl;
        return 0;
    }

    i64 k = (M / (N-1)) % MOD;

    i64 a = (2*k+1) % MOD * ((M+1) % MOD) % MOD;
    i64 b = (N-1) % MOD * k % MOD * (k+1) % MOD;
    cout << (a - b + MOD) % MOD << endl;
    // d = 0 -> M - 0 + 1
    // d = 1 -> M - (N-1) + 1
    // d = 2 -> M - 2*(N-1) + 1
    // ...
    // d = k -> M - k*(N-1) + 1
    // where k <= M/(N-1)
    return 0;
}