while true
        input = STDIN.gets.split(' ')
        n = input[0].to_i
        x = input[1].to_i
        break if n == 0 && x == 0

        count = 0
        (1..n).each {|i|
                e = i + 1
                (e..n).each {|j|
                        f = j + 1
                        (f..n).each {|k|
                                count += 1 if (i + j + k) == x
                        }
                }
        }

        puts count

end