/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B
  * Structured Program II - How many ways?
  */
object Main {
  def main(args: Array[String]): Unit = {
    val result = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" ").map(_.toInt))
      .map { case Array(n, x) => (n, x) }
      .takeWhile(_ != (0, 0))
      .map { case (n, x) =>
        (1 to n).combinations(3).count(_.sum == x)
      }
      .toList
    result.foreach(println)
  }
}