object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually {
      val Array(n, x, _*) = io.StdIn.readLine().split(" ").map(_.toInt)
      (n, x)
    }.takeWhile {
      case (0, 0) => false
      case _ => true
    }.foreach { case (n, x) =>
      val count =
        (1 to n - 2).map { i =>
          val v = x - i
          (i + 1 to n.min(v / 2)).count { j =>
            val pair = v - j
            j < pair && pair <= n
          }
        }.sum

      println(count)
    }
  }
}