while true
  n,x = gets.split.map {|s| s.to_i}
  break if n == 0 && x == 0
  cnt = 0
  for i in 1..n
    for j in i+1..n
      for k in j+1..n
        cnt += 1 if i+j+k == x
      end
    end
  end
  puts cnt
end