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 _ =>
        val counter = makeCounter
        countCombinations(n, x, counter)
        println(counter() - 1)
        execute(sc.nextInt(), sc.nextInt())
    }
  }

  def makeCounter: () => Int = {
    var cnt = 0
    () => cnt += 1; cnt
  }

  def countCombinations(end: Int, sum: Int, cnt: () => Int): Unit = {
    for (i <- 1 to end; j <- i + 1 to end; k <- j + 1 to end) {
      if (i + j + k == sum) cnt()
    }
  }
}