while true
  n,x = gets.chomp.split(" ").map &:to_i
  break if n == 0 and x == 0

  c = 0
  n.times { |i|
    (i+2..n).each { |j|
       if 0 < x-(i+1+j) and x-(i+1+j) <= n
         if x-(i+1+j) != i+1 and x-(i+1+j) != j
           c += 1
         end
        end
    }
  }
  puts c
end