import scala.io.StdIn.readLine
import scala.math.{max,min}

object Main extends App {

  var (n,x) = (0,0)
  while({val Array(n2,x2) = readLine.split(" ").map(_.toInt);n=n2;x=x2;(n,x)} != (0,0) ) {
    println(
      ( 1 until min(n-1,x/3) ).foldLeft(0) { (sum,i) =>
        sum + (max(i+1,x-i-n) until min(n,(x-i+1)/2)).length
      }
    )
  }
}