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 True:
    n, x = map(int, input().split())
    count = 0
    if n == 0 and x == 0:
        break
    else:
        for i in range(1, n):
            a = i
            for j in range(2, n+1):
                b = j
                c = x - (a+b)
                if a<b and b<c and c<=n:
                    count += 1
                else:
                    continue
        print(count)

Submission status: Accepted

Solution code:
A =[]
while True:
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    else:
        a = 0
        for i in range(1,n+1):
            if (i * 3 + 2)  > x:
                A.append(a)
                break
            else:
                for j in range(i+1,((x-i)//2) + 1):
                    c = x - (i + j)
                    if j < c <= n:
                        a += 1
                        
for i in A:
    print(i)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if (n,x)==(0,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 in_data(ts):
    while True:
        t = tuple(map(int, input().split(' ')))
        if t[0] == 0 and t[1] == 0:
            break
        ts.append(t)


def out_data(ts):
    for t in ts:
        cnt = 0
        for i in range(1, t[0] + 1):
            for j in range(i + 1, t[0] + 1):
                for k in range(j + 1, t[0] + 1):
                    if k == i or k == j:
                        continue
                    if i + j + k == t[1]:
                        cnt += 1
        print(cnt)


ts = []
in_data(ts)
out_data(ts)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    sum = 0
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                #print("i:",i+1,"j:",j+1,"k:",k+1)
                if i+j+k+3==x:
                    sum+=1

    print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8

while True:
    n, x = map(int, input().split())
    pattern = list()
    if n + x == 0:
        break
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i == j:
                continue
            k = x - i - j
            if k == i or k == j:
                continue
            if k < 1 or n < k:
                continue
            temp = sorted([i, j, k])
            if temp not in pattern:
                pattern.append(temp)
    #print(pattern)
    print(len(pattern))

Submission status: Accepted

Solution code:
def test():

	while True:

		count = 0
		inputs = list(map(int,input().split()))

		n = inputs[0]
		x = inputs[1]

		if n == 0 and 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 and j != k and k != i:
						if i + j + k == x:
							count += 1
		print(f"{count}")

if __name__ == "__main__":
	test()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 12 00:18:59 2019

@author: Atsushi
"""

while True:
    n, x = map(int,input().split())
    if n == x == 0:
        break
    count = 0
    #1 ~ n まで
    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 1:
    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)

    count = 0

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
cnt = 0
while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        break
    else:
        for i in range(1,a+1):
            for j in range(1,a+1):
                if i >= j:
                    continue
                for k in range(1,a+1):
                    if i>=k or j >=k:
                        continue
                    elif i+j+k==b:
                        cnt += 1

    print(cnt)
    cnt =0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nlist = []
xlist = []

while(1):
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    nlist.append(n)
    xlist.append(x)

for n, x in zip(nlist, xlist):
    cnt = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            k = x - i - j
            if j < k <= 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
 
  ans = 0
 
  for i in range(1,n+1):
    for j in range(i+1,n+1):
      k = x-(i+j)
      if k >= 1 and k <= n and k > j:
        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+1):
        for k in range(j+1,n+1):
          if i+j+k==x:ans+=1
    print(ans)

Submission status: Accepted

Solution code:
import sys,os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations
sys.setrecursionlimit(10**6)

while 1:
    n,x=map(int,input().split())
    cnt=0
    if (n,x)==(0,0):
        break
    a=list(range(1,n+1))
    b=list(combinations(a,3))
    for i in b:
        if sum(i)==x:
            cnt+=1
    print(cnt)

Submission status: Accepted

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

for a in ans:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list_way = []
ls = []
while True:
    n, x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break
    list_way.append([n, x])
for count in range(len(list_way)):
    r = 0
    list_n = [i + 1 for i in range(list_way[count][0])]
    for count0 in range(len(list_n)):
        num = list_n[0]
        list_n.remove(num)
        # print(list_n)
        for count1 in range(len(list_n)):
            for count2 in range(len(list_n) - count1 - 1):
                if list_n[count1] + list_n[count1 + count2 + 1] == list_way[count][1] - num:
                    r = r + 1
                    # print(r)
    ls.append(r)
for count in range(len(ls)):
    print(ls[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 + 1):
            k = x - (i + j)
            if j < k and k <= n:
                count += 1
    print(count)

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

Submission status: Accepted

Solution code:
a=[]
w=""
while(w!="0 0"):
    w=input()
    a.append(w)
a.pop()
for st in a:
    s=st.split()
    n=int(s[0])
    x=int(s[1])
    count=0
    for a in range(1,x//3+1):
        for b in range(a+1,(x-a)//2+1):
            if (x-a-b)<=n and b<(x-a-b):
                count+=1
    print("{0}".format(count))

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

  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
	p=0
	x,y=map(int,input().split())
	if x==0 and y==0:
		break
	for z in range(1,x):
		for a in range(z+1,x+1):
			for b in range(a+1,x+1):
				if z+a+b==y:
					p+=1
	print(p)

Submission status: Accepted

Solution code:
def main():
    ans = []
    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
        ans.append(c)
    for a in ans:
        print(a)


main()

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(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
  a=[s for s in itertools.combinations(range(1,n+1),3) if sum(s)==x]
  print(len(list(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:
num=0
k=0
while True:
    n,x=map(int,input().split())
    d = x-n
    if (n,x)==(0,0):
        break
    num=0
    if 3*(n-1)>=x:
        for i in range(3,n+1):
            for j in range(2,i):
                k=x-(i+j)
                if 0<k<j:
                    num+=1
    print(num)

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

            if not (j < k <= n):
                continue

            count += 1

    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
  n, x = map(int,input().split())
  c = 0
  if n == x == 0:
    break
  for r in range(1, n-1):
    for s in range(r+1, n):
      for t in range(s+1, n+1):
        if r+s+t == x:
          c += 1
  print(c)

Submission status: Accepted

Solution code:
while True:
  n, x = map(int,input().split())
  c = 0
  if n == x == 0:
    break 
  for r in range(1, n-1):
    for s in range(r+1, n):
      for t in range(s+1, n+1):
        if r+s+t == x:
          c += 1
  print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def get_combination_num(n: int, x: int) -> int:
    total_num: int = 0
    for a in [elem for elem in range(1, n + 1)]:
        if x < a:
            break
        for b in [elem for elem in range(1, a)]:
            if x < a + b:
                break
            for c in [elem for elem in range(1, b)]:
                if x < a + b + c:
                    break
                elif x == a + b + c:
                    total_num += 1

    return total_num


if __name__ == "__main__":
    while(True):
        n, x = map(lambda x: int(x), input().split())

        if (n == x == 0):
            break

        print(f"{get_combination_num(n, x)}")

Submission status: Accepted

Solution code:
while True:
    try:
        n,x = map(int,input().split())
        if n == x == 0:
            break
        else:
            ans = []
            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:
                            if i != j and i != k and j != k:
                                ans.append([i,j,k])
                            
            print(int(len(ans) / 6))
            
    except:
        break

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

Submission status: Accepted

Solution code:
while True:
  n, x = list(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):
      rem = x - i - j
      if j < rem <= n:
        ans += 1
  print(ans)

Submission status: Accepted

Solution code:
k=0
ans=0
while k==0:
 ans=0
 x,y=map(int,input().split())
 if x==0 and y==0:
  break
 else:
  for a in range(x):
   for b in range(x):
    for c in range(x):
     if a+b+c==y-3 and a!=b and b!=c and c!=a:
      ans+=1
  print(ans//6)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
c = 0
while c == 0:
    ans = 0
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        c = 1
    else:
        li = []
        for i in range(n):
            li.append(i+1)
        for a in range(1,n):
            for b in range(1,n):
                d = x - a - b
                if a != b and b != d and d != a and d <= n and a < b < d and d in li:
                    ans += 1
        print(ans)

Submission status: Accepted

Solution code:
import itertools

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

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

    for i in itertools.combinations(range(1, n+1), 3):
        if sum(i) == 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(n):

        for j in range(i):

            for k in range(j):

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

Submission status: Accepted

Solution code:
# 1 から n までの数の中から、重複無しで３つの数を選び
# それらの合計が x となる組み合わせの数を求める
while True:
    n, x = input().split()
    if n == x == "0":
        break
    n = int(n)
    x = int(x)
    num = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                # print("%d + %d + %d" %(i, j, k))
                if i + j + k == x:
                    num += 1
                    break
    print(num)

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
    cnt = 0
    for num1 in range(1, n+1):
        for num2 in range(num1+1, n+1):
            if num1 + num2 >= x:
                continue
            for num3 in range(num2+1, n+1):
                if num1 + num2 + num3 == x:
                    cnt += 1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
while True:
    n, x = map(int, input().split())
    if n == 0: break
    a = [s for s in itertools.combinations(range(1,n+1), 3) if sum(s) == x]
    print(len(list(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):
      if(j < x-i-j < n+1):
        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):
            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
  else:
    l = []
    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 i !=k :
            l.append([f'{i},{j},{k}'])
  print(int(len(l) / 6))

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

Submission status: Accepted

Solution code:
from itertools import product

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

    for a, b, c in product(range(1, n + 1), range(1, n + 1), range(1, n + 1)):
        co += a + b + c == x and a != b != c != a
    print(co // 6)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
'import math'
while(1):
    n,m=input().split()
    if n=='0' and m=='0':
        sys.exit()
    n=int(n)+1
    m=int(m)
    cnt=0
    for a in range(1,n):
        for b in range(a+1,n):
            for c in range (b+1,n):
                if a+b+c==m:
                    cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
while True:
    a = input()
    b = a.split()
    m = int(b[0])
    f = int(b[1])
    if m == 0 and f == 0 :
        break
    else:
        list1 = []
        num = 0
        for i in range(m):
            x=(int(i)+1)
            sum2=f-x
            list1.append(int(i)+1)
            for k in range(x,(m+1)):
                y = k
                z = f-x-y
                if z in list1 and z != x and z !=y and x != y:
                    num += 1
    print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    input_line = input()
    n, x = [int(s) for s in input_line.split(' ') if s]
    if n == 0 and x == 0:break
    ret = 0
    for i in range(1,n-1):
        for j in range(i+1,n+1):
            if x-i-j > n or x-i-j <= j: 
                # print(i,j)
                continue
            else: 
                ret += 1
                # print(i,j,x-i-j)

    print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if (n, x) == (0, 0): break
    ans = []
    for i in range(n, 1, -1):
        for j in range(1,n):
            tmp = x-(i+j)
            if tmp > n: continue
            if tmp > 0 and i > 0 and j > 0:
                if tmp != j and tmp != i and i != j:
                    pmt = sorted([i, j, tmp])
                    if not pmt in ans: ans.append(pmt)
    print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n_list=[]
x_list=[]
while True:
  n, x = map(int, input().split())
  if n == 0 and x == 0:
    break
  n_list.append(n)
  x_list.append(x)


for (nlist, xlist) in zip(n_list, x_list):
  a = 0
  for i in range(1, nlist+1):
    for j in range(i+1, nlist+1):
      for k in range(j+1, nlist+1):
        if i == j or j == k or i == k:
          continue
        if i + j + k == xlist:
          a = a + 1
  print(a)

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

    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+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:
    L=input().split( )
    n=int(L[0])
    x=int(L[1])
    if n==0 and x==0:
        break
    i=0
    for c in range(n+1):
        for b in range(c):
            if x-c-b<b and x-c-b>0:
                i+=1
    print(i)