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

object Main extends App {

  def getResult():Unit = {
    val Array(n,x) = readLine.split(" ").map(_.toInt)
    if( n!=0 || x!=0) {
      println( ( 1 until min(n-1,x/3) ).foldLeft(0) { (sum,i) => sum + max(min(n,(x-i+1)/2)- max(i+1,x-i-n),0)})
      getResult()
    }
  }

  getResult()
}