n,x = gets.chomp.split(" ").map &:to_i
c = 0
n.times { |i|
  (i+2..n).each { |j|
     if 0 < x-(i+1+j) and x-(i+1+j) <= n
       if x-(i+1+j) != i+1 and x-(i+1+j) != j
         c += 1
       end
      end
  }
}
puts c