object Main extends App {

  while (true) {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

    if (n == 0 && x == 0) {
      sys.exit()
    }
    var count = 0
    for (a <- 1 to n; b <- a + 1 to n; c <- b + 1 to n if a + b + c == x) {
      count += 1
    }
    println(count)
  }

}
