fun main(args: Array<String>) {
    while(true){
        val (n,x) = readLine()!!.split(" ").map { it.toInt() }
        if(n == 0 && x == 0) break
        var count = 0
        loop@for(i in 1..n){
            for(j in (i+1)..n){
                val k = x - i - j
                if(k <= j) continue@loop
                if(k <=n)
                    count++
            }
        }
        println(count)
    }
}

