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:
for _ in range(10000):
	n,x = map(int,input().split())
	
	if (n+x == 0):
		break
	
	input_list = list(range(1,n+1))
	
	res = 0
	
	for i in range(len(input_list)):
		for j in range(i+1,len(input_list)):
			for k in range(j+1,len(input_list)):
				if input_list[i]+input_list[j]+input_list[k] == x:
					res += 1
				
			if j + 2 == len(input_list):
				break
		
		if i + 3 == len(input_list):
			break
		
	print(str(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while (True):
    count = 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):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
#初期値の準備
data_count = 0
input_data = list()

#インプットdataから初期値の挿入
while data_count >= 0:
    input_data.append(list(map(int, input().split())))
    if input_data[data_count][0] == 0 and input_data[data_count][1] == 0:
        break
    data_count += 1

#結果判定
result = [0] * data_count
for h in range(data_count):
    max_number = input_data[h][0]
    judg_number = input_data[h][1]
    for i in range(max_number):
        for j in range(i+1, max_number):
            for k in range(j+1, max_number):
                if i+1+j+1+k+1 == judg_number:
                    result[h] += 1
                    break
                elif i+1+j+1+k+1 > judg_number:
                    break
                else:
                    continue

#結果表示
[print(i) for i in result]

Submission status: Accepted

Solution code:
while True:
 n,x = list(map(int, input().split() ))
 if n==0 and x==0:
  break
 nways = 0
 for i1 in range(1,n+1):
  if i1*3+3>x:
   break
  for i2 in range(i1+1,n+1):
   if i1+i2+i2+1>x:
     break
   for i3 in range(i2+1,n+1):
    if i1+i2+i3 == x:
     nways = nways + 1
     break
    elif i1+i2+i3>x:
     break
 print(nways)

Submission status: Accepted

Solution code:
while True:
    count = 0
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        exit()
    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:
a=0
num=[]
list_ans=[]
num.append([int(w) for w in input().split()])
while not num[a]==[0,0]:
    num.append([int(w) for w in input().split()])
    ran=[int(w) for w in range(num[a][0]+1)]
    ans=0
    
    for w in range(num[a][0]-2):
        
        for i in range(num[a][0]-2-w):
            
            for n in range(num[a][0]-2-i-w): 
                
                if ran[w+1]+ran[i+2+w]+ran[n+3+i+w]==num[a][1]:
                    ans+=1
    list_ans.append(ans)                
    a+=1
for i in list_ans:
    print(i)

Submission status: Accepted

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

    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(f"i:{i},j:{j},k:{k}")
    
    print(ans)

Submission status: Accepted

Solution code:
while True:
    a,b= map(int,input().split())
    if a==0 and b == 0:
        break
    a_rng=list(range(a,0,-1))
    l=0
    li=[]
    for i in a_rng:
        for j in a_rng:
            for k in a_rng:
                if i+j+k ==b and (i!=j and i!=k and j!=k):
                    dd = sorted([i,j,k])
                    if dd not in li:
                        li.append(dd)
                        l+=1
    print(l)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
def solve(n,x):
	ans = 0
	for i in range(1,n-1):
		for j in range(i+1, n):
			k = x-i-j
			if k>j and k<=n:
				ans += 1
	return ans

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

Submission status: Accepted

Solution code:
#7_B
import math

def findlimit(n, x, v):
    a = n - (v-1)
    b = math.floor(x/v)
    if a>=b:
        return b
    else:
        return a

while 1:
    n, x = map(int, input().split())
    l_a = findlimit(n,x,3)
    count = 0
    if n==0 and x==0:
        break
    if x<6:
        res = 0
    else:
        for a in range(l_a):
            a = a + 1
            y = x - a
            l_b = findlimit(n,y,2)
            b_ini = a + 1
            
            for b in range(l_b-b_ini+1):
                b = b + b_ini
                z = y - b
                if b<z<=n:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    # データを受け取る
    n, x = map(int, input().split())
    if n==x==0:
        break

    num = 0

    for i in range(1, n + 1):
        for j in range(1, n + 1):
            for k in range(1, n + 1):
                result = i + j + k
                if i >= j or i >= k or j >= k:
                    pass
                elif result == x:
                    num += 1
                else:
                    pass
    print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools


while True:
    n, x = [int(i) for i in input().split()]
    if n == x == 0:
        break
    ans = 0
    for a, b in itertools.combinations(range(1, n + 1), 2):
        c = x - (a + b)
        if b < c <= n:
            ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
while True:
    n,x=map(int,raw_input().split())
    if n==0 and x==0:
        break
    a=[]
    c=0
    for i in range(n):
        a.append(i+1)
    for i in itertools.combinations(a,3):
        if sum(i)==x:
            c+=1
    print c

Submission status: Accepted

Solution code:
def how_many_ways(n, x):

    count = 0
   
    for i in range(1, n + 1):
        s = x
        s = s - i
        for j in range( 1, n + 1):
                s = s - j
                for k in range( 1 , n + 1 ):
                    s = s - k
                    if s == 0:
                        count += 1

def how_many_ways2(n, x):

    count = 0

    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                if i < j < k and i + j + k == x:
                    count += 1

    print(count)
                        

if __name__ == "__main__":
    
    while(True):

        param = input().split(" ")
        n = int(param[0])
        x = int(param[1])

        if n == 0 and x == 0:
            break
        else:
            how_many_ways2(n, x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def combination(array, comb_size):
  if comb_size == 0: return []
  if len(array) < comb_size: return []
  if len(array) == comb_size: return [array]
  if comb_size == 1: return map(lambda x: [x], array)
  ret = []
  for i in range(0, len(array) + 1 - comb_size):
    picked = array[i]
    rest = array[i + 1:]
    for c in combination(rest, comb_size - 1):
      ret.append([picked] + c)
  return ret

while True:
  n, x = map(int, input().split())
  if n == x == 0: break
  comb = combination([i for i in range(1, n + 1)], 3)
  print(str([sum(i) for i in comb].count(x)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    #n,xの入力
    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):
            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 and n == 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 = count+1
                    break

    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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):
            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):
        exit()
    count = 0
    for a in range(1,n+1):
        for b in range(1,n+1):
            for c in range(1,n+1):
                if(a+b+c>x):
                    break
                if(a+b+c==x and a<b<c):
                    count = count + 1
    print(count)

Submission status: Accepted

Solution code:
while 1:
    n,x = map(int,input().split())
    if n == 0:break
    d = 0
    for a in range(1,x//3):
        for c in range(n,(x-a)//2,-1):
            b = x - a - c
            if a < b < c :d += 1
    print(d)

Submission status: Accepted

Solution code:
import itertools
while True:
    n, s = map(int, input().split())
    if n == s == 0:
        break
    l = list(itertools.combinations(range(1,n+1),3))
    result = 0
    for _ in l:
        if sum(list(_)) == s:
            result += 1
    print(result)

Submission status: Accepted

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

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
    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+=1
    print(ans)

Submission status: Accepted

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

    else:
        list1 = list()
        for i in range(1, n - 1):
            for j in range(i + 1, n):
                for k in range(j + 1, n + 1):
                    list1.append(i + j + k)
    print(list1.count(x))

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    combi = 0
    for a in range (1, n-1):
        for b in range (a+1, n): # c>b>a
            c = x - a - b # x = a+b+c
            if c <= b:
                break
            elif c > n:
                continue
            else:
                combi += 1
    print(combi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
D = map(int, open(0).read().split()[:-2])
for n, x in zip(*[iter(D)]*2):
    ans = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if j >= x - i - j:
                break
            if x - i - j not in (i, j) and x - i - j <= n:
                ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def divide_two(c, z):
    min_b = z // 2 + 1
    max_b = min(c-1, z-1)
    return max(max_b-min_b+1, 0)
    

num_set = []
cnt = 0
while True:
    n, x = map(int, input().split())
    if (n, x) == (0, 0):
        break
    else:
        num_set.append((n, x))
        cnt += 1

for i in range(cnt):
    num_count = 0
    (n, x) = num_set[i]
    for c in range(x//3, n+1):
        num_count += divide_two(c, x-c)
    print(num_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n, x = map(int, input().split())
    while (n, x) != (0, 0):
        ans = 0
        for b in range(1, n + 1):
            for a in range(max(1, x - b - n), b):
                c = x - b - a
                if c <= b: break
                #if c > n: continue
                # print(a,b,c)
                ans += 1
        print(ans)
        n, x = map(int, input().split())

main()

Submission status: Accepted

Solution code:
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



while True:
    N,X = map(int,input().split())
    if N == 0 and X == 0:
        break
    ans = 0
    for a in range(1,N+1):
        for b in range(1,N+1):
            if b <= a:
                continue
            c = X-(a+b)
            if c > b and c <= N:
                ans += 1
    print("%d"%(ans))

Submission status: Accepted

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

    cnt = 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:
                cnt += 1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    lst = list(map(int, input().split()))
    n, x = lst[0], lst[1]
    count = 0

    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:
                    count = count +1
                    break
            if i+j >= x:
                break
        
        if i >=x:
            break

    print(count)

Submission status: Accepted

Solution code:
result = []

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):
            for k in range(j+1, n+1):
                if x == i + j + k:
                    res += 1

    result.append(res)

for result in result:
    print(result)

Submission status: Accepted

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

    print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    count = 0
    for i in range(1, x//3+1):
        for j in range(i+1, x//2+1):
            if x-i-j <= n and x-i-j > j:
                count += 1
                # print('{} {}', i, j, x-i-j)
    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    cnt = 0
    for a in range(1, n-1):
        for b in range(a+1, n):
            c = x - a - b
            if b < c <= n:
                #print(f"{a}, {b}, {c}")
                cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
while n != 0:
    cnt = 0
    i = 1
    while i < n - 1:
        j = i + 1
        while j < n:
            k = j + 1
            while k <= n:
                if (i + j + k == x):
                    cnt += 1
                k += 1
            j += 1
        i += 1
            
    print(cnt)
    n, x = map(int, input().split())

Submission status: Accepted

Solution code:
n,x=[int(k) for k in input().split()]
count=0
while n or x:
    for i1 in range(1,x//3+1):
        if i1 > n:
            break
        for i2 in range(i1+1,(x-i1)//2+1):
            if i2>n:
                break
            i3=(x-i1-i2)
            if i2<i3 and i3<=n:
                count+=1
    n,x=[int(k) for k in input().split()]
    print(count)
    count=0

Submission status: Accepted

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

    if 3*(n -1) < x or x < 6:
        print(0)
        continue
    
    way = 0
    for i in range(1, x//3):
        p = x -i
        for j in range(n, p//2, -1):
            if i < p - j < j:
                way += 1
    print(way)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = 0
z = list()
while True:
    n,x = map(int,input().split())
    if n==x==0:
        break
    else:
        for i in range(1,n+1):
            for j in range(1,n+1):
                for k in range(1,n+1):
                    if i < j and i < k:
                        if j < k:
                            b = i+j+k
                            if b == x:
                                a += 1
                            else:
                                pass
                        else:
                            pass
                    else:
                        pass
        z.append(a)
        a = 0

for i in z:
    print(i)

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):
            for l in range(j+1,n+1):
                if i + j + l == x:
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
n, x = map(int,input().split())
while (not((n==0)and(x==0))):
    c = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            r = x - (i+j)
            if ((r>=j+1)and(r<=n)):
                c+=1
            #print(r, c)
    print(c)
    n, x = map(int,input().split())

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,1+N):
        for h in range(1+i,1+N):
            for j in range(1+h,1+N):
                if X == i+h+j:ans += 1
    print(ans)

Submission status: Accepted

Solution code:
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(2, n):
            for k in range(3, n+1):
                if i < j < k and i + j + k ==x:
                    count += 1
    print(count)

Submission status: Accepted

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


def solve(n, x):
    if x < 6:
        return 0
    M = n - 3
    S = x - 6
    dp = [[0 for i in range(S + 1)] for j in range(4)]
    dp[0][0] = 1
    for i in range(1, 4):
        for j in range(S + 1):
            if j - i < 0:
                dp[i][j] = dp[i - 1][j]
            else:
                dp[i][j] = dp[i - 1][j] + dp[i][j - i]
                if j - i - M >= 0:
                    dp[i][j] -= dp[i - 1][j - i - M]
    ret = dp[3][S]
    return ret


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
    n ,x=map(int, 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):
                judge=i+j+k
                if judge==x:
                    count=count+1
    print(count)

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):
            for k in range(j+1, n+1):
                if x == i+j+k:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = list(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):
            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())
    ans = 0
    if n == 0 and 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:
                    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 a in range(1,n-1):
        for b in range(a+1,n):
            if b<x-a-b<=n:
                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
    ans_list=[]

    for i in range(1,n+1):
        for j in range(1,n+1):
            k=x-i-j
            if i==j or j==k or k==i:
                pass
            elif k<=0:
                pass
            elif k>n:
                pass
            elif i+j==x-k:
                count+=1
                ans_list.append([i,j,k])
            else:
                pass
    
    for item in ans_list:
        item.sort()
    ans_list.sort()
    
    dup=0
    for i in range(len(ans_list)):
        if i==0:
            pass
        elif ans_list[i]==ans_list[i-1]:
            dup+=1
    
    ans=len(ans_list)-dup
    print(ans)

Submission status: Accepted

Solution code:
while True:
    combination_count = 0
    answer_set = set()
    item, target = map(int, input().split())
    
    if item == 0 and target == 0:
        break
    
    for i in range(1, item+1):
        for j in range(i+1, item+1):
            for k in range(j+1, item+1):
                if i + j + k == target and (i, j, k) not in answer_set:
                    combination_count += 1
                    answer_set.add((i, j, k))
    print(combination_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nums = []
flag = True
while flag:
    nums.append(list(map(int, input().split())))
    if nums[-1][0] == nums[-1][1] == 0:
        flag = False
nums.pop()
for num in nums:
    x_set = set()
    for a in range(1, num[0]+1):
        for b in range(1, num[0]+1):
            for c in range(1, num[0]+1):
                if a + b + c == num[1] and a != b and b != c and c != a:
                    x_set.add((a, b, c))
    print(int(len(x_set)/6))

Submission status: Accepted

Solution code:
n=10
x=10
count=0
n,x=map(int,input().split())
while True:
    if n==0 and x==0:
        break
    else:
        for p in range(1,n+1):
            for q in range(p+1,n+1):
                r=x-p-q
                if q<r<=n:
                    count+=1
    print(count)
    count=0
    n,x=map(int,input().split())

Submission status: Accepted

Solution code:
import sys
while True:
    res = 0
    n, x = [int(i) for i in input().split()]
    if n == 0 and x == 0:
        sys.exit()
    else:
        for i in range(1, n+1):
            for j in range(1, n+1):
                if j == i:
                    break
                for k in range(1, n+1):
                    if k == j:
                        break
                    if i != j and j != k and k != i and i + j + k == x:
                        res += 1
    print(res)

Submission status: Accepted

Solution code:
from itertools import combinations

n, x = [int(i) for i in input().split()]
while n or x:
    ans = 0
    for a in combinations(range(1, n + 1), 3):
        if sum(a) == x:
            ans += 1
    print(ans)
    n, x = [int(i) for i in input().split()]

Submission status: Accepted

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


    print(cnt)