# -*- coding: utf-8 -*-

"""

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp



"""

import sys

from sys import stdin

from itertools import combinations

input = stdin.readline





def main(args):

    while True:

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

        if n == 0 and x == 0:

            break



        ans = 0

        for c in combinations(list(range(1, n+1)), 3):

            if sum(c) == x:

                ans += 1



        print(ans)





if __name__ == '__main__':

    main(sys.argv[1:])

    
# -*- coding: utf-8 -*-

"""

"""

import sys

from sys import stdin

from math import factorial

input = stdin.readline





def solve(n, x):

    ans = 0

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

        for b in range(a+1, n+1):

            if b < (x - a - b) <= n:

                ans += 1

    return ans





def main(args):

    while True:

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

        if n == 0 and x == 0:

            break

        ans = solve(n, x)

        print(ans)





if __name__ == '__main__':

    main(sys.argv[1:])



# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp
"""
import sys
from sys import stdin
from itertools import combinations

input = stdin.readline


def main(args):
    while True:
        n, x = list(map(int, input().split()))
        if n == 0 and x == 0:
            break
        ans = 0
        for c in combinations(list(range(1, n + 1)), 3):
            if sum(c) == x:
                ans += 1
        print(ans)


if __name__ == "__main__":
    main(sys.argv[1:])

# -*- coding: utf-8 -*-
"""
"""
import sys
from sys import stdin
from math import factorial

input = stdin.readline


def solve(n, x):
    ans = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            if b < (x - a - b) <= n:
                ans += 1
    return ans


def main(args):
    while True:
        n, x = list(map(int, input().split()))
        if n == 0 and x == 0:
            break
        ans = solve(n, x)
        print(ans)


if __name__ == "__main__":
    main(sys.argv[1:])

-http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp -from itertools import combinations +from math import factorial + + +def solve(n, x): +    ans = 0 +    for a in range(1, n + 1): +        for b in range(a + 1, n + 1): +            if b < (x - a - b) <= n: +                ans += 1 +    return ans -        ans = 0 -        for c in combinations(list(range(1, n + 1)), 3): -            if sum(c) == x: -                ans += 1 +        ans = solve(n, x)