fun main(args: Array<String>) = itp1_7_b()

fun itp1_7_b() {
    var (n, x) = readLine()!!.split(' ').map { it.toInt() }

    val answer = StringBuilder()

    while (!(n == 0 && x == 0)) {
        val list = (1..n).toList()
        var count = 0L

        for (fi in list.indices) {
            val first = list[fi]
            for (si in fi + 1..list.lastIndex) {
                val second = list[si]
                val third = x - (first + second)
                if (third > second && third in 1..n) count++
            }
        }

        answer.appendln(count)

        readLine()!!.split(' ').map { it.toInt() }.let {
            n = it[0]
            x = it[1]
        }

    }


    print(answer)
}

