object Main {
  def main(args:Array[String]){
    Iterator.continually(readLine)   
    .map(s => {
      val xs = s.split(" ").map(_.toInt) 
      (xs(0), xs(1))
    })
    .takeWhile{
      case (0, 0) => false
      case _ => true
    }
    .foreach{
      xs =>
      val n = xs._1
      val x = xs._2
      val count = (1 to n).combinations(3)
        .count(ps => ps.sum == x)

      println(count)
    }
  }
}