while (n, x = gets.split(" ").map(&:to_i)) != [0, 0]
  c = 0
  for i in 1..n-2
    for j in i+1..n-1
      for k in j+1..n
        if i + j + k == x
          c += 1
        end
      end
    end
  end
  puts c
end

