def how_many_ways(n, x):

    ways = 0

    for i in range(1, n-1):

        for j in range(i+1, n):

            for k in range(j+1, n+1):

                if i+j+k == x:

                    ways += 1



    return ways



def main():

    while True:

        n, x = [int(x) for x in input().split()]

        if n == x == 0:

            break



        print((how_many_ways(n, x)))



if __name__ == '__main__':

    main()



while True:

    n, x = list(map(int, input().split()))

    if n == x == 0:

        break



    count = 0



    for i in range(1, n+1):

        for j in range(i+1, n+1):

            k = x - i - j



            if not (j < k <= n):

                continue



            count += 1



    print(count)



def how_many_ways(n, x):
    ways = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    ways += 1
    return ways


def main():
    while True:
        n, x = [int(x) for x in input().split()]
        if n == x == 0:
            break
        print((how_many_ways(n, x)))


if __name__ == "__main__":
    main()

while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    count = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            k = x - i - j
            if not (j < k <= n):
                continue
            count += 1
    print(count)

-def how_many_ways(n, x): -    ways = 0 -    for i in range(1, n - 1): -        for j in range(i + 1, n): -            for k in range(j + 1, n + 1): -                if i + j + k == x: -                    ways += 1 -    return ways - - -def main(): -    while True: -        n, x = [int(x) for x in input().split()] -        if n == x == 0: -            break -        print((how_many_ways(n, x))) - - -if __name__ == "__main__": -    main() +while True: +    n, x = list(map(int, input().split())) +    if n == x == 0: +        break +    count = 0 +    for i in range(1, n + 1): +        for j in range(i + 1, n + 1): +            k = x - i - j +            if not (j < k <= n): +                continue +            count += 1 +    print(count)