import java.util.Scanner

object HowManyWays {
  val sc = new Scanner(System.in)
  var n = 0
  var x = 0

  def input()  {
    n = sc.nextInt()
    x = sc.nextInt()
    // println("n = " + n)
    // println("x = " + x)
  }
  def listProduct(): Int = {
    val a = List.range(1, n + 1)
    // println(a)
    val b = a.combinations(3).map(l => l.sum).toList

    val c = b.count(p => p == x)
    // println(c)
    c
  }
  def run: Unit = {
    input()
    while (n != 0 && x != 0) {
      println( listProduct() )
      input()
    }
  }
}
object Main extends App{
  HowManyWays.run

}