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 -*-

def main():

    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)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n,x = map(int,input().split())
    if n == x == 0:
        exit()
    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:
num=[]
while True:
    num.append(list(map(int,input().split(" "))))
    if num[-1]==[0,0]:
        num=num[:-1]
        break
def sample(lst):
    tmp=0
    for i in range(1,lst[0]+1):
        for j in range(i,lst[0]+1):
            for k in range(j,lst[0]+1):
                if i+j+k==lst[1] and i!=j and j!=k:
                    tmp+=1
    return tmp
ans=[sample(i)for i in num]
for i in ans:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
results = []

def comb_gen(n):
    combs = []
    comb = []

    mb = 2 ** n
    for i in range(mb - 1):
        bi = bin(i + 1)[2:]
        con = "0" * (n - len(bi)) + str(bin(i + 1)[2:])
        #print(con)
        sum = 0
        for j in range(len(con)):
            if con[j] == "1" and sum < 3:
                comb.append(j + 1)
                sum += 1
        if len(comb) == 3 and comb not in combs:
            #print(comb)
            combs.append(comb)
        con = ""
        comb = []
    return combs

def combgen(n):
    nums = [i for i in range(1, n+1)]
    combs = []
    for i in itertools.combinations(nums, 3):
        combs.append(i)
    return combs

def sum_chk(combs, x):
    combs = combs
    res = 0
    for i in range(len(combs)):
        #print(combs[i])
        if sum(combs[i]) == x:
            #print(combs[i])
            res += 1
    return res

#print(comb_gen(5))


while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    combs = combgen(n)
    result = sum_chk(combs, x)
    results. append(result)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#67 組み合わせの数

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    while True:
        n, x = map(int, readline().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):
                    k = x-i-j
                    if j<k<=n:
                        count += 1
            print(count)





if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    
    if n==0 and x==0:
        break
    
    L=list(range(1,n+1))
  
    
    a=0
    for i in range(n-2):
        b=L[i]
        for j in range(1,n-1):
            c=L[j]
            for k in range(2,n):
                d=L[k]
                
                if b+c+d==x:
                    
                    if b>=c or c>=d :
                        pass
                    else:
                        a+=1
                    
    
    print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
while True:
    count = 0
    n,x = map(int,input().split())
    if [n,x] == [0,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:
import itertools
data = []
data_1 = []
while True:
    s = list(map(int, input().split()))
    if s[0] == 0 and s[1] == 0:
        break
    data.append(s)
# for n, x in data:
#     a = [i for i in range(1, n + 1)]
#     b = list(itertools.combinations(a, 3))
#     for c in b:
#         d = sum(c)
#         if d == x:
#             data_1.append(c)
#     print(len(data_1), end=" ")

for i in range(len(data)):
    data_1 = []
    n = data[i][0]
    x = data[i][1]
    
    a = [j for j in range(1, n + 1)]
    b = list(itertools.combinations(a, 3))
    
    for c in b:
        d = sum(c)
        if d == x:
            data_1.append(c)
    
    print(len(data_1), end="\n")

Submission status: Accepted

Solution code:
import itertools
data = []

while True:
    s = list(map(int, input().split()))
    if s[0] == 0 and s[1] == 0:
        break
    data.append(s)
    
for n, x in data:
    data_1 = []
    a = list(range(1, n + 1))
    for c in itertools.combinations(a, 3):
        d = sum(c)
        if d == x:
            data_1.append(c)
    print(len(data_1))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    print(c)

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if n==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:
#演習２－１ 

while True:
    n, x = map(int,input().split())
    if n == 0 and x ==0:
        break
    else:
        count=0
        #i < j < kと仮定することで、以下のように書ける
        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
                        
        print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
    n, x = map(int, input().split())
    if n==0 and x==0:
        break
    pool = []
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                if(x==i+j+k and i!=j and i!=k and j!=k):
                    tmp = set(list([i,j,k]))
                    if tmp not in pool:
                        pool.append(tmp)
    print(len(pool))

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):
        for b in range(a+1,N+1):
            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
    else:
        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:
import itertools

while True:
    n, x = list(map(int, input().split()))
    
    if n == x == 0 : 
          break
      
    count = 0
        
    for v in itertools.combinations(range(1,n+1), 3):
        if sum(v) == 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
    snt=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            if j<x-i-j<=n:
                snt+=1
    print(snt)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    
    a=list(range(1,n+1))
    m=0
    for i in range(n):
        f=a[i]
        for j in range(n-1):
            if a[j]!=f and a[j]<f:
                g=a[j]
            else: break
            for k in range(n-2):
                if a[k]==f or a[k]==g:
                    break
                if a[k]==x-f-g and a[k]!=f and a[k]!=g:
                    m+=1
                
    print(m)

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

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline
while True:
    n, x = map(int, input().split())
    
    if n == 0 and x == 0:
        break
    
    ans = 0
    for a in range(1, n-1):
        for b in range(a+1, n):
            c = x - a - b
            if c > b and c <= n:
                ans += 1
    
    print(ans)

Submission status: Accepted

Solution code:
ls = []
while 1:
    ls1 = list(map(int,input().split()))
    if ls1[0] == 0 and ls1[1] == 0:
        break
    ls.append(list(ls1))
    ls1.clear()
#print(ls)
for i in range(len(ls)):
    ans = 0
    for j in range(1,ls[i][0]+1):
        for k in range(j+1,ls[i][0]+1):
            for l in range(k+1,ls[i][0]+1):
                #print(i,j,k,l,ls[i][1])
                if j + k + l == ls[i][1]:
                    #print(j,k,l)
                    ans += 1
    print(ans)

Submission status: Accepted

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

    if n == 0:
        break

    ans = []

    for count_a in range(1, n + 1):
        for count_b in range(1 + count_a, n + 1):
            for count_c in range(1 + count_b, n + 1):
                if count_a == count_b or count_b == count_c or count_a == count_c:
                    continue

                if count_a + count_b + count_c == x:
                    ans.append([count_a, count_b, count_c])
    # print(ans)
    # 6通り出ちゃうから
    # print(ans)
    print(int(len(ans)))

Submission status: Accepted

Solution code:
import sys
from itertools import combinations


def main():
    input = sys.stdin.buffer.readline
    while True:
        n, x = map(int, input().split())
        if n == x == 0:
            break
        ans = 0
        for c in combinations(range(1, n + 1), 3):
            ans += sum(c) == x
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
XS = list(map(int, open(0).read().split()))
for i in range(0, len(XS), 2):
    n,x = XS[i:i+2]
    if n == 0 and x == 0:
        break
    ans = 0
    for j1 in range(1, n+1):
        for j2 in range(j1+1, n+1):
            for j3 in range(j2+1, n+1):
                if j1 + j2 + j3 == x:
                    ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
while a!=0 or b!=0:
    c=0
    for i in range(1,a+1):
        for j in range(i+1,a+1):
            for k in range(j+1,a+1):
                if i+j+k==b:
                    c=c+1
                
    a,b=map(int,input().split())
    print(c)

Submission status: Accepted

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

    print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools 

import sys
input = sys.stdin.readline
count=0
while True:
    N,X=map(int,input().split())
    if N==0 and X==0:
        
        exit()
    else:
        count=0
        T=[]
        for i in range(N):
            T.append(i+1)


        D=list(itertools.combinations(T,3))
        for Z in D:
            if Z[0]+Z[1]+Z[2]==X:
                count+=1
        print(count)

Submission status: Accepted

Solution code:
import itertools as it

n, x = map(int, input().split())

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

    res = 0
    li = range(1, n + 1, 1)
    for c in it.combinations(li, 3):
        res += 1 if sum(c) == x else 0
    print(res)

    n, x = map(int, input().split())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import *

while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    else:
        l = list(combinations(list(range(1, n + 1)), 3))
        count = [1 for s in l if sum(s) == x]
        print(f"{len(count)}")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = []
while True:
    N, X = map(int, input().split())
    if N == 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
    ans.append(cnt)
print(*ans, sep="\n")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def ways(n: int, x: int) -> int:
    counter = 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:
                    counter += 1
    return counter


def resolve():
    for line in sys.stdin:
        n, x = map(int, line.split())
        if n == x == 0:
            break

        print(ways(n, x))


resolve()

Submission status: Accepted

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

for i in nx:
    n = i[0]
    x = i[1]
    s = [j for j in range(1, n+1)]
    t = 0
    for o in range(0,n-2):
        for p in range(o+1,n-1):
            for q in range(p+1,n):
                if s[o]+s[p]+s[q] == x:
                    t += 1
    ans.append(t)

for i in ans:
    print(i)

Submission status: Accepted

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


l = len(n)
for i in range(l):
    cnt = 0
    for a in range(1, n[i]-1):
        for b in range(a+1, n[i]):
            for c in range(b+1, n[i]+1):
                if a + b + c == x[i]:
                    cnt += 1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys
n=1
while n>0:

    n,x= map(int,input().split())


    if n==x==0:
        sys.exit()

    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:
    a,b=map(int,input().split())
    sum=0
    e=[]
    if a==0 and b==0:
        break
    else:
        for i in range(1,a+1):
            for j in range(1,a+1):
                for k in range(1,a+1):
                    if i+j+k==b:
                            d=[i,j,k]
                            d.sort()
                            e.append(d)
    #print(e)
    uniqued = []
    for x in e:
        if not x in uniqued:
            uniqued.append(x)
    for i in range(len(uniqued)):
        for j in range(2):
            for k in range(2-j):
                if uniqued[i][j]==uniqued[i][2-k]:
                    sum+=1
                    break
            if uniqued[i][j]==uniqued[i][k]:
                break           
    print(len(uniqued)-sum)

Submission status: Accepted

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

Submission status: Accepted

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

for a in l:
    aa = [ i for i in range(1, a[0] + 1)]
    s = 0
    for i in range(0, len(aa) + 1):
        for j in range(i + 1, len(aa) + 1):
            for k in range(j + 1, len(aa)):
                t = aa[i] + aa[j] + aa[k]
                if t == a[1]:
                    s += 1
    print(s)

Submission status: Accepted

Solution code:
while True:
    dataset = input().split(" ")

    n = int(dataset[0])
    x = int(dataset[1])

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

    answer = []
    for i in range(n, 0, -1):
        for j in range(i-1, 0, -1):
            for k in range(j-1, 0, -1):
                if i + j + k == x:
                    obj = [i, j, k]
                    answer.append(obj)

    print(len(answer))

Submission status: Accepted

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

for n,x in a:
  res={}
  for i in range(1,n+1):
    for j in range(1,n+1):
      for k in range(1,n+1):
        if i+j+k==x and  i!=j and j!=k and k!=i:
          tmp=[i,j,k]
          tmp.sort()
          s=str(tmp[0])+str(tmp[1])+str(tmp[2])
          res[s]=1                               
  print(len(res))

Submission status: Accepted

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

Submission status: Accepted

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

import itertools

def main():
    while True:
        n,x = map(int,input().split())
        available_list=[int(i) for i in range(1,n+1)]
        counter=0
        if n==0 and x==0:
            exit()
        for value in itertools.combinations(available_list,3):
            if sum(value)==x:
                counter+=1
        print(counter)

if __name__=="__main__":
    main()