object Main extends App {
  import scala.collection.mutable
  import scala.io.StdIn._

  val mod = 1000000007L
  val Array(n, m) = readLine.trim.split(' ').map(_.toLong)
  if (n == 1) println((m + 1) % mod)
  else {
    val maxDiff = (m / (n - 1)) % mod
    println((((((m + 1) % mod) * maxDiff * 2) % mod + (m + 1) % mod - (maxDiff * (maxDiff + 1) % mod) * (n - 1)) % mod + mod) % mod)
  }

  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}
