object Main{
  def main(args:Array[String]){
    val sc=new java.util.Scanner(System.in)
    val b=new scala.util.control.Breaks
    b.breakable{
      while(true){
        val n,x=sc.nextInt()
        if(n==0) b.break
        var ans=0
        for(i<-1 to n;j<-i+1 to n;k<-j+1 to n if i+j+k==x) ans+=1
        println(ans)
      }
    }
  }
}