fun main(args: Array<String>) {
    while (true) {
        var count = 0
        val (n, target) = readLine()?.split(" ")?.map { it.toInt() } ?: return
        if (n == 0 && target == 0) break
        val checker = hashSetOf<CustomTriple>()
        (1..n).forEach { i ->
            for (j in 2..n){
                if(i == j) continue
                for (k in 3..n){
                    if(j == k || k == i) continue
                    if (i + j + k == target) {
                        var hasCombination = false
                        val tri = CustomTriple(i,j,k)
                        for (it in checker)  {
                            if (it.equals(tri)) {
                                hasCombination = true
                                break
                            }
                        }
                        if (!hasCombination){
                            count++
                            checker.add(tri)
                        }
                    }
                }
            }
        }
        println(count)
    }
}

data class CustomTriple(val f: Int, val s: Int, val t:Int){

    override fun equals(other: Any?): Boolean {
        return other != null &&
                other is CustomTriple &&
                (this.f == other.f || this.f == other.s || this.f == other.t) &&
                (this.s == other.f || this.s == other.s || this.s == other.t) &&
                (this.t == other.f || this.t == other.s || this.t == other.t)
    }

    override fun hashCode(): Int {
        return super.hashCode()
    }
}
