

fun main() {
    val mod = 1000000007
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val factorial = LongArray(m + 1){1L}
    val div = LongArray(m + 1) {1L}
    val inverse = LongArray(m + 1) {1L}

    for (i in 2 .. m) {
        factorial[i] = i * factorial[i - 1] % mod
        div[i] = (mod - mod / i) * div[mod % i] % mod
        inverse[i] = div[i] * inverse[i - 1] % mod
    }
    fun combination(n: Int, r: Int): Long {
        return factorial[n] * inverse[n - r] % mod * inverse[r] % mod
    }
    fun permutation(n: Int, r: Int): Long {
        return factorial[n] * inverse[n - r] % mod
    }
    var result = permutation(m, n)
    for (i in 1 .. n) {
        if ((i and 1) == 1) {
            result = (result + mod - combination(n, i) * permutation(m - i, n - i) % mod) % mod
        }else {
            result = (result + combination(n, i) * permutation(m - i, n - i)) % mod
        }
    }
    result = result * permutation(m, n) % mod
    println(result)
}
