/**
  * 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 dataSets = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" ").map(_.toInt))
      .map { case Array(n, x) => (n, x) }
      .takeWhile(_ != (0, 0))
      .toList
    val results = dataSets.map { case (n, x) =>
      // Memory Limit Exceeded
      // (1 to n).combinations(3).count(_.sum == x)
      (for (a <- 1 to n; b <- 1 to n if a < b; c <- 1 to n if a < c && b < c && (a + b + c) == x)
        yield 1).length
    }
    results.foreach(println)
  }

}