object Main {

    def main(args: Array[String]): Unit = {
        val sc = new java.util.Scanner(System.in)

        combination(sc)
    }

    def combination(scanner: java.util.Scanner): Unit = {
        val n, x = scanner.nextInt
        var count = 0

        if( n != 0 || x != 0 ) {
            for( i <- 1 to n-2 ) {
                for( j <- i+1 to n-1 ) {
                    if( i < j && j < x-i-j && x-i-j <= n ) count += 1
                }
            }

            println(count)
            combination(scanner)
        }
    }
}
