object Main extends App {
  val scanner = new java.util.Scanner(System.in)

  val inputs = Iterator.continually {
    val n = scanner.nextInt()
    val x = scanner.nextInt()

    (n, x)
  }

  val outputs = inputs.takeWhile(_ != (0, 0)).map {
    case (n, x) =>
      val comb = for {
        a <- 1 to n
        b <- (a+1) to n
        c <- (b+1) to n
        if a + b + c == x
      } yield (a, b, c)

      comb.size
  }

  outputs.foreach(println)
}