fun main(args: Array<String>) {
    while (true) {
        val inStr = readLine() ?: return;
        val (n, x) = inStr.split(' ').map { e -> e.toInt() }

        if ((n == 0) && (x == 0)) {
            return
        }
        val t = countCombination(n, x)
        println(t)
    }
}

fun countCombination(n: Int, x: Int): Int{
    var t: Int = 0

    for (i1 in 1..(n - 2)) {
        for (i2 in (i1+1)..(n - 1)) {
            for (i3 in (i2+1)..n) {
                val sum = i1 + i2 + i3
                if (sum == x) {
                    ++t
                }
            }
        }
    }

    return t
}

