object Main extends App {
  val sc = new java.util.Scanner(System.in)
  execute(sc.nextInt(), sc.nextInt())

  def execute(n: Int, x: Int): Unit = {
    (n, x) match {
      case (0, 0) => sc.close()
      case _ =>
        println((1 to n).combinations(3).filter(_.sum == x).size)
        execute(sc.nextInt(), sc.nextInt())
    }
  }
}