Problem:


How many ways?

  Write a program which identifies the number of combinations of three integers which satisfy the following conditions:

  
You should select three distinct integers from 1 to n.

  
A total sum of the three integers is x.

  For example, there are two combinations for n = 5 and x = 9.

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

  The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.

  The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.

Constraints

  
3 ≤ n ≤ 100

  
0 ≤ x ≤ 300

Output

  For each dataset, print the number of combinations in a line.

Sample Input

5 9
0 0

Sample Output

2

Note

      解説      

	


Sample input:
5 9
0 0


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
	n, x = map(int, input().split())
	if n == 0 and x == 0:
		break
	results = [] 
	n_list = [i for i in range(1, n+1)] 
	for i in n_list:
		for j in n_list:
			r = x - (i+j)
			if r in n_list:
				value = sorted([i, j, r])
				if len(list(set(value))) == 3 and not value in results:
					results.append(value)
	print(len(results))

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('{}'.format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    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
    listC.append(counter)
    counter = 0

for h in listC:
    print(h)

Submission status: Accepted

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

    print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations

results = []
while 1:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    count = 0
    for a, b, c in combinations(range(1, n+1), 3):
        if a + b + c == x:
            count += 1
    results.append(count)
print('\n'.join(map(str, results)))

Submission status: Accepted

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

            b-=1
            c=b-1
        a-=1
        b=a-1
        c=b-1

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = []
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
    ans.append(cnt)
print("\n".join(map(str,ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    n,x = map(int,input().split())
    if n==0 and x==0:
        return False
    ans = 0
    s = set()
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            it = x-i-j
            v = [it,i,j]
            v = sorted(v)
            val = v[0]*1000000+v[1]*1000+v[2]
            if 0<it<=n and it!=i and it!=j and (not val in s):
                s.add(val)
                ans+=1
    print(ans)
    return True
if __name__ == "__main__":
    while(solve()):
        pass

Submission status: Accepted

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

while not (n==0 and x== 0):
    count = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            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:
for _ in range(10000):
    n,x=list(map(int,input().split()))
    if n==0 and x==0:
        exit(0)
    ans=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if j<x-i-j<n+1:
                ans+=1
    print(ans)

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) - 1 for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

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

    ans = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if i+j > x:
                break
            for k in range(j+1, n+1):
                tmp = i+j+k
                if tmp==x:
                    ans+=1
                if tmp>=x:
                    break

    print(ans)

Submission status: Accepted

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

    for i in range(1,n+1):
        for j in range(2,n+1):
            if j <= i:
                pass
            else:
                for k in range(3,n+1):
                    if k <= j or k <= i:
                        pass
                    else:
                        if i+j+k == x:
                            count += 1
    print (count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = []
for i in iter(input, '0 0'):
    a.append(list(map(int, i.split())))
for i in range(len(a)):
    ans = 0
    for j in range(1, a[i][0]-1):
        for k in range(j+1, a[i][0]):
            for l in range(k+1, a[i][0]+1):
                if j+k+l == a[i][1]:
                    ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

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

Submission status: Accepted

Solution code:
from itertools import (
    accumulate,  # 累積和のイテレータ
    groupby,  # 値をkey,同じ値の集まりをgroup
    permutations,  # 順列
    combinations,  # 組み合わせ
    product,  # 重複あり順列（直積, 深いネストにも使える）
)

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

Submission status: Accepted

Solution code:
n_x = []

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

for n, x in n_x:
    ans = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    ans = []
    while True:
        N, X = map(int, input().split())
        if N == 0 and X == 0:
            break
        ans.append(solve(N, X))
    print(*ans, sep="\n")

Submission status: Accepted

Solution code:
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/7/ITP1_7_B


def solve(n, x):

    result = 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 or j == k or k == i:
                    continue

                if i + j + k == x:
                    result += 1

    return result


if __name__ == "__main__":
    while True:
        n, x = map(int, input().split())
        if n == 0 and x == 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:
    exit()
  else:
    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:
while True:
    n,x = map(int,input().split())
    if n==0 and x==0:
        break
    print(sum( [ max(min(n,(x-i+1)//2) - max(i+1,x-i-n),0) for i in range(1,x//3) ]))

Submission status: Accepted

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

    if n == 0 and x ==0 :
        break
    t=0
    for i in range(n,2,-1):
        for j in range(n-1,1,-1):
            if i >j:
                for k in range(n-2,0,-1):
                    if j > k:
                        if i+j+k == x:
                            t += 1
    print(t)

Submission status: Accepted

Solution code:
while True:
    # 入力
    n, x = (int(i) for i in input().split())
    # 終了条件
    if n==0 and x==0:
        break
    # メインの処理、xとnはそんなに大きな数ではないので愚直なアルゴリズムを実装する
    out = 0     # 出力する結果、初期値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:
                    out += 1
    print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ryu(x,y):
    count=0
    for p in range(1,x-1):
        for q in range(p+1,x):
            for r in range(q+1,x+1):
                if p+q+r==y:
                    count+=1
    return count

while 1:
    a,b=map(int,input().split())
    if a+b==0:
        break
    print(ryu(a,b))

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
import itertools

while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    counter = 0
    for v in itertools.combinations(list(range(1, n+1)), 3):
        if sum(v) == x:
            counter += 1
    print(counter)

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
    N, X = map(int, input().split())
    if N==0 and X==0:
        exit()
    A = list(range(1, N+1))
    Comb = combinations(A, 3)
    ans = 0
    for a, b, c in Comb:
        if (a+b+c) == X:
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
arr = []
while True:
    tmp = tuple(map(int, input().split()))
    if tmp == (0, 0):
        break
    else:
        arr.append(tmp)
for elem in arr:
    n = elem[0]
    x = elem[1]
    ans = 0
    li = [i for i in range(1, (n + 1))]
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                if li[i] + li[j] + li[k] == x:
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    [n, x] = [int(item) for item in input().split()]
    if n==0 and x==0:exit()
    returnList=[]
    cnt = 0
    for i in range(1,n+1):
        for j in range(1,i):
            k = x - i - j
            if k <j and k>0:
                returnList.append(sorted([i,j,k]))
                #print("i,j,k={},{},{}".format(i,j,k))
                #print("returnSet = {}".format(returnList))
    print(len(returnList))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
for i in range(10**5):
    x,y = map(int,input().split())
    if x == 0 and y == 0:
        break
    else:
        ans = 0
        for i in range(1,x+1):
            for j in range(i+1,x+1):
                for k in range(j+1,x+1):
                    if i+j+k == y:
                        if i!=j!=k:
                            ans += 1
        print(ans)

Submission status: Accepted

Solution code:
import itertools as it
for i in range(10**9):
    cnt=0
    n,x=map(int,input().split())
    if n==0 and x==0:
        exit()
    comb=it.combinations(range(1,n+1),3)
    for i in comb:
        if sum(i)==x:
            cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
while 1:
    # A = input()
    # A = int(input())
    n, x = map(int, input().split())
    plus1 = lambda x: x + 1
    # A = list(map(int, input().split()))
    # A = [int(input()) for i in range(N)]
    #
    # c = collections.Counter()

    if (n, x) == (0, 0):
        break
    else:
        c = 0
        for i in range(n):
            for j in range(i):
                for k in range(j):
                    if (i+1) + (j+1) + (k+1) == x:
                        c += 1

    print(c)

Submission status: Accepted

Solution code:
listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;


for pair in listA:
	n = pair[0]
	x = pair[1]
	
	if n == 0 and x == 0:
		break
	
	result = 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:
					result+=1
	print(result)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
L = []
while n != 0 or x != 0:
    L.append([n, x])
    n, x = map(int, input().split())
for i in range(len(L)):
    A = []
    for a in range(1, L[i][0] - 1):
        for b in range(2, L[i][0]):
            for c in range(3, L[i][0] + 1):
                if a < b < c and a + b + c == L[i][1]:
                    A.append([a, b, c])
    print(len(A))

Submission status: Accepted

Solution code:
import itertools

n, x = -1, -1
dataset = []

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

for data in dataset:
    c = 0
    arr = [x + 1 for x in range(data[0])]
    for v in itertools.combinations(arr, 3):
        if sum(v) == data[1]: c +=1
    print(c)

Submission status: Accepted

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

for data in dataset:
    count = 0
    n, x = data[0], data[1]

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

    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = []
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    tmp = 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:
                    tmp += 1
    ans.append(tmp)
[print(x) for x in ans]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
nl = lambda: list(map(int, stdin.readline().split()))


while True:
    ct = 0
    n, x = na()
    if n == 0 and x == 0:
        break
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            k = x - i - j
            if k > j and k <= n:
                #print(i, j, k)
                ct += 1
    print(ct)

Submission status: Accepted

Solution code:
from itertools import combinations
while True:
    n, x = [int(i) for i in input().split()]
    if n == 0 and x == 0:
        break
    ans = 0
    for i, j in combinations(range(1, n+1), 2):
        k = x - i - j
        if j < k <= n and k not in (i, j):
            ans += 1
    print(ans)

Submission status: Accepted

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


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

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(ans)

Submission status: Accepted

Solution code:
while True:
    count=0
    sum=0
    a,b=map(int,input().split())
    if a==0 and b==0:
        break

    for i in range(1,a+1):
        sum+=i
        for j in range(i+1,a+1):
            sum+=j
            for k in range(j+1,a+1):
                sum+=k
                if sum==b:
                    count+=1
                sum-=k
            sum-=j
        sum=0
    print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
while 1:
    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):
            c = x-a-b
            if c>b and c<=n:
                cnt+=1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    c = 0
    for a in range(1,n):
        for b in range(a+1, n+1):
            num = x - a - b
            if n >= num > b:
                c += 1
                # print(a,b,num)
            elif b > num:
                break
    print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    for i in range(n):
        for j in range(n):
            if j == i:
                break
            for k in range(n):
                if j == k:
                    break

                if (i + 1) + (j + 1) + (k + 1) == x:
                    cnt += 1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    counter = 0

    for first in range(n, 2, -1):
        # print("first:", first)

        for second in range(first-1, 1, -1):
            # print("second:", second)
            third = x - (first + second)

            if third > 0 and third < second:
                # print(first, second, third)
                counter = counter + 1 

    print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from itertools import combinations
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    while True:
        N,X=map(int,input().split())
        if N==X==0:
            exit()
        c=combinations(range(1,N+1),3)
        ans=0
        for x in c:
            if sum(x)==X:
                ans+=1
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    cnt = 0
    for i in range(1, N):
        for j in range(i+1, N):
            if(j<X-i-j<=N):
                cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
count = 0
data = []
ans = []
while True:
    n, m = map(int, input().split())
    data.append([n,m])
    if data[count][0] == data[count][1] == 0:
        break
    count += 1
data.pop()
for i in data:
  count = 0
  for j in range(1, (i[0]+1)):
    for k in range(1, (i[0]+1)):
      for l in range(1, (i[0]+1)):
        if (j+k+l) == i[1] and j != k and j != l and k != l:
          count += 1
  ans.append(count)
for m in ans:
  print(m//6)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve(n,x):
    ans = 0
    for i in range(1,n+1):
        for j in range(1,i):
            s = i+j
            for k in range(1,j):
                ns = s+k
                if ns == x:
                    ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    while 1:
        n,x = LI()
        if n == x == 0:
            break
        solve(n,x)

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 + 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:
data_list = list()
while True:
    data = list(map(int,input().split()))
    if data == [0,0]:
        break
    data_list.append(data)

for data in data_list:
    cnt = 0
    for a in range(1,data[0]):
        for b in range(a+1,data[0]):
            c = data[1] - a - b
            if c > 0 and c != a and c != b and c > b and c < data[0]+1:
                cnt += 1
    print(cnt)