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 1:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    c=0
    lis=[i+1 for i in range(a)]
    for i in range(a-2):
        for j in range(i+1,a-1):
            for l in range(j+1,a):
                if lis[i]+lis[j]+lis[l]==b:
                    c+=1
    print(c)

Submission status: Accepted

Solution code:
result = list()
while(True):
    n,x = map(int,input().split())
    count = 0
    if n==x and n==0:
        break
    
    if x /3 > n-1:
        print("0")
        continue
    if x - 2*n+1 >0 :
        start = x-2*n+1
    else :
        start = 1
    flag = 0
    for i in range(start,n):
        for j in range(i+1,n):
            if x - i - j <= j:
                break
            if x-i-j <= 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

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

Submission status: Accepted

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

    n_list = [int(x) + 1 for x in range(n)]
    p_list = list(itertools.combinations(n_list,3))
    r = 0
    for p in p_list:
        if p[0] + p[1] + p[2] == x:
            r += 1
    print(r)

Submission status: Accepted

Solution code:
import sys
while True:
  n,x=map(int,input().split())
  if n==0 and x==0: sys.exit()
  
  ans=0
  for i in range(n):
    i+=1
    for j in range(n-i):
      j+=i+1
      for k in range(n-j):
        k+=j+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(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
    import itertools
    pairList = itertools.product(range(1, n+1),range(1, n+1),range(1, n+1))
    print(sum([1 for i, i2, i3 in pairList if i + i2 + i3 == x and i < i2 < i3]))

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):
        if a + (a+1) + (a+2) > x:
            continue
        for b in range(a+1,n+1):
            for c in range(b+1,n+1):
                if a + b + c == x:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
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:
import itertools

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

    ret = 0
    for v in itertools.combinations(list(range(1, n + 1)), 3):
        if sum(v) == x:
            ret += 1

    print(ret)

Submission status: Accepted

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    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)
main()

Submission status: Accepted

Solution code:

while 1:

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

 print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == 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:
#ループでnとｘを読み込む
#１からｎー１でルーぷ
while True:
    line = list(map(int,input().split()))
    n = line[0]
    x = line[1]
    result=0
    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):
                if i+j+k ==x:
                    result +=1
    print(result)

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):
					total = i + j + k
					if total == 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:
                    #print(i, j, k)
                    ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

for e in sys.stdin:
    cnt = 0
    max, sum = map(int,e.split())

    if max == 0 and sum == 0:
        break    
    for i in range(1,max+1):
        for j in range(1,max+1):
            for k in range(1,max+1):
                if i+j+k == sum and i < j and j < k:
                    cnt += 1
    print(str(cnt))

Submission status: Accepted

Solution code:
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    inlist = []
    while True:
        n,k = mi()
        if n == 0 and k == 0:
            break
        inlist.append([n,k])
    for tmp in inlist:
        n = tmp[0]
        l = tmp[1]
        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 == l:
                        cnt+=1
        print(cnt)




main()

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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

while True:
    ans=0
    ni,xi=map(int,input().split())
    if ni==xi==0:
        exit()
    for a,b,c in combinations(map(int,range(1,ni+1)),3):
        if a+b+c==xi:
            ans+=1
    print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as cmb
N = []
X = []
while True:
  n, x = map(int, input().split())
  if n != 0:
    N.append(n)
    X.append(x)
  else:
    break


for n, x in zip(N, X):
  counter = 0
  for nums in cmb(list(range(1, n+1)), 3):
    if sum(nums) == x:
      counter += 1
  print(counter)

Submission status: Accepted

Solution code:
import itertools

while True:
    N,X = map(int,input().split())
    if N == 0 and X == 0:
        break
    else:
        ans = 0
        L = list(itertools.combinations([i for i in range(1,N+1)],3))

        for a,b,c in L:
            if a+b+c == X:
                ans += 1

        print(ans)

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

def main(n,x):
    ans = 0
    for m in range(2, min(n,x//2)+1):
        for s in range(1, m):
            for b in range(m+1, min(n+1,x)):
                if s+m+b == x:
                    ans+=1
          
    print(ans)          
    return
                
    return

if __name__ == '__main__':
    n,x = na()
    while n!=0 or x!= 0:
        main(n,x)
        n,x = na()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
  N,X=map(int,input().split())
  if N==0 and X==0:
    return False
  P=0
  for i in range(1,N+1):
    for j in range(1,N+1):
      for k in range(1,N+1):
        if i!=j and i!=k and j!=k:
          if i+j+k==X:
            P+=1
  print(P//6)
  return True

while solve():
  None

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
nx = []
while 1:
    i = list(map(int, input().split()))
    if i[0]==0:
        break
    nx.append(i)

for j in nx:
    ans = 0
    n,x = j[0], j[1]
    for i in combinations(range(1,n+1), 2):
         c = x - sum(i)
         if c<=0 or c>n: continue
         if c==i[0] or c==i[1]: continue
         ans += 1
    print(int(ans/3))

Submission status: Accepted

Solution code:
import itertools

if __name__ == "__main__":
    ns = []
    xs = []

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

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

        ns.append(n)
        xs.append(x)

    for n, x in zip(ns, xs):
        all_combinations = itertools.combinations(range(1, n + 1), 3)

        combinations_satisfied_sum_x = list(
            filter(lambda combination: sum(combination) == x, all_combinations)
        )

        print(len(combinations_satisfied_sum_x))

Submission status: Accepted

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

Submission status: Accepted

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

for [n,x] in A:
  c=0
  for i in range(n):
    rem = x-i-1
    for j in range(n-i):
      if j+i+3 <= rem-(j+i+2) <=n:
        c +=1
  print(c)

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

Submission status: Accepted

Solution code:
import itertools

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

    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

for i in ansary:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nx = []

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

for n, x in nx:
    ans = []
    
    for i in range(1,n+1):
        for j in range(1,n+1):
            if i == j:
                continue
            
            k = x - i -j
            
            if (not k == i) and (not k == j):
                if 1 <= k <= n:
                    ans.append([i,j,k])
    
    print(int(len(ans)/6))

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

Submission status: Accepted

Solution code:
while True:
    cnt = 0
    n,x = map(int,input().split())
    if n == x == 0:
        break
        exit()
    for i in range(101):
        for j in range(101):
            if j>=i:
               for k in range(101):
                    if k>=j:
                        if i!=j!=k and i+j+k==x and i!=0 and j!=0 and k!=0 and n>=k>j>i:
                            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):
        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:
#!/usr/bin/env python

def main():
    while True:
        n, x = list(map(int, input().split()))
        if n == 0 and x == 0:
            exit()

        else:
            ans = 0
            a = tuple(range(1, n+1))
            for idx1 in range(len(a)-1):
                target = x - a[idx1]
                idxl = idx1+1
                idxr = len(a)-1 
                while idxl < idxr:
                    if a[idxl] + a[idxr] == target:
                        ans += 1
                        idxl += 1
                        idxr -= 1
                    elif a[idxl] + a[idxr] < target:
                        idxl += 1
                    else:
                        idxr -= 1
            print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def solve(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
    return ans


def main():
    nx = map(int, read().split())

    for n, x in zip(*[iter(nx)]*2):
        if (n, x) == (0, 0):
            exit()
        print(solve(n, x))


if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
while True:
    answer = 0
    N,X = map(int, input().split())
    if N == 0 and X == 0:
        break
    num_list = list(range(1,N+1))
    for A in num_list:
        if A > X:
            break
        elif A != N and A != N - 1:
            for B in num_list[A:]:
                if A + B > X:
                    break
                elif B != N:
                    for C in num_list[B:]:
                        if A + B + C == X:
                            answer += 1
                        elif A + B + C > X:
                            break
                else:
                    break
        else:
            break
    print(answer)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    count = 0
    if n == 0 and x == 0:
        break
    for q in range(1, n + 1):
        for w in range(q + 1, n + 1):
            for r in range(w + 1, n + 1):
                total = q + w + r
                if x == total:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
import sys

from itertools import combinations


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    while True:
        n, x = map(int, input().split())
        if n == 0 and x == 0:
            break
        A = list(combinations(range(1, n + 1), 3))
        cnt = 0
        for a in A:
            if sum(a) == x:
                cnt += 1
        print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys
import random
import itertools

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))
_START_TIME = time.time()


def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():

    for i in range(300):
        c = iip()
        if c == [0, 0]:
            break

        ans = 0
        x = c[1]
        for j in range(1, c[0]):
            for k in range(j+1, c[0]):
                if j==k:
                    continue
                if j+k >= x-1:
                    continue
                if x-j-k > c[0]:
                    continue
                if k >= (x-j-k):
                    continue
                ans += 1
                #print(j, k)
        print(ans)








#####################################################ライブラリ集ここから




def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=True):  # 数字のinputをlistで受け取る
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1 and listed is False:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=True, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m

def time_debug_10percent():
    a = random.randint(0, 9)
    if a == 9:
        sys.exit()

def time_debug(t):
    time.sleep(_START_TIME + t - time.time())
    sys.exit()


def make_graph_edge_flat(N):  # グラフ作成のための辺をリストで返す
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): # 関数を二分探索
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  # リストを二分探索
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                #for i in path: # 経路圧縮
                #    self.parent[i] = cur
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
while not(a==b==0):
    ans = 0
    import itertools
    c = itertools.combinations([i for i in range(1,a+1)], 3)
    for i in c:
        if sum(i)==b: ans+=1
    print(ans)
    a,b = map(int,input().split())

Submission status: Accepted

Solution code:
import itertools
for e in iter(input, '0 0'):
    ans = 0
    # print(e.split())
    n = int(e.split()[0])
    x = int(e.split()[1])
    num = [i for i in range(1, n+1)]
    # print(num)
    for v in itertools.combinations(num, 3):
        if sum(v) == x:
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
import sys

def allsc():
    n , x = map(int,input().split())
    if x==0 and n == 0:
      sys.exit()
    ans = 0
    for i in range(1,n):
        for j in range(i+1,n+1):
            k = x - i - j
            if i < j and j < k and k <= n:
                ans += 1
    print(ans)

while True:
    allsc()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
import sys
for line in sys.stdin:
    n, x = map(int, line.split())
    if n == x == 0:
        sys.exit()

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

    print(cnt)

Submission status: Accepted

Solution code:
while True:
    n,x=input().split()
    n,x=[int(n),int(x)]
    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):
                sum=i+j+k
                if sum==x:
                    count=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
    ans = 0
    for i in range(1,n+1-2):    
        for j in range(i+1,n+1-1):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    # print("i,j,kは",i,j,k)
                    ans = ans + 1
    print(ans)
# print(n,x)

# print(n,x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

while True:
    N, X = [int(i) for i in input().split()]
    if N == 0 and X == 0:
        exit(0)
    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:

read_flag = True
while  read_flag:
    x, y = list(map(int, input().split()))
    if x == 0 and y  == 0:
        read_flag = False
        break
    ans = 0
    for i in range(1, y//3 + 1):
        for j in range(i+1, y):
            if j >= y - i -j:
                break
            if y - i - j > x:
                continue
            ans += 1
    print(ans)