Problem:


How many ways?

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

  
You should select three distinct integers from 1 to n.

  
A total sum of the three integers is x.

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

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

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

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

Constraints

  
3 ≤ n ≤ 100

  
0 ≤ x ≤ 300

Output

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

Sample Input

5 9
0 0

Sample Output

2

Note

      解説      

	


Sample input:
5 9
0 0


Sample output:
2

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

Solution code:
for i in range(10**6):
    n,x = map(int,input().split())
    if n==0 and x==0:
        exit()
    ans=0
    for j in range(1,n+1):
        for k in range(j+1,n+1):
            if x-j-k>k and x-j-k<=n:
                ans+=1
                
    print(ans)

Submission status: Accepted

Solution code:
# ITP1_7_B.py
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):
            k = X - i - j
            if k > i and k > j and N >= k > 0:
                ans+=1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    seen = set()
    for idx1 in range(1, num+1):
        for idx2 in range(idx1+1, num+1):
            candidate = total - (idx1 + idx2)
            if 1 <= candidate <= num and idx1 != candidate and idx2 != candidate:
                combo = tuple(sorted([idx1, idx2, candidate]))
                seen.add(combo)
    print(len(seen))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

i = 0
j = 0

k = 0
l = 0
m = 0

n = 0
a = []
num = []
count = 0
check = []

while True:
    a.append(list(map(int, input().split())))
    if a[n][0] == 0 and a[n][1] == 0:
        break
    n += 1

while i < n:
    count = 0
    check.append(0)
    num = []
    j = 0
    while True:
        count += 1
        num.append(count)
        if count == a[i][0]:
            break
    
    for j in range(len(num)):
        if j + 2 > len(num):
            break

        for k in range(j + 1, len(num)):

            for l in range(k + 1, len(num)):
                if num[j] + num[k] + num[l] == a[i][1]:
                    check[i] += 1
    i += 1

i = 0
while i < n:
    print("%s" % check[i])
    i += 1

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+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
    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=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(i+1,n):
        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:
        break
    else:
        combinations = 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:
                        combinations += 1
        print(combinations)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    count=0
    n,x=map(int,input().split())
    if n==x==0:
        break
    else:
        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=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(i+1,n):
         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:
        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):
                    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:
        break
    else:
        count=0
        #range(1,n)は、1からn-1までを意味する（eg.range(2,n)=2,3,4...n-1)
        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=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(i+1,n):
                for k in range(j+1,n+1):
                    if i+j+k==x:
                        s=s+1
        print(s)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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
    for comb in combinations(range(1, n+1), 3):
        if sum(comb) == x:
            cnt += 1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
while True:
    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==x==0:
    break
  else:
    N=[]
    for n_1 in range(1,x//3+1):
      z=x-n_1
      for n_2 in range(n_1,n):
        n_3=z-n_2
        if n>=n_3 >n_2>n_1:
          N.append(n_3)
    print(len(N))

Submission status: Accepted

Solution code:
import itertools
lis_num =[]



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

    lis = list(range(1, n + 1))
    

    for i in itertools.combinations(lis, 3) :
        if sum(i) == x :
            count += 1
            
    
    print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, x = [int(line) for line in input().split()]
    if n == 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):
                # print(i, j, k)
                if i != j and j != k and i != k:
                    if i + j + k == x:
                        count += 1
    print(count)

Submission status: Accepted

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

while(True):
  n, x = map(int, input().split())
  if (n==0)and(x==0):
    break
  count=0
  
  h=[ int(i+1) for i in range(n)]
  lh = list(itertools.combinations(h, 3))
  
  for i in lh:
    if (i[0]+i[1]+i[2]) == x:
      count += 1
  print(count)

Submission status: Accepted

Solution code:
while True:
    num,sums = map(int, input().split())
    if num == 0 and sums == 0:
        break
    count = 0
    for x in range(1, num + 1):
        for y in range(x + 1, num + 1):
            for z in range(y + 1, num + 1):
                if x + y + z == sums:
                    count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

for o in output:
    print(o)

Submission status: Accepted

Solution code:
def isEnd(list):
    if (list[0]==0) and (list[1]==0):
        return True
    return False

def answer(list):
    kumi = 0
    if list[1] < 6:
        return kumi
    for i in range(1, list[1]+1):
        for j in range(i+1, list[1]+1):
            another = list[1]-i-j
            if (another > j) and(another <= list[0]):
                kumi += 1
    return kumi

flag = True
a = []

while flag:
    t = list(map(int, input().split()))
    if isEnd(t):
        flag = False
        continue
    a.append(t)

for i in a:
    ans = answer(i)
    print(ans)

Submission status: Accepted

Solution code:
import itertools
while True:
  n, x = map(int, input().split())
  if n == x == 0:
    break
  else:
    list_com = list(itertools.combinations(range(1, n+1), 3))
    list_cnt = []
    for i in range(len(list_com)):
      if sum(list_com[i]) == x:
        list_cnt.append(list_com[i])
      else:
        continue
  print(len(list_cnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    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 & x == 0:
        break
    
    counter = 0
    for i in range(n):
        num1 = i + 1
        for j in range(n - num1):
            num2 = j + 1 + num1
            for k in range(n - num2):
                num3 = k + 1 + num2
                # print(num1, num2, num3)
                total = sum([num1, num2, num3])
                if total == x:
                    # print(" -> OK")
                    counter += 1
                    
    print(counter)

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 1 How many ways?

import itertools

n_list = []
x_list = []
while True:
    _n, _x = map(int, input().split())
    if _n == 0 and _x == 0:
        break
    n_list.append(_n)
    x_list.append(_x)

l = len(n_list)

for i in range(l):
    ans = 0
    n = n_list[i]
    x = x_list[i]
    for v in itertools.combinations(range(1,n+1), 3):
        if sum(list(v)) == x:
            ans += 1
    print(ans)

Submission status: Accepted

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

    i = 1
    s = 0
    while i < n+1:
        j = 2
        while j < n+1:
            k = 3
            while k < n+1:
                if i < j < k:
                    #print('*', i, j, k) 
                    if i + j + k == x:
                        s = s + 1
                k = k + 1
            j = j + 1
        i = i + 1
    print(int(s))

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
  n,m = map(int,input().split())
  if n==m==0: exit()

  res = 0
  for x,y,z in list(combinations(range(1,n+1), 3)):
    if x+y+z == m: res += 1

  print(res)

Submission status: Accepted

Solution code:
li = []

while True:
    i,j = map(int,input().split())
    if i == 0 and j == 0:
        break
    li.append((i,j))

for l,m in li:
    point = 0
    for i in range(1,l-1):
        for j in range(i+1,l):
            for k in range(j+1,l+1):
                if i+j+k == m:
                    point += 1
    print(point)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

while True:
    num,ans = [int(x) for x in input().split()]
    i = 1
    j = 1
    k = 1
    count = 0
    if  (num,ans)==(0,0): 
        break
    for i in range(1,num-1):
        for j in range(i + 1, num):
            for k in range(j + 1,num + 1):
                if i + j + k == ans:
                    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):
            for c in range(b+1,n+1):
                if a+b+c==x: ans+=1
    print(ans)

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

        print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ITP1_7_B - How Many Ways?
ns = []
xs = []
while True:
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    ns.append(n)
    xs.append(x)
ans = []
for i in range(len(ns)):
    tmp = 0
    for a in range(1,ns[i]+1):
        for b in range(a,ns[i]+1):
            for c in range(b,ns[i]+1):
                if a+b+c == xs[i]:
                    if a!=b and b!=c and c!= a:
                        tmp += 1
    ans.append(tmp)
print(*ans,sep="\n")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import operator
import functools

EOL = '0 0'

for line in iter(input, EOL):
    n, x = map(int, line.split())
    combinations = list(itertools.combinations(list(range(1, n + 1)), 3))
    print(len(list(filter(functools.partial(operator.eq, x), map(sum, combinations)))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
table = []

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

for i in range(len(table)):
    ans = 0
    for j in range( 1, table[i][0] + 1):
        for k in range(j + 1, table[i][0] + 1):
            for l in range(k + 1, table[i][0] + 1):
                if j + k + l == table[i][1]:
                    ans += 1
                    #print("{}+{}+{}".format(j, k, l))
    print(ans)

Submission status: Accepted

Solution code:
import math
l=[]
while True:
  n,x=map(int,input().split())
  if (n,x)==(0,0):
    break
  l.append((n,x))
for (n,x) in l:
  ans=0
  a_min=int(math.ceil(x/3))+1
  for a in range(n,a_min-1,-1):
    b_min=((x-a)//2)+1
    for b in range(a-1,b_min-1,-1):
      if x-a-b<=0:
        continue
      ans+=1
  print(ans)

Submission status: Accepted

Solution code:
import itertools
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
        y=[]
        l=list(range(1,n+1))
        for team in itertools.combinations(l,3):
            s=sum(team)
            y.append(s)
        print(y.count(x))

Submission status: Accepted

Solution code:
while True:
  n, x = map(int, input().split())
  if n == 0 and x == 0:
    break
  else:
    print(sum([sum([i, j, k]) == x - 3 for i in range(n) for j in range(i) for k in range(j)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
for _ in range(10000):
    n, x = map(int, input().split())

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

    ans = 0

    for num1 in range(1, n + 1):
        if num1 * 3 >= x:
            break

        for num2 in range(num1 + 1, n + 1):
            num3 = x - num1 - num2
            if num2 >= num3:
                break
            if (num3) <= n:
                if num1 != num3 and num2 != num3:
                    ans += 1
    print(ans)