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 }

      var count = 0
      for(i <- 1 to in(0); j <- i + 1 to in(0); k <- j + 1 to in(0)){
        if(i + j + k == in(1)){
          count += 1
        }
      }
      println(count)
    }
  }
}