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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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(1, n + 1):
            if i == j:
                continue
            for k in range(1, n + 1):
                if j == k or k == i:
                    continue
                elif i + j + k == x:
                    y += 1
    print(y // 6)

Submission status: Time Limit Exceeded

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

    print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def search(nmax, n, x):
    if n > nmax: return 0
    if x < 0: return 0
    if x == 0: return 1
    return search(nmax, n+1, x) + search(nmax, n+1, x-n)

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

    num = search(n, 0, x)
    print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

  for n1 in range(1, n+1):
    for n2 in range(2, n+1):
      for n3 in range(3, n+1):
        if n1 != n2 and n2 != n3 and n3 != n1:
          if n1+n2+n3 == x and n1 < n2 < n3:
            cnt += 1

  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve(sup,rest,digit,used1,used2):
    if digit==0:
        if rest==0:
            return 1
        else:
            return 0
    sum=0
    for i in range(1,sup+1):
        if i!=used1 and i!=used2:
            if used1==0:
                sum+=solve(sup,rest-i,digit-1,i,used2)
            elif used2==0:
                sum+=solve(sup,rest-i,digit-1,used1,i)
            else:
                sum+=solve(sup,rest-i,digit-1,used1,used2)
    return sum

N=[]
X=[]
while True:
    n,x=map(int,raw_input().split())
    if (n,x)==(0,0):
        break
    N.append(n)
    X.append(x)
for i in range(len(N)):
    print('%d'%(solve(N[i],X[i],3,0,0)/6))

Submission status: Time Limit Exceeded

Solution code:
'''
ITP-1_7-B
 ????????????????????°
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
????????????????????????????????????????????????????????°????????????????????????????????????
'''
n, x = map(int, input().split())

while True:

    # EndCheck
    if n == x == 0:
        break

    ansCnt = 0
    for cnt1 in range(1,n+1):
        for cnt2 in range(cnt1+1,n+1):
            for cnt3 in range(cnt2+1,n+1):
                if cnt1 + cnt2 + cnt3 == x:
                    ansCnt += 1
                    break
    print(ansCnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/local/env python3

import sys
from itertools import combinations


def find_all_subsets_of_target_sum(numbers, target_sum):
    subsets = []
    for x in range(len(numbers)):
        subsets.extend([
                combo for combo in combinations(numbers, x)
                if sum(combo) == target_sum
            ]
        )
    return subsets


def find_num_of_subset_with_x_elements(upper_bound, target_sum, x_elements):
    numbers = [int(number) for number in range(1, upper_bound+1)]
    subsets = find_all_subsets_of_target_sum(numbers, target_sum)
    subset_count = 0
    for subset in subsets:
        if len(subset) == x_elements:
            subset_count += 1
    return subset_count


def program_runner():
    while True:
        n, x = map(int, sys.stdin.readline().split())
        if n == x == 0:
            break
        print(find_num_of_subset_with_x_elements(n, x, 3))


def main():
    program_runner()


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
while True:
    n, x = [int(temp) for temp in input().split()]
    if n == x == 0 : break
    res  = []
    for check1 in range(1, n + 1) :
        for check2 in range(2, n + 1) :
            for check3 in range(3, n + 1) :
                if (check1 != check2) and (check2 != check3) and (check3 != check1) and (check1 + check2 + check3 == x) :
                    tem = [check1,check2,check3]
                    tem.sort()
                    if tem not in res : res.append(tem)
    print(len(res))

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
while 1:
    if n == 0 and x == 0:
        break
    s = []
    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\
                and i != j and i != k and j != k:
                    sort = sorted([i, j, k])
                    if sort not in s:
                        s.append(sort)
    print(len(s))
    n, x = map(int, input().split())

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
while True:
    if n == 0 and x == 0:
        break
    cnt = 0
    sort_list = []
    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\
                and i != j and i != k and j != k:
                    sort = sorted([i, j, k])
                    if sort not in sort_list:
                        sort_list.append(sort)
                        cnt += 1
    print(cnt)
    n, x = map(int, input().split())

Submission status: Time Limit Exceeded

Solution code:
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    a = []
    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\
                or i == j\
                or j == k\
                or i ==k:
                    continue
                if i + j + k == x:
                    sort = sorted([i, j, k])
                    if sort not in a:
                        a.append(sort)
    print(len(a))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
ans = 0
while not (N == 0 and M == 0):
 for i in range(N):
  for j in range(N):
   for k in range(N):
    if ( i==j or i==k or j==k): pass
    elif (i + j + k == M): ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
ans = 0
while not (N == 0 and M == 0):
 for i in range(N):
  for j in range(N):
   k = M - i - j
   if ( i==j or i==k or j==k): pass
   elif (i + j + k == M): ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
ans = 0
while not (N == 0 and M == 0):
 for i in range(1, N+1):
  for j in range(1, N+1):
   k = M - i - j
   if ( i==j or i==k or j==k): pass
   elif (i + j + k == M): ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
ans = 0
while not (N == 0 and M == 0):
 for i in range(1, N+1):
  for j in range(i, N+1):
   k = M - i - j
   if ( i==j or i==k or j==k): pass
   elif (i + j + k == M): ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
while True:
    array = []
    n, x = map(int, input().split())
    if n == 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 + k == x and i != j != k and i != j and i != k and j != k):
                    sort = sorted([i, j, k])
                    if sort not in array:
                        array.append(sorted((i, j, k)))
    print(len(array))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    comb = set()
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                if i == j or j == k or i == k:
                    continue
                elif i + j + k == x:
                    sort_9 = sorted((i, j, k))
                    sort_9 = tuple(sort_9)
                    comb.add(sort_9)
    print(len(comb))

Submission status: Time Limit Exceeded

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

    comb = set()
    for i in range(1, n+1):
        for j in range(2, n+1):
            for k in range(3, n+1):
                if i == j or j == k or i == k:
                    continue
                elif i + j + k == x:
                    sort_9 = sorted((i, j, k))
                    comb.add(tuple(sort_9))

    print(len(comb))

Submission status: Time Limit Exceeded

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

Submission status: Memory Limit Exceeded

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

Submission status: Accepted

Solution code:
def main():

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

        if n == x == 0:
            break
        else:
            for a in range(1, n+1):
                for b in range(1, a):
                    for c in range(1, b):
                        pattern += 1 if a + b + c == x and a > b > c else 0
            print(pattern)
                            

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    while True:
        n, x = map(int, input().split())
        if n == x == 0:
            break
        number = 0
        for i in range(n):
            j = i + 1
            if x - j > n*2 - 1:
                continue
            elif x - j <= j:
                break
            else:
                for k in range(x - j):
                    m = k + 1
                    if k < j:
                        continue
                    elif (x - j - m) > m and x - j - m <= n:
                        number += 1

        print(number)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def how_many_ways(n, x):
    ways = 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:
                    ways += 1

    return ways

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

        print(how_many_ways(n, x))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ele_and_tar = []
rs = []
flag1 = 1
flag2 = 0
while flag1:
    data = [int(x) for x in input().split()]
    if data == [0,0]:
        flag1 = 0
    else:
        ele_and_tar.append(data)
        
for i in range(len(ele_and_tar)):
    rs.append(0)
for math in ele_and_tar:
    for i in range(1,math[0]+1):
        for j in range(i+1,math[0]+1):
            for k in range(j+1,math[0]+1):
                if (i + j + k) == math[1]:
                    rs[flag2] = rs[flag2] + 1
    flag2 = flag2 + 1
    
for out in rs:
    print(out)

Submission status: Accepted

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

Submission status: Accepted

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

while not (n == 0 and x == 0):
    test = [[i,j,k] 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]
    print(len(test))
    n, x = [int(i) for i in input().split()]

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:
b = []
count = []
while True:
    inp = input()
    a = inp.split()
    a[0] = int(a[0])
    a[1] = int(a[1])
    if a[0] == 0 and a[1] == 0:
        break
    else:
        b.append(a)
        count.append(0)
for i in range(len(b)):
    for j in range(1,b[i][0]):
        for k in range(j+1,b[i][0]):
               for l in range(k+1,b[i][0]+1):
                    if b[i][1]-j-k-l == 0:
                        count[i] += 1
for i in range(len(count)):
    print(count[i])

Submission status: Accepted

Solution code:
# coding: utf-8
while True:
    n, x = map(int, input().split())
    comb = 0
    
    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):
                # print('{} {} {}'.format(i, j, k))
                if i + j + k == x:
                    comb += 1
    print(comb)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def dfs(i, j, s):
    if j > 3:
        return
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        if s + k > x:
            break
        dfs(k, j + 1, s + k)

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

    for i in range(3, n + 1):
        dfs(i, 1, i)

    print(sum(ans))

Submission status: Accepted

Solution code:
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            for k in range(1, j):
                if sum([i, j, k]) == x:
                    result += 1
    return str(result)

ans = []
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    ans.append(calc(n, x))

print("\n".join(ans))

Submission status: Accepted

Solution code:
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            if i + j < x < i + 2 * j:
                result += 1
    return str(result)

ans = []
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    ans.append(calc(n, x))

print("\n".join(ans))

Submission status: Accepted

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

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(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:
    cou = 0
    n,x = map(int,input().split())
    if n==0 and x==0:
        break
    for i in range(1,x//2):
        for j in range(i+1,x//2):
            k = x - i - j
            if i<=n and j<=n and k<=n and k>j:
                cou += 1
    print(cou)

Submission status: Accepted

Solution code:
def a():
    data_set=[]
    while True:
        s=input().split()
        data_set.append(s)
        if ["0","0"] in data_set:
            break
    data_set=data_set[:-1]
    import itertools
    for i in data_set:
        count=0
        n=int(i[0])
        x=int(i[1])
        num=list(itertools.combinations(range(1,n+1),3))
        for j in num:
            if sum(j)==x:
                count+=1
        print(count)
a()

Submission status: Accepted

Solution code:
readline = open(0).readline
ans = []
while 1:
    N, X = map(int, readline().split())
    if not N:
        break
    res = 0
    for x in range(1, N+1):
        for y in range(x+1, N+1):
            z = X - x - y
            if y < z <= N:
                res += 1
    ans.append("%d\n" % res)
open(1, 'w').writelines(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

while True:
    n, x = [int(x) for x in stdin.readline().rstrip().split()]
    if n == 0 and x == 0:
        break
    else:
        count = 0
        for i in range(1, n-1):
            for j in range(i+1, n):
                if j < x-i-j <= n:
                    count += 1
        else:
            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 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 i == k or j == k:
                    continue
                if (i + j + k) == x:
                    cnt += 1
    print('%d' % (cnt / 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(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:
dataNum = 0
combNum = [0] * 100
while True:
    n,x=map(int, input().split())
    if n is x is 0:
        break
    else:
        for a in range(1,n-1):
            for b in range(a+1,n):
                for c in range(b+1,n+1):
                    calcResult = a + b + c
                    if calcResult == x:
                        combNum[dataNum] += 1
                    else:
                        pass
    dataNum += 1

for index in range(dataNum):
    print(combNum[index])

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(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=map(int,input().split())
    a=0
    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:a+=1
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: UTF-8

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, N+1):
            if i >= j:
                continue
            c = X - (i + j)
            if c > j and c <= N:
                ans += 1
    print("%d"%(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x = -1,-1
table = []
while n != 0 or x != 0:
  n,x = (int(x) for x in input().split())
  table.append([n,x])

for t in table:
  n = t[0]
  x = t[1]
  if n == 0 and x == 0:
    break
  i = 1
  s = 0
  while i < n:
    #print (i)
    if x - i > n + (n - 1):
      i += 1
      continue
    else:
      j = i + 1
      while j < n:
        #print (str(i) + "," + str(j) + "," + str(x - i - j))
        if x - i - j <= n and x - i - j > j:
          s += 1
        j += 1
      i += 1
  print (s)

Submission status: Accepted

Solution code:
import itertools

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

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

	#データリスト作成
	data = [m for m in range(1,n+1)]
	data_cmb = list(itertools.combinations(data,3))

	#検証
	res = [ret for ret in data_cmb if sum(ret) == x]
	print(len(res))

Submission status: Accepted

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

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

	#データリスト作成
	data = [m for m in range(1,n+1)]
	data_list = []
	cnt = 0
	#n種類の数字があって、xになる組み合わせは？
	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:
					cnt += 1

	print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
count_a = []
pos = 0
while True:
    n, x = list(map(int, input().split()))
    count = 0
    if n == x == 0:
        break
    else:
        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) and (j != k) and (i != k):
                        if (i+j+k) == x:
                            count += 1
        count_a.append(count)
        pos = pos+1

for i  in count_a:
    print(i)

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(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:
    e,a = map(int,input().split())
    if e ==0 and a ==0:
        break
    cnt = 0
    for i in range(1,e+1):
        for j in range(1,e+1):
            if j<=i:
                continue
            X = a - (i + j)
            if X > j and X <=e:
                cnt +=1
    print(cnt)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    from sys import stdin
    from itertools import combinations

    while True:
        n, x = (int(n) for n in stdin.readline().rstrip().split())

        if n == x == 0:
            break

        a = range(1, n + 1)
        l = tuple(filter(lambda _: sum(_) == x, combinations(a, 3)))

        print(len(l))