#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
def aux(n, x)
  count=0
  for i in 3..n
    for j in 2..(i-1)
      for k in 1..(j-1)
        if i+j+k == x
          count += 1
          #puts "i: #{i}, j: #{j}, k: #{k} count=#{count}"
        end
      end
    end
  end

  count
end

def main
  dat=[]
  fh=STDIN
  #fh=File.new("x.txt", "r")
  while fh.gets
    l=$_.chomp.split.map {|x| x.to_i}
    break if l[0]==0 and l[1]==0
    #puts "l0: #{l[0]}, l1: #{l[1]}"
    dat.push(l)
  end

  dat.each { |x|
    puts aux(x[0],x[1]);
  }
end

if $0 == __FILE__ then
  main
end
