  1 while (n, x = gets.split.map(&:to_i)) != [1, 0] do
  2 
  3   count = 0
  4   for i in 1..n do
  5     for j in (i+1)..n do
  6       for k in (j+1)..n do
  7         if  i + j + k == x then
  8           count += 1
  9         end
 10       end
 11     end
 12   end
 13 
 14   puts count
 15 
 16 end