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:
import sys

while(1):
    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+1):
            if x-i-j > j and x-i-j <= n:
                ans += 1
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
#67
import itertools
K=[]
A=int()
while True:
    n,x = map(int,input().split())

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

    #for i in range(n):
    K=[int(i) for i in range(1,n+1)]
    
    c=list(itertools.combinations(K,3))
    #print(c)
    for j in range(len(c)):
        a = c[j][0]+c[j][1]+c[j][2]
        
        if a==x:
            #print(c[j][0])
            A += 1
    print(A)
    A=0

Submission status: Accepted

Solution code:
from itertools import combinations

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, x = list(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:
import itertools

def solve(n,x):
  count = 0
  li = [x for x in range(1,n+1)]
  for team in itertools.combinations(li, 3):
      # print(team)
      if sum(team) == x:
        count += 1

  return print(count)

for i in range(100000000):
  n, x = map(int, input().split())
  if n == 0 and x == 0:
    break
  solve(n, x)

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(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 == 0 and x == 0:
        break

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    while True:
        a, b = map(int, input().split())
        if a==0 and b ==0:
            sys.exit()
        s = range(1, a+1)
        count = 0
        kumi = [[0,0,0]]
        for i in s:
            for k in s:
                for j in s:
                    if i + k + j == b and i != k and k != j and i != j:
                        flag = True
                        for ku in kumi:
                            if i in ku and k in ku and j in ku:
                                flag = False
                                break
                        if flag:
                            kumi.append([i,k,j])
                            count += 1
        print(count)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
while n != 0 or x != 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:
def main():
    import sys
    
    while True:
        n, x = tuple(map(int, sys.stdin.readline().split()))
        cnt = 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:
                        cnt+=1
        
        print(cnt)
                    
    

if __name__=='__main__':
    main()

Submission status: Accepted

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

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

for i in range(len(n)):
    cnt = 0
    for i2 in range(1,n[i]+1):
        for i3 in range(1,n[i]+1):
            if i2 >= i3:
                continue
            for i4 in range(n[i]+1):
                if i3 >= i4:
                    continue
                y = x[i] - (i2+i3+i4)
                
                if y==0:
                    cnt +=1
                    break

    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lis=[]

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


for v in lis:
	n=v[0]
	x=v[1]
	# nums=lis(range(1,n+1))
	count=0
	for j in range(1,n-2 +1):
		for k in range(j+1,n-1 +1):
			for l in range(k+1,n +1):
				if j+k+l==x:
					count+=1

	print(count)

Submission status: Accepted

Solution code:
def find_conb(result_list,candidate,result,cond):
    
    if len(result)>3:
        return
    
    #2つめの要素の処理で処理が完了する
    #->level3の展開が不要になる
    if len(result)==2:
        res=cond-sum(result)
        if res in candidate:
            result_list.append(result[:]+[res])
            return
        else:
            return
    
    if sum(result) == cond and len(result)==3:
        return
        result_list.append(result[:])
        return
    
    #和が超えたら終了
    if sum(result) > cond:
        return
    
    #候補がなくなったら終了
    if len(candidate) == 0:
        return
    #canditateの最小値がcondを超えたら枝仮
    if candidate[0] >= cond:
        return
    

    
    n=candidate.pop(0)
    
    # print(result[:]+[n])
    find_conb(result_list,candidate[:],result[:]+[n],cond)
    #nを含まないとき
    find_conb(result_list,candidate[:],result[:],cond)
    

def run():
    
    data_list=[]
    
    while True:
        n,x=tuple(map(int,input().split()))
        
        if n==0 and x==0:
            break
        
        data_list.append((n,x))
    
    
    for n,x in data_list:
        #組み合わせの計算
        #動的計画法が必要
        result_list = []
        candidate=[i for i in range(1,n+1)]
        cond=x
        result=[]
        find_conb(result_list,candidate,result,cond)
        
        print(len(result_list))
    # print(result[:]+[n])
    find_conb(result_list,candidate[:],result[:]+[n],cond)
    #nを含まないとき
    find_conb(result_list,candidate[:],result[:],cond)
    

def run():
    
    data_list=[]
    
    while True:
        n,x=tuple(map(int,input().split()))
        
        if n==0 and x==0:
            break
        
        data_list.append((n,x))
    
    
    for n,x in data_list:
        #組み合わせの計算
        #動的計画法が必要
        result_list = []
        candidate=[i for i in range(1,n+1)]
        cond=x
        result=[]
        find_conb(result_list,candidate,result,cond)
        
        print(len(result_list))

run()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

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

    print(ans)

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

Submission status: Accepted

Solution code:
inp = []
while(1):
    ans = 0
    n, x = map(int, input().split())
    if n == 0:
        break
    for y1 in range(1, n-1):
        for y2 in range(y1+1, n):
            for y3 in range(y2+1, n+1):
                if y1 + y2 + y3 == 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:
        a=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:
                         a+=1
        print(a)

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

Submission status: Accepted

Solution code:
def solve(n, x):
    """
    a + b + c = x
    となる a, b, cを求める。
    重複を無くして考えるため、
    a < b < cとする。
    1 <= a < b <= n
    を満たすような2重ループを作る。
    a,bを固定すれば、cを出せるので、
    a<b<cを満たすとき、ans += 1
    """
    ans = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            c = x - a - b
            if b < c <= n:
                ans += 1

    print(ans)
    return


def main():
    while True:
        n, x = list(map(int, input().split()))
        if n == x == 0:
            break
        else:
            solve(n, x)
    return


if __name__ == "__main__":
    main()

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):
            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

    cnt=0
    for i in range(1,n+1):
        for j in range(1+i,n+1):
            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)&(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:
# coding: utf-8
# Your code here!

while True:
   n, x = map(int, input().split())
   if n + x == 0:
      break
   
   c = 0
   li = []
   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:
for e in iter(input, "0 0"):
    
    n,x=map(int,e.split())

    i = 1
    j = i + 1
    k = i + 2

    result = 0

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

        if n < k:
            j += 1
            k = j + 1
            if n < k:
                i += 1
                j = i + 1
                k = j + 1 
                if n < k:
                    break

    print(result)

Submission status: Accepted

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

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

    for i in range(n):
        for j in range(n):
            for k in range(n):
               if i < j < k:
                   if i + j + k + 3 == x:
                       y += 1

    print(y)

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

Solution code:
while True:
    ans = 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):
            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())
    cnt = 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:
                    cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

    count = 0

    u = math.ceil(x/3)
    while u<=n and u<=x-3:
        v = (x-u)//2 + 1
        while v < (x-u):
            w = (x-u) - v
            if u > v > w:
                count +=1
                #print(u, v,w)
            v+=1
        u+=1
    print(count)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


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

Submission status: Accepted

Solution code:


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

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

Submission status: Accepted

Solution code:
n = []; x = []
for _ in range(3000):
    i, j = map(int, input().split())
    if i == 0 and j == 0:
        break
    else:
        n.append(i)
        x.append(j)

cnt = [0 for _ in range(len(n))]
for i in range(len(n)):
  sequence = [h+1 for h in range(n[i])]
  for j in reversed(sequence):
    for k in reversed(sequence[1:j-1]):
      if j + k >= x[i] or x[i] - (k-1) > j + k:
        continue
      cnt[i] += 1
  print(cnt[i])

Submission status: Accepted

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

    cnt = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            if j+1 <= x-i-j <= n:
                cnt += 1

    print(cnt)

Submission status: Accepted

Solution code:
while True:
    try:
        n, x = map(int, input().split())
    
        if n==0 and x==0:
            break
    
    except:
        break
    
    S = []
    for i in range(1,n+1,1):
        for j in range(1,n+1,1):
            for k in range(1,n+1,1):
                
                if i<j<k:
                    s = i+j+k
                    if s==x:
                        S.append(s)
    
    Slen = len(S)
    print(Slen)
    
    continue

Submission status: Accepted

Solution code:
from itertools import combinations

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

    count = 0
    for values in combinations(range(1, n + 1), r=3):
        if sum(values) == x:
            count += 1

    print(count)

Submission status: Accepted

Solution code:
import itertools

while(True):
  n,x = map(int, input().split(" "))
  if n == 0:
    break
  count = 0
  for i in itertools.combinations(range(1, n + 1), 3):
    if sum(i) == x:
      count += 1
  print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def combs(n, x):
    c = 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:
                    c+=1
                elif i+j+k > x:
                    break
    return c

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    ans = 0
    if n == 0 & 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:
from itertools import combinations

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

Submission status: Accepted

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

    count = 0

    for i in range(1, x // 3):
        for j in range(i + 1, x // 2):
            k = x - i - j
            if j < k <= n:
                count += 1

    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools


input_list = []

for i in iter(input, '0 0'):
    input_list.append(i)

for i in input_list:
    count = 0
    n, x = map(int, i.split())
    for j in itertools.combinations(range(1, n + 1), 3):
        if sum(j) == x:
            count += 1
    print(count)

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

Submission status: Accepted

Solution code:
#1_7_B
import itertools
while True:
    n , x = map(int,input().split())
    if n == x == 0:
        break
    l =[]
    for j in range(1 , n+1):
        l.append(j)

    li =  [i for i in itertools.combinations(l, 3)]
    y = len(li)
    s = 0
    for j in range(y):
        if sum(li[j]) == 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
    
    
    cnt = 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:
                    cnt += 1
                    
    
    print(cnt)

Submission status: Accepted

Solution code:
def main_v2():
    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):
                k = x - (i + j)
                if k > j and k <= n:
                    count += 1
        print(count)
    return 0


if __name__ == "__main__":
    main_v2()

Submission status: Accepted

Solution code:
ans = []
while True:
    n,x = [int(i) for i in input().split()]
    count = 0
    st = []
    if n == 0 and x == 0:
        break
    for i in range(1,n+1):
        for j in range(2,n+1):
                if j <= i:
                    continue
                k = x - (i + j)
                if j < k and k <= n:
                    count += 1
    ans.append(count)

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

Submission status: Accepted

Solution code:
while 1:
    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
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, x = [int(arg) for arg in input().split()]
    if n == 0 and x == 0:
        break
    if x < 6:
        print(0)
        continue

    count = 0
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if i == j:
                continue
            elif i + j >= x:
                continue
            for k in range(1, n + 1):
                if i != j and j != k and i != k and i + j + k == x:
                    count += 1
    print(int(count / 6))

Submission status: Accepted

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

    n = x - 3 if n >= x - 2 else n
    count = 0
    
    for maximum in range(n, 2, -1):
        for mid in range(maximum - 1, 1, -1):
            for minimum in range(mid - 1, 0, -1):
                if maximum + mid + minimum == x:
                    count += 1
                    
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

while True:
    count = 0
    n, x = list(map(int, input().split(' ')))
    if n == 0 and x == 0:
        sys.exit(0)
    for i in range(n+1):
        for j in range(n+1):
            for k in range(n+1):
                if i >= j or j >= k or i == 0:
                    continue
                if i + j + k == x:
                    count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    while True:
        n,x=map(int,readline().split())
        if n==0 and x==0:
            break
        ans=0
        for a in range(1,n+1):
            for b in range(a+1,n+1):
                for c in range(b+1,n+1):
                    if a+b+c==x:
                        ans+=1

        print(ans)

if __name__=="__main__":
    main()