import scala.io.StdIn._

object Main {
  def main(args: Array[String]) {
    def combinationCount(input: String): Unit = {
      if(input != "0 0") {
        val Array(toNum, sumNum) = input.split(" ").map(_.toInt)
        var combinationNum = 0
        for (i <- 1 until toNum - 1;
             j <- i + 1 until toNum;
             k <- j + 1 to toNum; if i + j + k == sumNum) combinationNum += 1
        println(combinationNum)
        combinationCount(readLine())
      }
    }

    combinationCount(readLine())
  }
}