loop {
  n, x = gets.split(" ").map(&:to_i)

  if n+x == 0
    break
  end

  y = 0

  for i in 1..n
    for j in i+1..n
      for k in j+1..n
        if i + j + k == x
          y += 1
        end
      end
    end
  end    
}