Problem:


How many ways?

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

  
You should select three distinct integers from 1 to n.

  
A total sum of the three integers is x.

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

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

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

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

Constraints

  
3 ≤ n ≤ 100

  
0 ≤ x ≤ 300

Output

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

Sample Input

5 9
0 0

Sample Output

2

Note

      解説      

	


Sample input:
5 9
0 0


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

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

def dfs(i, sum, t):
    if t == 0:
        if sum == x:
            return 1
        else:
            return 0
    else:
        if sum >= x:
            return 0
        elif i == 0:
            return 0
        else:
            return dfs(i - 1, sum + i - 1, t - 1) + dfs(i - 1, sum, t)

while n != 0 or x != 0:
    c = dfs(n + 1, 0, 3)
    print(c)
    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
 
    print(sum( [ max(min(n,(x-i+1)//2) - max(i+1,x-i-n),0) for i in range(1,x//3) ]))

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    return cnt

def ansOutPut(ans, ansnum):
    for i in range(ansnum):
        print(ans[i])

N, X = map(int, input().split())
ans = []
while(N != 0 or X != 0 ):
    ans.append(checkConnum(N,X))
    N, X = map(int, input().split())

ansOutPut(ans, len(ans))

Submission status: Accepted

Solution code:
lst = []
while True:
    a = list(map(int, input().split()))
    if a[0] == a[1] == 0:
        break
    else:
        lst.append(a)
for nx in lst:
    con = 0
    for i in range(1, nx[0]-1):
        for j in range(i+1, nx[0]):
            for k in range(j+1, nx[0]+1):
                if i + j + k == nx[1]:
                    con += 1
    print(con)

Submission status: Accepted

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

    print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import itertools

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

Submission status: Accepted

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

    ans = 0
    for i in range(1, x+1):
        for j in range(i+1, x+1):

            c = y - (i+j)

            if c > j and c <= x:
                ans += 1

    print("%d"%(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    count = 0
    for x1 in range(1, n + 1):
        for x2 in range(x1 + 1, n + 1):
            for x3 in range(x2 + 1, n + 1):
                if x1 + x2 + x3 == x:
                    count += 1
    print(count)

Submission status: Accepted

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

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):
            c = x - a - b
            if b < c <= 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

    ans = 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:
                    ans +=1
                    
    print(ans)

Submission status: Accepted

Solution code:
while(True):
    count = 0
    sc = input().split()
    n = int(sc[0])
    x = int(sc[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:
    m,n=map(int,input().split())
    if m==n==0:
        break
    else:
        ans=0
        for a in range(1,m+1):
            for b in range(1,a):
                for c in range(1,b):
                    if a+b+c==n:
                        ans+=1
        print(ans)

Submission status: Accepted

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

while(1):
    n,x = li()
    if(n == 0 & x == 0):
        break

    if(x == 0):
        print(0)
        continue

    dp = [[0] * (x+1) for i in range(4)]
    dp [1][1] = 1
    dp[0][0]=1

    for i in range(2,n+1):
        for j in range(x,0,-1):
            for k in range(3,0,-1):
                # print(i,j,k)
                #i個目でi+1以上いれた時の話をしてるとpass
                if(i<k):
                    # print('pass')
                    pass

                # 選んだ選択肢 + 選ばなかった選択肢
                else:
                    if(j-i  >=  0):
                        dp[k][j] =   dp[k][j] + dp[k-1][j-i]

    print(dp[3][x])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from itertools import combinations as c
    while True:
        n,x=map(int,input().split())
        if n==0 and x==0:
           break
        else:
            cnt=0
            for s in c(range(1,n+1),3):
                if sum(s)==x:
                    cnt+=1
            print(cnt)
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def pattern(n,x):
    ans=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            k = x - i - j
            if i + j + k == x and max(i,j) < k <= n:
                ans += 1
                #print(i,j,k)
    return ans
Flg=True
while Flg:
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    else:
        print(pattern(n,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 k in range(i + 1, n):
            if k < x - (i + k) <= n:
                count += 1
    print(count)

Submission status: Accepted

Solution code:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

while 1:
    m, f = map(int, readline().split())
    if m == 0 and f == 0:
        break
    ans = 0
    A = [(i, j, k) for i, j, k in list(itertools.combinations(range(1, m + 1), 3)) if i + j + k == f]
    print(len(A))

Submission status: Accepted

Solution code:
while True:
    n, x = map(lambda a: int(a), input().split(" "))
    if (n, x) == (0, 0):
        break
    if x < 1 + 2 + 3 or x > n + (n - 1) + (n - 2):
        print(0)
        continue
    values = list(range(1, n + 1 if n - 3 <= x else x + 1))
    N = len(values)
    count = 0
    for i1 in range(N - 2):
        for i2 in range(i1 + 1, N - 1):
            for i3 in range(i2 + 1, N):
                if values[i1] + values[i2] + values[i3] == x:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
c = []
while True:
    n, x = [int(i) for i in input().split()]
    if n == 0 and x == 0:
        break
    else:
        b = {}
        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:
                        break
                    elif i + j + k == x:
                        c = [i,j,k]
                        b[" ".join(map(str, sorted(c)))] = i + j + k
    print(len(b))

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

Solution code:

while(True):
    n, x = map(int, input().split())
    if n == 0 and x == 0: break
    ans = 0
    for i in range(1, n-1):
        for j in range(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:
s=[]
while True:
    l=list(map(int,input().split()))
    if l==[0,0]:
        break
    s.append(l)
#print(s)
for i in range(len(s)):
    cnt=0
    for j in range(1,s[i][0]+1):
        #l_2=list(range(1,s[i][0]+1))
        #print(l_2)
        for k in range(1,s[i][0]+1):
            for m in range(1,s[i][0]+1):
                if j<k and k<m:
                    if k+m+j==s[i][1]:
                        cnt+=1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

def twoSum(tup):
    count = []
    can = list(range(1,tup[0]+1))
    for i in combinations(can,3):
        if sum(i) == tup[1]:
            count.append(i)
    return len(count)

for tup in candidates:
    print(twoSum(tup))

Submission status: Accepted

Solution code:
while(True):
    d_set = input()
    d_set = d_set.split()
    n,x = int(d_set[0]),int(d_set[1])
    if n == 0 and x == 0:
        break
    c_set = list(range(1,min(n+1,x+1-3)))
    cnt = 0
    for i in range(len(c_set)):
        c1_set = c_set[i+1:]
        for j in range(len(c1_set)):
            c2_set = c1_set[j+1:]
            for k in range(len(c2_set)):
                if c_set[i] +c1_set[j] + c2_set[k] == x:
                    cnt += 1

    else:
        print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

    if n == 0 and x == 0:
        break
    
    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 solve(N, X):
    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
    return ans


while True:
    N, X = tuple(map(int, input().split()))
    if N == 0 and X == 0:
        break
    print(solve(N, X))

Submission status: Accepted

Solution code:
def cal_comb_num(n, x):
    sum = 0
    pairs = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            sum = x - i - j
            if j < sum <= n:
                pairs += 1
    print(pairs)

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

Submission status: Accepted

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

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

    print(count)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    while True:
        N, X = MI()

        if N == 0 and X == 0:
            return

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

def comb(L,num):
    return list(combinations(L,num))

while True:
    n,x = map(int,input().split())
    if n==0 and x==0:
        exit()
    
    n_L = range(1,n+1)
    ans = 0
    for i in comb(n_L,3):
        if sum(i) == x:
            ans += 1
    
    print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

for q in range(10 ** 9):
    n, x = map(int, input().split())
    if n == x == 0:
        break
    ans = 0
    for i in range(1, n + 1):
        for l in range(i + 1, n + 1):
            for k in range(l + 1, n + 1):
                if i + l + k == x:
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
ans = []

while True:
    n, x = [int(x) for x in input().split()]
    if n == 0 and 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):
                s += (i + j + k == x)
    ans.append(s)

for s in ans:
    print(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(1, n+1):
            tmp = x-(i+j)
            if i+j+tmp == x and 1 <= tmp <= n:
                if i != j and i != tmp and j != tmp:
                    ans += 1
    print(ans//6)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def combination(n, x):
    ans = []
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            k = x - i - j
            if i != j and j != k and i != k and 0 < k <= n:
                ans.append(sorted([i, j, k]))
    ans.sort()
    ans = list(map(list, set(map(tuple, ans))))
    print(len(ans))

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

Submission status: Accepted

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

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

    ans = 0
    for 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:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=ja

def solve(n, x):
    count = 0
    for largest in range(1, n+1):
        for middle in range(1, largest):
            for smallest in range(1, middle):
                if largest+middle+smallest == x:
                    count += 1
    return count

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

Submission status: Accepted

Solution code:

nums = []
sum_nums = []
counts = []
while True:
    n, x = input().split(" ")
    n, x = int(n), int(x)
    if n == 0 and x == 0:
        break
    else:
        nums.append(n + 1)
        sum_nums.append(x)

for num, sum_num in zip(nums, sum_nums):
    count = 0
    for i in range(1, num):
        for j in range(i + 1, num):
            for k in range(j + 1, num):
                if (i + j + k) == sum_num:
                    count += 1
    counts.append(count)
for i, num in enumerate(counts):
    print(str(num))

Submission status: Accepted

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

while n != 0 or x != 0:
    ans = 0
    for c in itertools.combinations(list(range(1, n+1)), 3):
        if sum(c) == x:
            ans += 1

    print(ans)

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

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(1, n+1):
            if i!=j and i!=x-i-j and j!=x-i-j and 0<x-i-j<=n:
                ans+=1
    print(ans//6)

Submission status: Accepted

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

    print(c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

nx=[-1,-1]
while 1:
    ans=0
    nx=list(map(int,input().split()))
    testlst=[i for i in range(1,nx[0]+1)]
    lst=list(combinations(testlst, 3))
    if nx==[0,0]:
        break
    # print(lst)
    for i in range(len(lst)):
        if sum(lst[i])==nx[1]:
            ans+=1
    print(ans)

Submission status: Accepted

Solution code:
q=[]
qqq=0
while(True):
    x,y = map(int, input().split())
    if(x==0 and y == 0):
        break
    q.append(0)
    for a in range(x):
        for b in range(x-a-1):
            for c in range(x-a-b-2):
                if(a + 1 + a + b + 2 + a+ b+c +3 == y):
                    q[qqq]+=1
    qqq+=1
for ww in q:
    print(ww)

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

Submission status: Accepted

Solution code:
def solve(n,x):
	out = 0
	for i in range(1,n-1):
		for j in range(i+1, n):
			for k in range(j+1,n+1):
				if i+j+k == x:
					out += 1

	return out

ans = []
while True:
	N, X = map(int,input().split())
	if N == 0 and X == 0:
		break

	ans.append(solve(N,X))

for a in ans:
	print(a)

Submission status: Accepted

Solution code:
nx = []
while True:
    nx.append([int(i) for  i in input().split(" ")])
    if nx[-1] == [0, 0]:
        nx.pop()
        break

for c in range(len(nx)):
    count = 0
    for i in range(1, nx[c][0]+1):
        for j in range(i+1, nx[c][0]+1, 1):
            for k in range(j+1, nx[c][0]+1, 1):
                if i + j + k == nx[c][1]:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
n, x = 0, 0
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 == x == 0:
        exit(0)
    ans = 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:
                    ans += 1
    print(ans)

Submission status: Accepted

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

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 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
                    break
    
    print(count)

Submission status: Accepted

Solution code:
def comb(n,x):
    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
    return ans

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

Submission status: Accepted

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

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 itertools

answer = []

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

    target = [i for i in range(1, n + 1)]
    combi = list(itertools.combinations(target, 3))
    count = 0
    for i in range(len(combi)):
        if sum(combi[i]) == x:
            count += 1
    
    answer.append(count)

[print(answer[i]) for i in range(len(answer))]

Submission status: Accepted

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

Submission status: Accepted

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