while line=gets
  (n,x)=line.split().map(&:to_i)
  c=0
  (1..n-2).each do |n1|
    (n1+1..n-1).each do |n2|
      (n2+1..n).each do |n3|
        c+=1 if n1+n2+n3 == x
      end
    end
  end
  puts c
end