Problem:


How many ways?

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

  
You should select three distinct integers from 1 to n.

  
A total sum of the three integers is x.

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

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

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

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

Constraints

  
3 ≤ n ≤ 100

  
0 ≤ x ≤ 300

Output

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

Sample Input

5 9
0 0

Sample Output

2

Note

      解説      

	


Sample input:
5 9
0 0


Sample output:
2

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():
    A = []

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

if __name__ == '__main__':
    main()

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(1, n + 1):
    for j in range(1, i):
      for k in range(1, j):
        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,n+1):
    for b in range(1,n+1):
      if b <= a:
          continue
      c = x-(a+b)
      if c >b and c <=n:
         ans +=1
  print('%d'%(ans))

Submission status: Accepted

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    while 1:
        a,b=map(int,input().split())
        if a==b==0:
            break
        print(sum(sum(i)==b for i in combinations(range(1,a+1),3)))
    
    
    
    

if __name__ == '__main__':
    main()

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, n + 1):
            
            if i <= j:
                break

            for k in range(1, n + 1):
                
                if j <= k:
                    break
                
                if i + j + k == x:
                    cnt += 1
    
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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, n + 1):
            if a == b:
                continue
            for c in range(b, n + 1):
                if a == c or b == c:
                    continue
                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
 else :
   s = 0
   for i in range(1, n + 1) :
     for j in range(1, i) :
       for k in range(1, j) :
         if(i + j + k == x) :
           s += 1
         else :
           pass
   print(s)

Submission status: Accepted

Solution code:
NX = []
NX_hairetsu = []
while True:
    n, x = [int(e) for e in input().split()]
    if n==0 and x==0:
        break
    else:
        NX = [n, x]
        NX_hairetsu.append(NX)
        
for i in range(len(NX_hairetsu)):
    count = 0
    N = [e for e in range(1, NX_hairetsu[i][0]+1)]
    for a in range(len(N)-2):
        for b in range(a+1, len(N)-1):
            for c in range(b+1, len(N)):
                if N[a]+N[b]+N[c]==NX_hairetsu[i][1]:
                    count += 1
    print(count)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

while True:
    n, x = [int(e) for e in input(). split()]

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

    for i, j, k in itertools.combinations(range(1, n + 1), 3):
        if i + j + k == x:
            a = a + 1
    
    print("%d" % (a))

Submission status: Accepted

Solution code:
while True:
    n,x=[int(e) for e 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):
            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 = [int(e) for e in input().split()]
    if n == 0 and x == 0:
        break
    
    can_list = itertools.combinations(range(1, n + 1), 3)
    
    answer_list = [can for can in can_list if sum(can) == x]
    
    print(len(answer_list))

Submission status: Accepted

Solution code:
import itertools

while True:
    str = input().split()
    n, x = int(str[0]), int(str[1])
    if n == 0 and x == 0:
        break
    
    numbers_comb = itertools.combinations(range(1, n + 1), 3)
    answers = [comb for comb in numbers_comb if comb[0] + comb[1] + comb[2] == x]
    print(len(answers))

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:
while True:

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

    if x + y == 0:
        break

    if x - 3 > y:
        x = y - 3

    count = 0
    for i in range(x, 2, -1):
        for j in range(2, i, 1):
            for k in range(1, j, 1):
                if (i + j + k) == y:
                    count += 1

    print(count)

Submission status: Accepted

Solution code:
combination=list()
counter=0
garbage=0
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        for i in range(len(combination)):
            print(combination[i])
        break
    else:
        for i in range(1,n+1):
            for j in range(1,n+1):
                for k in range(1,n+1):
                    if i+j+k==x:
                        if i>=j or j>=k or i>=k:
                            garbage+=1
                        else:
                            counter+=1
        combination.append(counter)
        counter=0

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

Submission status: Accepted

Solution code:
def three_nums(n, x):
    res = 0
    if (x <= 5):
        return 0
    if ((0.5 * n * (n+1)) < x):
        return 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):
                    res += 1
    return res

if __name__ == "__main__":
    while True:
        n, x = map(int, input().split())
        if n == x == 0:
            break
        print(three_nums(n, x))

Submission status: Accepted

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

    print(count)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	n,x = map(int, input().split())
	while n + x != 0:
		num = list(range(1,n+1))
		c = 0
		for i in range(n):
			for j in range(i+1,n):
				for k in range(j+1,n):
					if num[i]+num[j]+num[k] == x:
						c += 1
		print(c)
		n,x = map(int, input().split())

Submission status: Accepted

Solution code:
import itertools

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

    # set number list
    n_list = [i for i in range(1,n+1)]
    
    # compute combination
    c_list = list(itertools.combinations(n_list, 3))
    
    # initialize count
    count = 0
    
    # count total
    for each_c in c_list:
        if sum(each_c) == x:
            count+=1
    
    # output
    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:
while True:
    n,x=map(int,input().split())
    if n == 0 and x == 0:
        break
    count=0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i+j+k+3 == x:
                    if i < j and j < k:
                        count += 1
    print("%d"%(count))

Submission status: Accepted

Solution code:
import itertools

switch = 0

while(switch == 0):
    count = 0
    arr = []
    n = 0
    
    nx = list(map(int, input().split(' ')))
    
    if nx[0] == nx[1] == 0:
        break
    
    for i in range(nx[0] + 1):
        arr.append(i)
        n += 1
        
    numbers = list(itertools.combinations(arr[1:], 3))

    for i in range(len(numbers)):
        if int(numbers[i][0]) + int(numbers[i][1]) + int(numbers[i][2]) == nx[1]:
            count = count + 1
            
    print(count)

Submission status: Accepted

Solution code:
while 1:
	n,x=map(int,input().split())
	if n==x==0:break
	print(sum(min((x-a-1)//2,n-1)-max(a,x-a-n-1)for a in range(max(1,x-2*n),min(x//3,n-1))))

Submission status: Accepted

Solution code:

while True:
    y = input()
    list = y.split()
    [n, x] = list
    n = int(n)
    x = int(x)
    nx = n + x
    
    #終了条件を記載
    if nx ==  0:
        break
    
    #比較する数字3つはa,b,cとする
    #最終的にa,b,cの合計がxになった場合にansカウントを1増やす
    
    ans = 0
    N = n + 1
    
    #最初の数aを抽出
    for a in range(1,N):
        #次の数値bを抽出
        for b in range(a + 1,N):
            #aとbが一緒であればスキップする処理
            if a == b:
                continue
            #最後の数値cを抽出
            for c in range(b + 1,N):
                #a=cまたはb=cならforを抜ける処理
                if a == b or b == c:
                    continue
                
                #計算をする
                abc = a + b + c
                if abc == x:
                    ans = ans + 1
                
    print(ans)

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
while nums != [0,0]:
    count = 0
    for n3 in range(3, nums[0]+1):
        for n2 in range(2, n3):
            for n1 in range(1, n2):
                if n1+n2+n3 == nums[1]:
                    count += 1
    print(count)
    nums = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N, X = [], []


def set_inputs():
    global N, X
    while True:
        n, x = get_li()
        if n == x == 0:
            break
        N.append(n)
        X.append(x)
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    for n, x in zip(N, X):
        s = set()
        for i in range(1, min(n + 1, x - 1)):
            for j in range(1, min(n + 1, x - i)):
                k = x - i - j
                if i == j or j == k or k == i or k < 1 or n < k:
                    continue
                a, b, c = sorted([i, j, k])
                s.add((a, b, c))
        print(len(s))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def getN():
    return int(input())

def getlist():
    return list(map(int, input().split()))

def solve(n,x):
    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 and i != j and i != k:
                    cnt += 1

    return cnt

while(True):
    n,x = getlist()
    if n == 0 and x == 0:
        break
    else:
        print(solve(n,x))

Submission status: Accepted

Solution code:
#  combination tst 
import itertools
sentinel = [0, 0]

flag = True
while flag == True:

    basic_info = [int(i) for i in input().split()]
    if basic_info == sentinel:
        flag == False
        break
    n = basic_info[0]
    x = basic_info[1]

    numbers = [i+1 for i in range(n)]
    # print(numbers)
    cnt = 0
    combi_nums = itertools.combinations(numbers, 3)
    for c in combi_nums:
        if sum(c) == 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):
        for j in range(1,i):
            for k in range(1,j):
                if i + j + k == x:
                    ans += 1
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#     if n == 0 and x == 0:
#         break
#     else:
#         for i in range(n):
#             for j in range(n):
#                 if i == j:
#                     continue
#                 else:
#                     for k in range(n):
#                         if i == j and j == k:
#                             continue
#                         else:
#                             if i + j + k == x:
#                                 cnt += 1

#     print("{}".format(cnt))


# 間違い
# square1001の回答が一番近い
# 範囲をめっちゃ間違えてた

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

    if n == 0 and x == 0:
        break
    else:
        for i in range(1, n + 1):
            for j in range(1, i):
                for k in range(1, j):
                    if i + j + k == x:
                        cnt += 1
    print("{}".format(cnt))

Submission status: Accepted

Solution code:
n = []
x = []

while True:
    n1,x1, = map(int,input().split())
    if (n1 == 0)*(x1 == 0) :
        break
    n.append(int(n1))
    x.append(int(x1))

s = []
comb = 0
for u in range(len(n)):
    for i in range(1,n[u]+1):
        for j in range(i,n[u]+1):
            for k in range(j,n[u]+1):
                if (i != j)*(j != k)*(k!=i)*(x[u]==i+j+k):
                    s1 = [i,j,k]
                    s1.sort()
                    if s1 not in s:
                        s.append(s1)
    print(len(s))
    s = []

Submission status: Accepted

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

Submission status: Accepted

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


while True:
    nx = input().split()
    n = int(nx[0])
    x = int(nx[1])

    if n == 0 and x == 0:
        break
    else:
        print(combination(n, x))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n_x = input()
    n_x_list = n_x.split(" ")
    n_int = int(n_x_list[0])
    x_int = int(n_x_list[1])
    if n_int == 0 and x_int == 0:
        break
    ans = 0
    fir = 1
    sec = 2
    thi = 3
    while True:
        if thi > n_int:
            break
        if fir + sec + thi == x_int:
            ans += 1
        if sec == n_int - 1:
            fir += 1
            sec = fir + 1
            thi = fir + 2
        elif thi == n_int:
            sec += 1
            thi = sec + 1
        else:
            thi += 1
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
while True:
    line = input().split()
    n = int(line[0])
    x = int(line[1])
    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:
from itertools import combinations



while True:
    n, t = map(int, input().split())
    if n+t:
        count = 0
        for c in combinations(range(1, n+1), 3):
            if sum(c) == t:
                count += 1
        print(count)
    else:
        break

Submission status: Accepted

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

    ans = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            tmp = x - a - b
            if b < tmp and tmp <= n:
                ans += 1

    print(ans)

Submission status: Accepted

Solution code:
while True:
    a, b = list(map(int, input().split()))
    if a == 0 & b == 0:
        break
    ans = 0
    for i in range(1, a + 1):
        for j in range(1, i):
            for n in range(1, j):
                if i + j + n == b:
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    a=input()
    b=a.split()
    n=int(b[0])
    x=int(b[1])
    if n==0 and x==0:
        break
    count=0
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if i>=j or j>=k or i>=k:
                    pass
                elif i+j+k==x:
                    count+=1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    N,X = map(int,input().split())
    if N==0 and X==0:
        break
    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:
def cycle(n, x, c):
    if c == 0:
        return 1 if n >= x >= 1 else 0
    a = 0
    for i in range(min(n, x - c), c - 1, -1):
        a += 0 if c == 1 and i == x - i else cycle(i - 1, x - i, 1 if c == 3 else 0)
    return a

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if 0 == n == x: break
    count = 0
    a_max = min(n, x - 3)
    for a in range(a_max, a_max // 3, -1):
        b_max = min(a - 1, x - a - 1)
        for b in range(b_max, b_max // 3, -1):
            if x - a - b >= b: break
            count += 1
    print(count)

Submission status: Accepted

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