while line = gets
  n,x = line.split.map { |e| e.to_i }
  break if n == 0 && x == 0
  count = 0
  for i in 1..n-2
    for j in i+1..n-1
      for k in j+1..n
        count += 1 if i+j+k == x
      end
    end
  end
  puts count
end