from itertools import combinations



if __name__ == '__main__':

    while True:

        # ?????????????????\???

        data = [int(x) for x in input().split(' ')]

        upper_limit = data[0]

        target_number = data[1]

        if upper_limit == 0 and target_number == 0:

            break



        # ????????????????????????

        choices = combinations(list(range(1, upper_limit+1)), 3)



        # ????¨???????X????????´????????°????¢????????????????

        hit_count = 0

        for c in choices:

            # print(c)

            if sum(c) == target_number:

                hit_count += 1

        print(hit_count)
# -*- 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:])

    
from itertools import combinations

if __name__ == "__main__":
    while True:
        # ?????????????????\???
        data = [int(x) for x in input().split(" ")]
        upper_limit = data[0]
        target_number = data[1]
        if upper_limit == 0 and target_number == 0:
            break
        # ????????????????????????
        choices = combinations(list(range(1, upper_limit + 1)), 3)
        # ????¨???????X????????´????????°????¢????????????????
        hit_count = 0
        for c in choices:
            # print(c)
            if sum(c) == target_number:
                hit_count += 1
        print(hit_count)

# -*- 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 -*- +""" +http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp +""" +import sys +from sys import stdin +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) + + -    while True: -        # ?????????????????\??? -        data = [int(x) for x in input().split(" ")] -        upper_limit = data[0] -        target_number = data[1] -        if upper_limit == 0 and target_number == 0: -            break -        # ???????????????????????? -        choices = combinations(list(range(1, upper_limit + 1)), 3) -        # ????¨???????X????????´????????°????¢???????????????? -        hit_count = 0 -        for c in choices: -            # print(c) -            if sum(c) == target_number: -                hit_count += 1 -        print(hit_count) +    main(sys.argv[1:])