while True:

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

    if n == x == 0:

        break

    cnt = 0

    upper_max_value = min(x - 3, n)

    lower_max_value = max(int(x / 3), 3)

    for i in range(upper_max_value, lower_max_value - 1, -1):

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

            for k in range(j - 1, 0, -1):

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

                    cnt += 1

    print(cnt)
while True:

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

    if n == x == 0:

        break

    max_a = min(x - 3, n)

    min_a = max(x // 3 + 1, 3)

    cnt = 0

    for i in range(min_a, max_a + 1):

        max_b = min(i - 1, x - i - 1)

        min_b = (x - i) // 2 + 1

        cnt += (max_b - min_b + 1)

    print(cnt)
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    cnt = 0
    upper_max_value = min(x - 3, n)
    lower_max_value = max(int(x / 3), 3)
    for i in range(upper_max_value, lower_max_value - 1, -1):
        for j in range(i - 1, 1, -1):
            for k in range(j - 1, 0, -1):
                if (i + j + k) == x:
                    cnt += 1
    print(cnt)

while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    max_a = min(x - 3, n)
    min_a = max(x // 3 + 1, 3)
    cnt = 0
    for i in range(min_a, max_a + 1):
        max_b = min(i - 1, x - i - 1)
        min_b = (x - i) // 2 + 1
        cnt += max_b - min_b + 1
    print(cnt)

+    max_a = min(x - 3, n) +    min_a = max(x // 3 + 1, 3) -    upper_max_value = min(x - 3, n) -    lower_max_value = max(int(x / 3), 3) -    for i in range(upper_max_value, lower_max_value - 1, -1): -        for j in range(i - 1, 1, -1): -            for k in range(j - 1, 0, -1): -                if (i + j + k) == x: -                    cnt += 1 +    for i in range(min_a, max_a + 1): +        max_b = min(i - 1, x - i - 1) +        min_b = (x - i) // 2 + 1 +        cnt += max_b - min_b + 1