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

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