def read_inputs
  inputs = []
  loop do
    input = gets.split(" ").map(&:to_i)
    case input
      when [0, 0] then break
      else inputs << input
    end
  end
  inputs
end

def countWays(n, x)
  (1..n).map {|a|
    sb = a + 1
    next 0 if sb > n
    [*sb..n].map {|b|
      sc = b + 1
      next 0 if sc > n
      [*sc..n].map {|c|
        next 0 if a == b || b == c || a == c
        next 1 if a + b + c == x
        0
      }.inject(:+)
    }.inject(:+)
  }.inject(:+)
end

inputs = read_inputs
puts inputs.map {|i| countWays(*i)}.join("\n")