#!/usr/bin/ruby
# -*- coding: utf-8 -*-

def nwa(n, x)
  count = 0
  (1..n).each{|i|
    (1..(i-1)).each{|j|
      (1..(j-1)).each{|k|
#       printf("%d %d %d\n", i,j,k)
        if i+j+k == x then
          count += 1
#          printf("count=%d\n", count)
        else
        end
      }}}
  count
end

if __FILE__ == $0
  while gets
    fl=$_.chomp.split.map{|x| x.to_i}
    n = fl[0]
    x = fl[1]
    if n==0 and x==0 then break end
    puts nwa(n,x)
  end
end