loop do

n, x = gets.split.map{|v|
  v.to_i
}
  if n == 0 && x == 0
    break
  end
  count = 0
  for i in 1..n
    for j in i+1..n
      for k in j+1..n
        if x == i + j + k
          count += 1
        end
      end
    end
  end

print count, "\n"

end
