import scala.collection.mutable
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    while (true) {

      val in = StdIn.readLine().split(" ").map(_.toInt)
      if (in(0) == 0 && in(1) == 0) { return }

      val set = mutable.Set[Set[Int]]()
      for(i <- 1 to in(0); j <- 1 to in(0); k <- 1 to in(0)){
        if(Set(i,j,k).size == 3 && i + j + k == in(1)){
          set += Set(i,j,k)
        }
      }
      println(set.size)
    }
  }
}