fun main() {
    val (n, k) = readLine()?.split(" ")?.map(String::toLong) ?: return
    val nn = n + 1
    if (nn <= k) {
        println(1L)
        return
    }
    val m = 1000000007L
    val values = 0.until(nn).map {
        it
    }
    val c = nn - k
    val maxValue = values.sum()
    var minSum = maxValue
    var maxSum = maxValue
    var count = ((maxSum - minSum) + 1) % m
    repeat(c.toInt()) {
        minSum -= values[values.size - it - 1]
        maxSum -= values[it]
        count = (count + (maxSum - minSum) + 1) % m
    }
    println(count)
}
