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:
# coding: utf-8

import itertools

data_set = []
answer = []

while (1):
    n,x = map(int, input().split())
    if (n == 0 and x == 0):
        break
    data_set.append([n,x])

for d in data_set:
    num = list(range(d[0] + 1))[1:]
    counter = 0
    for i in itertools.combinations(num, 3):
        if (sum(i) == d[1]):
            counter += 1
    answer.append(counter)
    
for ans in answer:
    print(ans)

Submission status: Accepted

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

    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:
from itertools import combinations

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

Submission status: Accepted

Solution code:
while True:
    n, x = [int(a) for a in input().split()]
    if n == x == 0:
        break
    cnt = 0
    for i in range(1, n):
        for j in range(i + 1, n):
            flag = False
            for k in range(j + 1, n + 1):
                if flag:
                    break
                if (i + j + k) == x:
                    cnt += 1
                    flag = True

    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
count = []

while True:
    sub_count = 0
    n,x = map(int,raw_input().split())
    if n == x == 0:
        break
    
    for i in range(n):
       for j in range(n):
           for k in range(n):
               if ((i + j + k + 3) == x) and ((i != j != k != i) == True):
                   sub_count += 1
    count.append((sub_count / 6))


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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
import sys

p = sys.stdin.readlines()
r = 0
for i in p:
	n,x = map(int,i.split())
	if n==0 and x==0:
		break
	else:
		for a in range(1,n+1):
			for b in range(1,n+1):
				if a==b:
					break
				else:
					for c in range(1,n+1):
						if a==c or b==c:
							break
						elif a+b+c==x:
							r+=1
	print r
	r = r*0

Submission status: Accepted

Solution code:
while True:
    try:
        n,x = map(int,input().split(" "))
        if n == 0 and x == 0:
            break
        pattern = 0
        for i in range(1,n+1):
            for j in range(i+1,n+1):
                for h in range(j+1,n+1):
                    if i + j + h == x:
                        pattern += 1
        print(pattern)
    except (EOFError):
        break

Submission status: Accepted

Solution code:
results = []
while True:

    n,x = map(int ,raw_input().split())
    
    if n is x is 0:
        break
    s = 0
    for i in xrange(1,n+1):
        for j in xrange(1,n+1):
            for k in xrange(1,n+1):
                if i+j+k == x:
                    if i != j and j != k and k != i :
                        s+=1
       
    results.append(s/6)

for i in results:
    print i

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

while True:
    n, x = map(int, raw_input().split())
    if n == 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
                    break
    print count

Submission status: Accepted

Solution code:
import itertools
while True:
    n, x = map(int, input().split())
    if n == 0 and x ==0:
        break
    comb = itertools.combinations(range(1, n+1), 3)
    sumn = list(sum(c) for c in comb)
    print(sumn.count(x))

Submission status: Accepted

Solution code:
import itertools
while True:
    count = 0
    n, x = map(int, raw_input().split())
    if n==0 and x==0:
        break
    #for i in xrange(1, n):
     #   for j in xrange(1, n):
      #      for k in xrange(1, n):
       #         if i!=j and  j!=k and k!=i and i+j+k==x:
    #print count
    ls = list(itertools.combinations(xrange(1, n+1), 3))
    #print ls
    l = len(ls)
    for i in xrange(l):
        if ls[i][0]+ls[i][1]+ls[i][2]==x:
            count+=1
    print count

#for x in itertools.combinations_with_replacement()

Submission status: Accepted

Solution code:
y = raw_input()
n, x = y.split()
n = int(n)
x = int(x)
co = 0

while n != 0 or x != 0:
    for i in range(1, n-1):
        for j in range(2, n):
            for k in range(3, n+1):
                sum = i + j + k
                if sum == x and i < j and j < k:
                    co += 1
                    break

    print co
    
    y = raw_input()
    n, x = y.split()
    n = int(n)
    x = int(x)
    co = 0

Submission status: Accepted

Solution code:
while True:
    n,x= map(int,raw_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 = count + 1
    print count

Submission status: Accepted

Solution code:
while True:
    n,x= map(int,raw_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 = count + 1
                     break
    print count

Submission status: Accepted

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

    if n == 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 = count + 1
                     break
    print count

Submission status: Accepted

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

    if n == 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):
                s = i + j + k
                if s == x:
                     count = count + 1
                     break
                elif s > x:
                     break
    print count

Submission status: Accepted

Solution code:
import itertools
a = []
while True:
    n = map(int, raw_input().split())
    if n == [0, 0]:
        break
    a.append(n)

for n in range(len(a)):
    x = 0
    b = []
    for m in range(a[n][0]):
        if m == range(a[n][0]): break
        b.append(m+1)

    c = list(itertools.combinations(b, 3))
    for l in range(len(c)):
        sum = c[l][0] + c[l][1] + c[l][2]
        if sum == a[n][1]: x += 1
    print x

Submission status: Accepted

Solution code:
import itertools
while 1:
    n,x=map(int,raw_input().split())
    if n==0 and x==0:
        break
    else:
        answer=0
        l=range(1,n+1)
        for ele in itertools.combinations(l,3):
            if sum(ele)==x:
                answer+=1
        print answer

Submission status: Accepted

Solution code:
while(True):
    n, x = map(int, input().split())
    if(n == x == 0): break
    ans = 0
    for x1 in range(1, n-1):
        for x2 in range(x1+1, n):
            for x3 in range(x2+1, n+1):
                if((x1 + x2 + x3) == x):
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while 1:

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

	count = 0
	for i in xrange(1, n-1):
		for j in xrange(i+1, n):
			for k in xrange(j+1, n+1):
				if i+j+k > x:
					break
				if i+j+k == x:
					count += 1
	print count

Submission status: Accepted

Solution code:


m = 0
while m == 0:
    n, x = map(int,raw_input().split())
    count = 0    
    if n == 0 and x == 0:
        break
    for i in xrange(1,n+1):
        for j in xrange(1,n+1):
            for k in xrange(1,n+1):
                ans = i + j + k
                if ans == x and i != j and j != k and k != i:
                    count = count + 1
    print count / 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:
#   1~n?????§?????????3????????°???????¶??????????????????°???x????????????????????°????±???????????????°??????
while 1:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    ansCount = 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 == x and i != j and i != k and j != k:
                    ansCount += 1
                    #   print("{0} {1} {2}".format(i, j, k))
    print("{0}".format(ansCount))

Submission status: Accepted

Solution code:
a, b = (int(i) for i in input().split())
while a != 0 or b != 0:
    count = 0
    for i in range(1, a-1):
        for j in range(i+1 , a):
            for k in range(i+2, a+1):
                if i + j + k == b and i < j < k:
                    count += 1
    print("{0}".format(count))
    a, b = (int(i) for i in input().split())

Submission status: Accepted

Solution code:
a, b = (int(i) for i in input().split())
#0??¨0?????\??????????????´????????????????????????
while a != 0 or b != 0:
    count = 0
    #i?????????????????°???
    for i in range(1, a-1):
        #j?????????????????°???
        for j in range(i+1 , a):
            #k?????????????????°???
            for k in range(i+2, a+1):
                #??????????????´???????????????????????????
                if i + j + k == b and i < j < k:
                    count += 1
    print("{0}".format(count))
    a, b = (int(i) for i in input().split())

Submission status: Accepted

Solution code:
# 12-Structured_Program_II-How_many_ways.py

# ????????????????????°
# 1 ?????? n ?????§?????°?????????????????????????????§???????????°?????????????????????????¨???? x ??¨??????
# ????????????????????°????±???????????????°?????????????????????????????????
# ????????°???1 ?????? 5 ?????§?????°???????????????????????§????????????????¨???? 9 ??¨???????????????????????????

# 1 + 3 + 5 = 9
# 2 + 3 + 4 = 9
# ??????????????????????????????

# Input
# ?????°??????????????????????????\?????¨???????????????????????????
# ???????????????????????§??????????????§??????????????? n???x ??? 1 ???????????????????????????

# n???x ?????¨?????? 0 ?????¨?????\?????????????????¨????????????
# n ??? 3 ??\??? 100?????\?????¨????????????

# Output
# ????????????????????????????????????????????????????????°????????????????????????????????????

# Sample Input
# 5 9
# 0 0
# Sample Output
# 2

result = []
n=[]
x=[]

while 1:
	temp = input().split() 
	if temp[0]=="0" and temp[1]=="0":
		break;
	else:
		n.append( int( temp[0] ))
		x.append( int( temp[1] ))

for i in range( len(n) ):
	count =0
	for n1 in range(1,n[i]+1-2):
		for n2 in range(n1+1, n[i]+1-1):
			for n3 in range(n2+1, n[i]+1):
				sum = n1+n2+n3
				if sum == x[i]:
					count+=1
	result.append(count)

for i in range( len(result) ):
	print(result[i])
	# if i == len(result)-1:
	# 	print(result[i])
	# else:
	# 	print("{0} ".format(result[i]), end="")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
import itertools
while True:
    n,x = [int(x) for x in input().split()]
    if (n,x)==(0,0): break
    cnt=0
    for comb in itertools.combinations(range(1,n+1),3):
        if sum(comb) == x: cnt+=1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n,x = [int(x) for x in input().split()]
    if (n,x)==(0,0): break
    cnt=0
    if 3*(n-1) >= x:     # If n-2 + n-1 + n < x, there is no combination
        a_max = x//3 - 1 # a_max + a_max+1 + a_max+2 = x
        if 2*n-1 < x: 
            a_min = x - (2*n-1) # set minimum value of a
        else:
            a_min = 1
        for a in range(a_min,a_max+1):
            b_max = (x-a-1)//2 # b_max + b_max+1 <= x-a
            b_min = (x-a) - n  # set minimum value of b
            b_min = b_min if b_min > a+1 else a+1
            cnt += b_max - b_min + 1
    print(cnt)

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:
while True:
	k=map(int,raw_input().split(" "))
	if k[0]==k[1]==0:
		break
	ct=0
	a=0
	b=0
	c=0	
	max=k[0]
	sum=k[1]
	a=max+1
	
	while True:
		a-=1
		b=a-1
		c=sum-a-b
		if not a>b>c:
			print ct
			break
		while a>b>c:
			if a>b>c>0:
				ct+=1
			b-=1
			c+=1

Submission status: Accepted

Solution code:
while True:
	k=map(int,raw_input().split(" "))
	if k[0]==k[1]==0:
		break
	ct=0
	a=0
	b=0
	c=0	
	max=k[0]
	sum=k[1]
	a=max+1
	while True:
		a-=1
		b=a-1
		c=sum-a-b
		if not a>c:
			print ct
			break
		while b>c:
			if c>0:
				ct+=1
			b-=1
			c+=1

Submission status: Accepted

Solution code:
while True:
	k=map(int,raw_input().split(" "))
	if k[0]==k[1]==0:
		break
	ct=0
	max=k[0]
	sum=k[1]
	a=max+1

	while True:
		a-=1
		b=a-1
		c=sum-a-b
		if not a>c:
			print ct
			break
		while b>c:
			if c>0:
				ct+=1
			b-=1
			c+=1

Submission status: Accepted

Solution code:
while True:
    data = input().split()
    n = int(data[0])
    x = int(data[1])
    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 and j != k and i != k:
                    c = i + j + k
                    if c == x:
                        count += 1
    print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
while True:
    count=0
    n,x = [int(a)for a in input().split(' ')]
    if n+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:
while True:
	n,x = list(map(int,input().split()))
	if n == 0 and x == 0:
		break

	count = 0
	for a in range(1,x//3):
		for b in range(a+1,x//2):
			c = x - (a + b)
			if b < c <= n:
				count += 1
	print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

while(True):
    i=0
    a=list(map(int,input().split()))
    if(a[0]==0 and a[1]==0):
        break
    for x in range(2,a[0]):
        sum=a[1]-x
        for y in range(1,x):
            if (sum-y<a[0]+1 and sum-y>x):
                i+=1
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:

    n, x = map(int, input().split())
    if n == x == 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 + j + k + 3 == x):
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
import itertools

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

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

	count = 0
	num_sequence = [i + 1 for i in range(n)] # [1, 2, 3, 4, 5]
	for guess in itertools.combinations(num_sequence, 3):
		sum = 0
		for i in guess:
			sum += i
		if (sum == x):
			# (1, 3, 5)
			# (2, 3, 4)
			count += 1

	print(count)

Submission status: Accepted

Solution code:
def solve(n,x):
    count = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            if i == j :
                continue
            for k in range(1,n+1):
                if j == k or i == k:
                    continue
                if i+j+k == x:
                    count += 1
    return count//6

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

Submission status: Accepted

Solution code:
def solve(n,x):
    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
    return count

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    print(c)

Submission status: Accepted

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

    cnt = 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:
                    cnt += 1
    list.append(cnt)

for s in list:
    print(s)

Submission status: Accepted

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

    if n == x == 0:
        break

    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)

Submission status: Accepted

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

    if n == x == 0:
        break

    count = 0
    for s in range(1, n + 1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = [int(i) for i in input().split()]
    
    if n == x == 0:
        break
        
    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == sum([s, m, e]):
                    count += 1
                    
    print(count)

Submission status: Accepted

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


    if n == x == 0:
        break

    count = 0
    for s in range(1, n - 1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)

Submission status: Accepted

Solution code:
while True:
    n,x = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for s in range(1, n-1):
        for m in range(s+1, n):
            for e in range(m+1,n+1):
                if x == sum([s,m,e]):
                    count += 1

    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = [int(i) for i in input().split()]
     
    if n == x == 0:
        break
         
    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == sum([s, m, e]):
                    count += 1
                     
    print(count)

Submission status: Accepted

Solution code:
while True:

    n,x = [int(r) for r in input().split()]

    if n == x ==0:
      break

    count =0
    for s in range(1,n-1):
        for m in range(s+1,n):
            for e in range(m+1,n+1):
                if x ==sum([s,m,e]):
                    count+= 1

    print(count)

Submission status: Accepted

Solution code:
while True:
    n,x = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for s in range(1, n-1):
        for m in range(s+1, n):
            for e in range(m+1,n+1):
                if x == sum([s,m,e]):
                    count += 1
 
    print(count)

Submission status: Accepted

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

    if n == x == 0:
        break

    count = 0
    for s in range(1, n+1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)

Submission status: Accepted

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

    if n == x == 0:
        break

    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == s + m + e:
                    count += 1

    print(count)

Submission status: Accepted

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

    if n == x == 0:
        break

    count = 0
    for s in range(1, n + 1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == s + m + e:
                    count += 1

    print(count)

Submission status: Accepted

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

    if n == x == 0:
        break

    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == s+m+e:
                    count += 1

    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = [int(i) for i in input().split()]
 
    if n == x == 0:
        break
 
    count = 0
    for s in range(1, n + 1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == s + m + e:
                    count += 1
 
    print(count)

Submission status: Accepted

Solution code:
date=[]
while True:
    x, y= [int(i) for i in input().split()]
    count=0
    if x == 0 and y ==0:
        break
    else:
        for k in range(1,x-1):
            for h in range(k+1,x):
                for g in range(h+1,x+1):
                    if k + h + g == y:
                        count = count + 1
    date.append(count)

for u in range(0,len(date)):
    print(date[u])

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
    array = set(range(1, n+1))
    for ele in combinations(array, 3):
        if sum(ele) == x:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n,x = [int(i) for i in input().split()]
    if n == 0 and x == 0: break
    count = 0
    # 3????????°?????????????°????x//3?????????x//3 * 3 == x ?????????????°????x//3??\?????§?????????????????????
    for a in range(1, x//3):
        # 3????????°?????????????????????x//2?????????x//2 * 2 == x ?????????????????????x//2??\?????§?????????????????????
        for b in range(a+1,x//2):
            c = x - (a + b)
            if b < c <= n:
                count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n,x=[int(x) for x in input().split()]
    if [n,x]==[0,0]:
        break
    count=0
    if 3*(n-1)>=x:
        a_max=x//3-1
        if 2*n-1<x:
            a_min=x-(2*n-1)
        else:
            a_min=1
        for a in range(a_min,a_max+1):
            b_max=(x-a-1)//2
            b_min=(x-a)-n
            b_min=b_min if b_min>a+1 else a+1
            count+=b_max-b_min+1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
NX = input().split()
n = int(NX[0])
x = int(NX[1])

while n!=0 or x!=0:
    out = 0
    for ii in range(n-2):
        i = ii+1 #i:1~n-2
        for jj in range(n-1-i):
            j = jj+1+i #j:i+1~i+1+n-2-i=i+1~n-1
            for kk in range(n-j):
                k = kk+1+j #k:j+1~n-j+j+1 =
                if k !=i and k!=j and i+j+k == x:
                    out = out+1
    print(out)
    NX = input().split()
    n = int(NX[0])
    x = int(NX[1])

Submission status: Accepted

Solution code:
def func(x, y):
    temp = 0
    for i in range(y-1, x/2, -1):
        if x-i > 0:
            temp += 1
    return temp

while(1):
    ans = 0
    n, x = map(int, raw_input().split())
    if n == 0 and x == 0:
        break
    else:
        for i in range(n, 0, -1):
            if x-i < 3:
                ans = 0
            else:
                ans += func(x-i, i)
    print ans

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import itertools

while True:
 n, x = map(int, raw_input().split())
 if n==0 and x==0: break
 count = 0
 for a, b, c in itertools.combinations(range(1, n+1), 3):
  if a+b+c==x:
   count += 1
 print count

Submission status: Accepted

Solution code:
# ????????????????????°????±???????????????°??????
import sys
import itertools

def main():
    while True:
        data = sys.stdin.readline().strip().split(' ')
        n = int(data[0])
        x = int(data[1])
        
        if n == 0 and x == 0:
            break

        cnt = 0
        for i in itertools.combinations(range(1, n+1), 3):
            if sum(i) == x:
                cnt += 1

        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

a = []
while True:
    d = list(map(int,input().split()))
    if d == [0,0]:
        break
    a.append(d)

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

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B "How many ways?" ????§£??????
# 
import itertools
while True:
    n, x = map(int, input().split())
    if not n:
        break
    print(list(map(sum, itertools.combinations(range(1, n + 1), 3))).count(x))

Submission status: Accepted

Solution code:
while 1:
    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 1:
 n, x = map(int, input().split())
 counter = 0
 if n == 0 and x == 0:
  break
 # y + (y-1) + (y-2) = x 
 y = (x+3) // 3
 for a in range(y, n+1):
  for b in range(2, a):
   if (x-a-b) > 0 and (x-a-b) < b:
    counter += 1
 print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    ins = list(map(int, input().split()))
    ls = range(1,ins[0]+1)
    
    if ins[0] == 0 and ins[1] == 0:
        break
        
    else:
        counter = 0
        for i in range(ins[0]-2):
            if ls[i]+ls[i+1]+ls[i+2] <= ins[1]:
                      for j in range(i+1, ins[0]-1):
                        for k in range(j+1, ins[0]):
                            if ls[i] + ls[j] + ls[k] == ins[1]:
                                counter += 1
    print(counter)