Problem:


How many ways?

  Write a program which identifies the number of combinations of three integers which satisfy the following conditions:

  
You should select three distinct integers from 1 to n.

  
A total sum of the three integers is x.

  For example, there are two combinations for n = 5 and x = 9.

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

  The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.

  The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.

Constraints

  
3 ≤ n ≤ 100

  
0 ≤ x ≤ 300

Output

  For each dataset, print the number of combinations in a line.

Sample Input

5 9
0 0

Sample Output

2

Note

      解説      

	


Sample input:
5 9
0 0


Sample output:
2

Submission status: Accepted

Solution code:
while 1:
    n, x = map(int,input().split())
    if n == x ==0:
        break
    ans  = 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:
                   ans += 1
    print(ans)

Submission status: Accepted

Solution code:

while True:
    n, x = map(int, input().split())

    if n == 0 and x == 0:
        break

    count = 0
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if i == j:
                break
            else:
                for k in range(1, n + 1):
                    if k == i or k == j:
                        break
                    elif (i + j + k) == x:
                        count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n,x = tuple(int(i) for i in input().split())
    if n == x == 0:
        break
    r = 0
    a = [j for j in range(1,n+1)]
    #print(a)
    for l in a:
        b = [k for k in range(1,l)]
        if len(b) == 0:
            continue
        #print(b)
        for m in b:
            c = [o for o in range(1,m) if l+m+o == x]
            #print(c)
            r += len(c)
            c.clear()
        b.clear()
    print(r)

Submission status: Accepted

Solution code:
def add(n, sum, count, count2, k):
    count += 1
    if k >= sum: 1
    elif count == 3:
        if sum <= n:
            count2 += 1
        #print(sum, count2, count)
    else:
        for i in range(int(sum / 2 - k)):
            j = i + k + 1
            #print(j, count2, count)
            count2 += add(n, sum - j, count, 0, j)
    return count2

while True:
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        break
    print(add(n, m, 0, 0, 0))

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    count = 0
    tou = []
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                if x == (i + j + k):
                    count += 1
                    if i == j or j == k or k == i:
                        count -= 1
                    
    print(count // 6)

Submission status: Accepted

Solution code:
while True:
    n, x = [int(i) for i in input().split(' ')]
    if n == 0 and x == 0: break

    combis = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if x - i - j > j and x - i - j <= n:
                combis += 1
    print(combis)

Submission status: Accepted

Solution code:
while True :
    num = 0
    n,x = map(int,input().split())
    if(n==0 and x==0): break
    for i in range (1,n) :
        for j in range(1,i):
            s = x - j - i
            if(s<=n and j<i and i<s):
                num += 1
    print(num)

Submission status: Accepted

Solution code:
while True:
	n,x = map(int,input().split())
	if (n+x == 0):
		break
	sum =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:
					sum+=1
	print(sum)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break

    ans = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if j < x - i - j <= n:
                ans += 1
            elif x - i - j <= j:
                break
        if i + j >= x:
            break
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
B=[]
while True:
    l=input().split()
    n=int(l[0])
    x=int(l[1])
    if n==0 and x==0:
        break
    else:
        a=list(range(1,n+1))
        b=0
        for i in a:
            for p in a:
                for m in a:
                    if i+p+m==x and i!=p and p!=m and m!=i:
                        b+=1
                    else:
                        pass
        B.append(int(b/6))

for c in B:
    print(c)

Submission status: Accepted

Solution code:
while True:
    count=0
    n,x=map(int,input().split())
    if n==x==0:
        break
    for i in range(1,n+1):
        for j in range(i,n+1):
            for k in range(j,n+1):
                if i+j+k==x and (i!=j and i!=k and k!=j):
                    count+=1
    print(count)

Submission status: Accepted

Solution code:
import sys
import math
 
while 1:
    n, x = map(int , raw_input().split())    
    if n + x == 0:
        break 
    cnt = 0
    for i in xrange(1, n+1):
        for j in xrange(i+1, n+1):
            for k in xrange(j+1, n+1):
                if i + j + k == x:
                    cnt += 1
 
    print cnt

Submission status: Accepted

Solution code:
result = []
while True:
    count, target = map(int, input().split())
    if count == target == 0: break
    lis = [i for i in range(1, count+1)]

    result = 0
    for n1 in lis:
        for n2 in lis[n1:]:
            for n3 in lis[n2:]:
                if n1+n2+n3 == target:
                    result += 1
    
    print(result)

Submission status: Accepted

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

    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break

    comb = set()
    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 or j == k or i == k:
                    continue
                elif i + j + k == x:
                    sort_9 = sorted((i, j, k))
                    comb.add(tuple(sort_9))

    print(len(comb))

Submission status: Accepted

Solution code:
# AOJ ITP1_7_B

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    while True:
        a = numinput()
        n = a[0]; x = a[1]
        if n == 0 and x == 0: break
        # 1からnまでの異なる3つの数の和がxになる数の組の個数。
        count = 0
        for i in range(1, (x // 3) + 1):
            for j in range(i + 1, n + 1):
                if j < x - i - j <= n:
                    count += 1
                    # print(str(i) + " " + str(j) + " " + str(x - i - j))
        print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
while 1:
    sum = 0
    n, x = map(int, input().split())
    if (n == 0 and x == 0):
        break
    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):
                    sum += 1
    print(sum)

Submission status: Accepted

Solution code:
def combination():
    cnt = 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:
                    cnt += 1
    return cnt

while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break

    print(combination())

Submission status: Accepted

Solution code:

while True:
	arr = list(map(int, input().split()))
	n = arr[0]
	x = arr[1]

	if n == 0 and x == 0:
		break
	c = 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:
					c += 1
	print(c)
	c = 0

Submission status: Accepted

Solution code:

while True:
	arr = list(map(int, input().split()))
	n = arr[0]
	x = arr[1]

	if n == 0 and x == 0:
		break
	ans = 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:
					ans += 1
	print(ans)

Submission status: Accepted

Solution code:
def func(n, x):
    ans = 0
    for i in range(1, x // 3):
        for j in range(i+1, x // 2):
            k = x - i - j
            if j < k <= n:
                ans += 1
    return ans


while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    print(func(n,x))

Submission status: Accepted

Solution code:
while True:
    A = 0
    n, x = map(int, input().split())
    if n == x == 0:
        break
    for a in range(1,n+1):
        for b in range(a+1,n+1):
            for c in range(b+1, n+1):
                if a + b + c == x:
                    A += 1
    print(A)

Submission status: Accepted

Solution code:
while 1:
    k=input().split()
    n=int(k[0])
    x=int(k[1])
    if n==0 and x==0 :
        break
    m=0
    for i1 in range(1,n-1):
        for i2 in  range(i1+1,n):
            for i3 in  range(i2+1,n+1):
                if (i1!=i2 and i2!=i3) and (i3!=i1 and x==i1+i2+i3):
                    m+=1
    print(m)

Submission status: Accepted

Solution code:
while True:
    p=0
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    for i in range(1,n+1):
        for j in range(2,n+1):
            if i==j:
                break
            for k in range(3,n+1):
                if i==k or j==k:
                    break
                g=i+j+k
                if x==g:
                    p+=1
    print(p)

Submission status: Accepted

Solution code:
# How many ways?

import math

end = 0
while end == 0:
    a = [int(i) for i in input().rstrip().split()]
    n = a[0]
    x = a[1]
    if n == 0 and x == 0:
        end += 1
    else:        
        if x <= 5 or x >= 298 or 3 * (n - 1) < x:
            ways = 0
            print(ways)
        elif x <= 7:
            ways = 1 # x = 6 のとき (1, 2, 3), x = 7 のとき (1, 2, 4)
            print(ways)
        else: # x >= 8 のとき
            ways = 0 # Initialize
            maximumLow = x // 3 - 1 # 選ぶ数の最小値の最大
            minimumHigh = math.ceil(x / 3) + 1 # 選ぶ数の最大値の最小
            # 最小値を選ぶ
            for i in range(1, maximumLow + 1):
                topTwo = x - i
                minimumMid = i + 1
                maximumMid = topTwo // 2
                minimumHigh = topTwo // 2 + 1
                # 中間値を選ぶ
                for j in range(minimumMid, maximumMid + 1):
                    wantedHigh = x - i - j
                    if minimumHigh <= wantedHigh <= n:
                        ways += 1
            print(ways)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int,input().split())
    if(n==0 and x==0):
        break
    nlist = []
    for i in range(1,n+1):
        nlist.append(i)
    count = 0
    for i1 in range(n-2):
        for i2 in range(i1+1,n-1):
            for i3 in range(i2+1,n):
                y = nlist[i1]+nlist[i2]+nlist[i3]
                if(y == x):
                    count += 1
            
    print(count)

Submission status: Accepted

Solution code:
while True:
	n, x = list(map(int, input().split()))
	if n == x == 0:
		break
	ans = 0
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			sec = x - i - j
			if j < sec <= n:
				ans += 1
	print(ans)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, raw_input().split())
    if n == 0 and x == 0:
        break

    c = 0
    for i1 in range(1, n+1):
        for i2 in range(i1+1, n+1):
            s = x - (i1 + i2)
            if s > i2 and s <= n:
                c += 1
    print(c)

Submission status: Accepted

Solution code:
import sys

i = 0
for line in sys.stdin:
    n,x = line.split()
    n = int(n)
    x = int(x)

    if n == 0 and x == 0: break
    c = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            ij = i + j
            for k in range(j+1, n+1):
                if ij+k == x:
                    c +=1
    print c

Submission status: Accepted

Solution code:
while True:
    n,x = map(int, raw_input().split())
    if n == 0 and x == 0: break
    c = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            ij = i + j
            for k in range(j+1, n+1):
                if ij+k == x:
                    c += 1
    print c

Submission status: Accepted

Solution code:
while True:
    n,x = map(int, raw_input().split())
    if n == 0 and x == 0: break
    c = 0
    for i in range(1, min(n+1,x/3)):
        for j in range(i+1, min(n+1,x/2)):
            for k in range(j+1, n+1):
                ijk = i + j + k
                if ijk == x:
                    c += 1
                    break
                elif ijk > x: break
    print c

Submission status: Accepted

Solution code:
while True:
    n,x = map(int, raw_input().split())
    if n == 0 and x == 0: break
    c = 0
    for i in range(1, min(n-1,x/3)):
        for j in range(i+1, min(n,x/2)):
            for k in range(j+1, n+1):
                ijk = i + j + k
                if ijk == x:
                    c += 1
                    break
                elif ijk > x: break
    print c

Submission status: Accepted

Solution code:
def count(n, x):
    c = 0
    for i in range(1, n-1):
        for j in range(i+1, n,):
            for k in range(j+1, n+1):
                s = i + j + k
                if s == x:
                    c += 1
                    break
                elif s > x: break
    return c

while True:
    p = map(int, raw_input().split())
    if p == [0, 0]: break
    print count(*p)

Submission status: Accepted

Solution code:
while 1:
        p=0
        e=map(int,raw_input().split())
        if e[0]==e[1]==0:
                break
        for i in range(e[0]):
                for j in range (e[0]):
                        for k in range (e[0]):
                                if i+j+k+3==e[1] and i!=j and j!=k and i<j<k:
                                        p+=1
        print p

Submission status: Accepted

Solution code:
from __future__ import division, print_function
from sys import stdin
while True:
    n, x = (int(s) for s in stdin.readline().split())
    if n == 0 and x == 0:
        break
    n += 1
    cnt = 0
    for a in range(1, n):
        if a >= x:
            break
        for b in range(a+1, n):
            ab = a + b
            if ab >= x:
                break
            for c in range(b+1, n):
                abc = ab + c
                if abc == x:
                    cnt += 1
                    break
                if abc > x:
                    break
    print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import timeit
import time
import sys
import io
import re
import math
#start = time.time()
#start = time.clock()
while True:
    l = []
    (n,x)=map(int, raw_input().split())
    if n==x==0:
        break
    ans=0
    for a in range(1,n+1):
        l.append(a)
    for i in l:
        if i > 98: break
        for j in l:
            if j > 99 or i+j>x: break
            p=0
            for k in l:
                p=i+j+k
                if (i != j and j != k and k != i) and p==x and i<j<k:
                    ans+=1
    print ans

#end = time.clock()
#print end - start

Submission status: Accepted

Solution code:
while True:
	n, x = map(int, raw_input().split())
	if (n == 0) and (n == x):
		break
	cnt = 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:
					cnt += 1
				elif (i + j + k) > x:
					break
	print cnt

Submission status: Accepted

Solution code:
while True:
	n, x = map(int, raw_input().split())
	if (n == 0) and (n == x):
		break
	cnt = 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:
					cnt += 1
	print cnt

Submission status: Accepted

Solution code:
while True:
    n,x = map(int,raw_input().split())
    if n == 0 and x == 0:
        break
    count = 0
    for a in xrange(1,n+1):
        for b in xrange(1,n+1):
            if a == b:
                break
            for c in xrange(1,n+1):
                if a == c or b == c:
                    break
                if a+b+c == x:
                    count +=1
    print count

Submission status: Accepted

Solution code:
while 1:
    n, x = map(int, raw_input().split())
    if n == 0: break
    count = 0
    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if i+1 + j+1 + k+1 == x:
                    count += 1
    print count

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, raw_input().split())
    if n == 0 and x == 0:
        break

    count = 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:
                    count += 1
    print count

Submission status: Accepted

Solution code:
while True:
	n, x = map(int, raw_input().split())
	if n + x == 0: break
	ans = 0
	for i in range(1,n-1):
		for j in range(i+1, n):
			for h in range(j+1, n+1):
				if i + j + h == x: ans += 1
	print ans

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
    n, x = map(int, input().strip().split())
    if n == x == 0: break
    print(sum(1 for p in combinations(range(1, n + 1), 3) if sum(p) == x))

Submission status: Accepted

Solution code:
while True:
 n,x=map(int,raw_input().split())
 if n==0 and 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

Submission status: Accepted

Solution code:
while True:
    count = 0
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    for a in range(1,n-1):
        for b in range(a+1,n):
            for c in range(b+1,n+1):
                if a+b+c == x:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
s=[]
while True:
    n,x = map(int, input().split())
    if n==0 and x==0:
        break
    res=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            z=x-i-j
            if j<z<=n:
                res+=1
    s.append(res)
                


for i in range(len(s)):
    print(s[i])

Submission status: Accepted

Solution code:
# 全探索 : 全列挙 (全4問)

# 1 How many ways? (AOJ)

import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

n = 1
x = 1
while True:
    n, x = map(int, input().split())
    if (n, x) == (0, 0):
        sys.exit(0)
    else:
        L = []
        ans = 0
        for i in range(1, n + 1):
            for j in [k for k in range(1, n + 1) if k != i]:
                k = x - (i+j)
                if i != k and j != k and sorted((i,j,k)) not in L and k in range(1, n+1):
                    ans += 1
                    L.append(sorted((i, j, k)))
        print(ans)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    y=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 and j!=k and k!=i and i+j+k==x:
                    y+=1
    print(y)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == 0 and 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)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    ans = 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:
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True :
    n,x=map(int,input().split())
    
    if n==0:
        break
    else :
        s=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 :
                        s+= 1
                        
        print(s)

Submission status: Accepted

Solution code:
import itertools
ans_list = []
while True:
    n, x = [int(i) for i in input().split()]
    if n == 0 and x == 0:
        break
    count_list = []
    for v in itertools.combinations(range(1, n+1), 3):
        if sum(v) == x:
            count_list.append(v)
    ans_list.append(len(count_list))
for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
while(True):
    n,x=(int(s) for s in input().split())
    if n==0 and x==0:
        break
    a=0
    for i in range(1,n):
        for j in range(i+1,min(n,x-i+1)):
            if x-i-j>=j+1 and x-i-j<=n:
                a+=1
    print(a)

Submission status: Accepted

Solution code:
while True:
  s,t= map(int,input().split())
  if s+t == 0:break
  c=0
  for i in range(1,s+1):
    for j in range(i+1,s+1):
      for k in range(j+1,s+1):
        if i+j+k ==t:c+=1
  print(c)

Submission status: Accepted

Solution code:
while True:
    nyuryoku = []
    tomeru = []
    nyuryoku  = (input().split( ))
    tukau = [int(s) for s in nyuryoku]
    if tukau[0] == 0 and tukau[1] == 0:
        break
    else:
        ans = int(0)
        for a in range(1,tukau[0]+1):
            for b in range(1,tukau[0]+1):
                if b <= a:
                    continue
                c = tukau[1]-(a+b)
                if c > b and c <= tukau[0]:
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if n==0 and x==0 :
        break
    cnt=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            if j<x-i-j<=n:
                cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n==0 and x==0:
        break
    c=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:c +=1
    print(c)

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    
    count=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==m:
                    count+=1
                    
    print(count)

Submission status: Accepted

Solution code:
while True: 
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    a=0
    for i in range(1,n+1):
        for j in range(1+i,n+1):
            for k in range(j+1,n+1):
                if (i+j+k)==x:
                    a+=1
    print(a)

Submission status: Accepted

Solution code:
while True:
	n,x=[int(x) for x in input().split()]
	if(n,x)==(0,0): break
	cnt=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: cnt+=1
	print(cnt)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if(n==0 and x==0):
        break
    ans=0
    for i in range(1,n):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if(i+j+k==x):
                        ans=ans+1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if(n==0 and x==0):
        break
    ans=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):
                    ans=ans+1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if(n==0 and x==0):
        break
    ans=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 :
                    ans=ans+1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if(n==0 and x==0):
        break
    s=0
    for i in range(1,n):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if(i+j+k==x):
                    s=s+1
    print(s)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if (n==0 and x==0):
        break
    ans=0
    for i in range(1,n):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if (i+j+k==x):
                    ans+=1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    ans=0
    for i in range(1,n):
        for k in range(i+1,n):
            for j in range(k+1,n+1):
                if i+k+j==x:
                    ans+=1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    if(n == 0 and m == 0):
        break
    ans=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 == m):
                    ans=ans+1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    a=0
    n,x=map(int,input().split())
    if(n==0 and x==0):
        break
    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):
                    a=a+1
                elif(n==0 and x==0):
                    print()
    print(a)

Submission status: Accepted

Solution code:
while 1:
  s,t= map(int,input().split())
  if s+t == 0:break
  c=0
  for i in range(1,s+1):
    for j in range(i+1,s+1):
      for k in range(j+1,s+1):
        if i+j+k ==t:c+=1
  print(c)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
while True:
    n,x=map(int,input().split())
    
    if n+x==0:
        break
    else:
        ans=0
        for i in range(1,n+1):
            for j in range(1,i):
                for k in range(1,j):
                    if i+j+k==x:
                        ans+=1
    
        print(ans)

Submission status: Accepted

Solution code:
import itertools
while True :
    n,x = map(int,input().split())
    if n==0 and x==0 :
        break
    N=list(range(1,n+1))
    l=[]
    for j in itertools.combinations(N, 3):
        X=sum(j)
        if X==x :
            l.append(1)
    print(sum(l))

Submission status: Accepted

Solution code:
ans = []

while True:
    n, x = map(int, input().split())
    count = 0

    if n == x == 0:
        break
    for i in range(1, n-1):
        for j in range(i+1, n):
            k = x - i - j
            if j < k <= n:
                count += 1
    ans.append(count)

print(*ans, sep='\n')

Submission status: Accepted

Solution code:
import itertools
while True:
    n, x = list(map(int, input().split()));
    if (n == 0) and (x == 0):
        break;
    N = [];
    for i in range(1,n+1):
        N.append(i)

    a = 0;
    for c  in itertools.combinations(N, 3):
        if sum(c) == x:
            a += 1;
    print(a);

Submission status: Accepted

Solution code:
while True:
    n,x = map(int,input().split())
    
    if n == 0 and x == 0:
        break
    
    ans = 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:
                    ans += 1
                
    
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    c=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:
                    c+=1
    print(c)

Submission status: Accepted

Solution code:
while True:
    s,t=map(int,input().split())
    if s+t==0:
        break
    c=0
    for i in range(1,s+1):
        for j in range(i+1,s+1):
            for k in range(j+1,s+1):
                if i+j+k ==t:
                    c+=1
    print(c)

Submission status: Accepted

Solution code:
def get_count(n,x):
    count = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if (i+j+k+3) == x:
                    count += 1
    return count

if __name__ == "__main__":
    while True:
        n,x = map(int,input().split())
        if n==0 and x == 0:
            exit()
        else:
            print(get_count(n,x))

Submission status: Accepted

Solution code:
import itertools


while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    count = 0
    for i in itertools.combinations(range(1, n+1), 3):
        if sum(i) == x:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    c=0
    for i in range(1,n+1):
        for j in range(1,n+1):
            if i>=j:
                pass
            else:
                z=x-(i+j)
                if z>j and z<=n:
                    c+=1
    print(c)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    ans = 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:
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if n+x==0: break
    ans=0
    for i in range(1,n+1):
        for j in range(i+1,n):
            k=x-i-j
            if i<j<k<=n and i+j+k==x: ans+=1
    print(ans)

Submission status: Accepted

Solution code:
n,x = [],[]
while True:
	a,b = map(int,input().split())
	if a == 0 and b == 0:
		break
	else:
		n.append(a)
		x.append(b)
for i in range(len(n)):
	counter = 0
	for k in range(n[i]):
		kk = k+1
		for s in range(n[i]-kk):
			ss = s + kk + 1
			for f in range(n[i]-ss):
				ff = f + ss + 1
				if kk + ss + ff == x[i]:
					counter +=1
	print(counter)

Submission status: Accepted

Solution code:
while True:
    n,x=(int(l) for l in input().split())
    if n==0 and x==0:
        break
    answer_count=0
    for a in range(1,n+1):
        for b in range(1,a):
            for c in range(1,b):
                if a+b+c==x:
                    answer_count+=1
    print(answer_count)

Submission status: Accepted

Solution code:
while True:
  n,x = map(int,input().split())
  if (n,x) ==(0,0):
    break
  c=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:
          c+=1
  print(c)