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

  c = 0
  n.times { |i|
    if i+2 <= n-1
      s = i+2
      (s..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
      }
    end
  }
  puts c
end