import java.util.Scanner

fun main(args:Array<String>){

    val cin = Scanner(System.`in`)
    val result = mutableListOf<Int>()

    while(true){
	    val n = cin.nextInt()
	    val x = cin.nextInt()

	    if(n + x == 0) break

	    result.add(calc(n, x))
    }

    for(i in result.indices) println(result[i])
}

fun calc(n:Int, x:Int):Int{

    var t:Int = 0

    for(i in 1..n-2){
	    for(j in i+1..n-1){
	        for(k in j+1..n){
		        if(i + j + k == x) t++
	        }
	    }
    }
    return t
}


