import scala.util.control.Breaks
object Main extends App {

  val b = new Breaks

  b.breakable {
    while (true) {
      val Seq(n, x) = readLine().split(' ').map(_.toInt).toList

      if (n == 0 && x == 0) b.break

      val nums = for {
        i <- 1 to n
        j <- 1 until i
        k <- 1 until j
      } yield { (i, j, k) }

      val ans = nums.count(t => t._1 + t._2 + t._3 == x)

      println(ans)
    }
  }
}
