while True:

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

    if n == x == 0:

        break

    count = 0

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

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

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

                if i + j + k == x:

                    count += 1

    print(count)
while True:

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

    if n == x == 0:

        break

    count = 0

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

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

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

                if x - (i + j + k) == 0:

                    count += 1

                if x - (i + j + k) < 0:

                    break

    print(count)
while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    count += 1
    print(count)

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

-                if i + j + k == x: +                if x - (i + j + k) == 0: +                if x - (i + j + k) < 0: +                    break