Problem:


How many ways?

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

  
You should select three distinct integers from 1 to n.

  
A total sum of the three integers is x.

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

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

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

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

Constraints

  
3 ≤ n ≤ 100

  
0 ≤ x ≤ 300

Output

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

Sample Input

5 9
0 0

Sample Output

2

Note

      解説      

	


Sample input:
5 9
0 0


Sample output:
2

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())
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):
            k = x - i - j
            if k > j and k <= n:
                ans += 1
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
while 1:
    n,x = list(map(int,input().split()))
    if n == x == 0:
        break
    c = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k ==x:
                    c += 1
                    #print(i,j,k)
    print(c)

Submission status: Accepted

Solution code:
import sys
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        sys.exit()
    cnt=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            k=x-i-j
            if k > j and k <= n:
                cnt+=1
            else:
                continue
    print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations


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

Submission status: Accepted

Solution code:
import itertools


pr = []
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    count = 0
    for c in itertools.combinations(range(1, n+1), 3):
        if sum(c) == x:
            count += 1
    pr.append(count)
for e in pr:
    print(e)

Submission status: Accepted

Solution code:
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

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

inf = float("inf")

def main():
    inp = [i for i in readlines()]
    for _inp in inp:
        n, x = map(int, _inp.split())
        if n == x == 0:
            return
        else:
            count = 0
            l = [i for i in range(1, n+1)]
            for a, b, c in combinations(l, 3):
                if a + b + c == x:
                    count += 1
            print(count)
            
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,1):
        for j in range(i+1,n+1,1):
            for k in range(j+1,n+1,1):
                if i+j+k == x:
                    cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
    count = 0
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    
    li = []
    for i in range(n):
        li.append(i+1)
    
    c = combinations(li, 3)
    list_c = list(c)
    for k in list_c:
        if sum(k) == x:
            count += 1
    
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def output(n,x):
    count = 0
    for a in range(n): # a = 0,1,2,3,... n-1
        for b in range(n)[a+1:]: # b =1,2,3,... n-1
            for c in range(n)[b+1:]: # c = 2,3,4,5,...n-1
                if (a+1)+(b+1)+(c+1) == x:
                    count += 1
    return count

Data_set = []

# 入力
while True:
    n,x = input().split()
    n = int(n)
    x = int(x)
    if n == 0 and x == 0:
        break
    Data_set.append([n,x])

for a in Data_set:
    print(output(a[0],a[1]))

Submission status: Accepted

Solution code:
while True:
    N, X = list(map(int, input().split()))
    if N == 0 and X == 0:
        break
    if X < 6:
        print('0')
        continue
    total = 0
    for i in range(1, N+1, 1):
        for j in range(i+1, N+1, 1):
            for k in range(j+1, N+1, 1):
                num = i + j + k
                if num == X and i != j and j != k and k != i:
                    total += 1
    print(f"{total}")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def combination(n, x):
    count = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            if x - i - j in range(j+1, n+1):
                count += 1
    print(count)


n, x = 1, 1
while n != 0 or x != 0:
    n, x = map(int, input().split())
    if n != 0 or x != 0:
        combination(n, x)

Submission status: Accepted

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

    count = 0
    for a in range(1, n+1):
        for b in range(1, n+1):
            for c in range(1, n+1):
                if a < b < c and a + b + c == x:
                    count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
  n, x = map(int,input().split())
  cnt = 0
  s = [0] * 3
  if n == 0 and x == 0:
    break
  for i in range(1,n+1):
    s[0] = i
    for j in range(i+1,n+1):
      s[1] = j
      for m in range(j+1,n+1):
        s[2] = m
        if sum(s) == x:
          cnt += 1
  print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    #標準入力、両方0だった場合終わる
    a,b = map(int,input().split())
    if a == 0 and b == 0:break
    else:
        kei = 0
        #全パターンを試す
        for num1 in range(1,a + 1):
            for num2 in range(1,a + 1):
                for num3 in range(1,a + 1):
                    #文字がかぶっている場合を除く
                    if num1 + num2 + num3 == b:
                        if num1 == num2 or num1 == num3 or num2 == num3:pass
                        else:kei += 1
                    else:pass
        #同じ組み合わせの組が6こできるから割る6して出力
        print(int(kei / 6))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May  8 00:57:52 2020

@author: Kanaru Sato
"""
import itertools
ans = []
while True:
    n,x = list(map(int,input().split()))
    if n == 0 and x == 0:
        break
    else:
        nums = [i for i in range(1,n+1)]
        count = 0
        for combi in itertools.combinations(nums,3):
            if sum(list(combi)) == x:
                count += 1
        ans.append(count)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def check(n,x):
    ct = 0
    for n in range(1,n+1):
        for m in range(1,n):
            for o in range(1,m):
                if n+m+o == x:
                    ct+=1
    print(ct)

while True:
    n,x = map(int, input().split())
    if n==0 and x==0:
    	break
    else:
        check(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 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:
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,a):
            for c in range(1,b):
                if a + b + c == 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 a in range(1, x // 3):
        for b in range(a + 1, x):
            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
    answer = 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:
                    answer += 1
    print(answer)

Submission status: Accepted

Solution code:
while True:
	n, x = map(int, input().split())
	if n == 0 and x == 0:
		exit(0)
	cnt = 0
	for i in range(1, n - 1):
		#	print(i)
		for j in range(i + 1, n):
			#		print(' {0}'.format(j))
			if n >= x - i - j > j:
				#			print('  {0} {1} {2}'.format(i, j, x - i - j))
				cnt = cnt + 1

	print(cnt)

Submission status: Accepted

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

    if n==0 and x==0 :
        break
    else:
        count = 0
        for i in range(1,n-1):
            for j in range(i+1,n):
                if j < x-i-j <= n:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
while n!=0 or x!=0:
    icnt=0
    for i in range(1,n-1):
        for ii in range(i+1,n):
            if x-i-ii>ii and x-i-ii<=n:
#                print(x,i,ii,x-i-ii)
                icnt+=1
    print(icnt)
    n,x=map(int,input().split())

Submission status: Accepted

Solution code:
n,x= 0,0

def dfs(l: list) -> int:
    global n
    global x
    ret = 0
    if len(l) == 3:
        if sum(l) == x:
            return 1
        else:
            return 0
    s = 0
    if len(l) == 0:
        s = 1
    else:
        s = l[-1]+1
    
    for i in range(s,n+1):
        ret += dfs(l+[i])
    return ret

def main():
    global n
    global x
    while True:
        n,x = map(int,input().split())
        if n == 0:
            break
        print(dfs([]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = []
while n == [] or n[-1] != [0, 0]:
    n.append(list(map(int, input().split())))
l = len(n)
for i in range(l-1):
    ans = 0
    for j in range(1,n[i][0]-1):
        for k in range(j+1, n[i][0]):
            if n[i][1] - j - k >= k+1 and n[i][1] - j - k <= n[i][0]:
                ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

while True:
    z = []
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    for i in itertools.combinations(range(1, a + 1), 3):
        if i[0] + i[1] + i[2] == b:
            z.append(i)
    print(len(z))
    z = []

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

Submission status: Accepted

Solution code:
while True:
  n,x=list(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:
import sys
input = sys.stdin.readline


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


def readint():
    return int(input())


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


def readstrs():
    return input().split()


l = []
while True:
    nx = list(readnums())
    if nx[0] == 0 and nx[1] == 0:
        break
    else:
        l.append(nx)

for v in l:
    n, x = v[0], v[1]
    ans = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            k = x - i - j
            if k != i and k != j and k > j 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 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:
                    ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    inlis = []
    n, x = map(int,input().split())
    while n != 0 or x != 0:
        inlis.append([n,x])
        n, x = map(int,input().split())

    #print (inlis)

    ans = 0
    for nx in inlis:
        ans = 0
        n = nx[0]
        x = nx[1]
        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:
                        if i + j + k == x and i != j and j != k and k != i:
                            ans += 1
                            #print(i, j, k)
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
while True:
    a = 0
    n,x = map(int,input().split())
    if n == 0:
        exit()
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i + j + k == x:
                    a += 1
    print(a)

Submission status: Accepted

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

    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i+j+k == x:
                    cnt += 1
    
    ans.append(cnt)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ITP1_7_B - How Many Ways
import sys


def dfs(A, n, x):
    global ans
    if len(A) == 3:
        if sum(A) == x:
            ans += 1
        return

    else:
        if A:
            mini = max(A) + 1
        else:
            mini = 1

        for i in range(mini, n+1):
            B = A.copy()
            B.append(i)
            dfs(B, n, x)


while True:
    n, x = map(int, sys.stdin.readline().strip().split())
    if (n == 0) & (x == 0):
        break

    A = []
    ans = 0
    dfs(A, n, x)
    print(ans)

Submission status: Accepted

Solution code:
import itertools

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

    nums = [i+1 for i in range(n)]
    c = itertools.combinations(nums, 3)
    
    r=0
    for v in c:
      if v[0]+v[1]+v[2] == x:
        r+=1

    print(r)

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

while 1:
  s,t= map(int,input().split())
  if s+t == 0:break
  c=0
  for i in range(1,s+1):
    for j in range(i+1,s+1):
      for k in range(j+1,s+1):
        if i+j+k ==t:c+=1
  print(c)

Submission status: Accepted

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

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


def count_sum(n, x):
    cnt = 0
    for a, b, c in itertools.combinations(range(1, n + 1), 3):
        if (a + b + c) == x:
            cnt += 1

    return cnt


for n, x in zip(N, X):
    print(count_sum(n, x))

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

Submission status: Accepted

Solution code:

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

        print(count)

Submission status: Accepted

Solution code:
sum_anss = []
while True:
    n, x = map(int,input().split())
    if n==0 and x == 0:
        break
    else:
        sum_ans = 0
        for i in range(1,n+1):
            for j in range(1,i):
                for k in range(1,j):
                    if i != j and j != k and k !=i:
                        if i + j + k == x:
                            sum_ans = sum_ans + 1
        sum_anss.append(sum_ans)
for sum_a in sum_anss:
    print(sum_a)

Submission status: Accepted

Solution code:
import math
while True:
    n,x = list(map(int,input().split()))
    if n*n + x*x == 0:
        break
    count = 0
    for a in range(1,n+1):
        if a >= x - a - n:
            add = max(math.floor((x-a-0.1)/2) - a,0)
        else:
            add = max(math.floor((x-a-0.1)/2) - (x-a-n) + 1,0)
        count += add
    print(count)

Submission status: Accepted

Solution code:
from sys import stdin, exit
import itertools

if __name__ == "__main__":
  
  while True:
    cnt = 0
    N, X = [int(item) for item in input().split()]
    if N==0 and X==0:
      break
    
    for N_1 in range(1, N+1):
      for N_2 in range(N_1+1, N+1):
        N_3 = X - (N_1 + N_2)
        if 1<=N_3 and N_3<=N and N_2<N_3:
          cnt += 1
          # print(N_1, N_2, N_3)
        
    print(cnt)

Submission status: Accepted

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

  if n==0:break

  Candi = [i for i in range(1, n + 1)]
  count = 0

  for j in itertools.combinations(Candi, 3):
    if sum(list(j)) == x:
      count += 1

  print(count)

Submission status: Accepted

Solution code:
nx=[]

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

n_list = [row[0] for row in nx]
x_list = [row[1] for row in nx]

for n,x in zip(n_list,x_list):
    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 :
        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:
import itertools

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

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

    combination_list = itertools.combinations(range(1, n + 1), 3)
    combination_sum_list = [sum(list(x)) for x in combination_list]
    count = combination_sum_list.count(x)

    print(count)

Submission status: Accepted

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

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

    for nx in nx_list:
        n, x = nx
        cnt = 0

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
c = []
i = 0

while n != 0 or x != 0:
    x1, x2, x3 = 1, 2, 3
    c.append(0)

    while x1 < int(x / 3):
        while x2 != (x - 1) and x2 <= x3:
            x3 = x - x2 - x1
            if x3 > x2 and n >= x3:
                c[i] += 1
            x2 += 1
        x1 += 1
        x2 = x1 + 1

    n, x = map(int, input().split())
    i += 1

for xc in c:
    print(xc)

Submission status: Accepted

Solution code:
#n:1からnまでの数
#x:合計値

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
"""全探索：全列挙
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=ja
"""

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:

N = []
X = []
while 1:
    n,x = map(int, input().split())
    if n == 0 and x == 0:
        break
    N.append(n)
    X.append(x)

counter = [0] * len(N)
for h in range(len(N)):
    for i in range(1, N[h] + 1):
        for j in range(i, N[h] + 1):
            if j == i:
                continue
            for k in range(j, N[h] + 1):
                if k == i or k == j:
                    continue
                elif i + j + k == X[h]:
                    counter[h] += 1

    print(counter[h])

Submission status: Accepted

Solution code:
m = 0
list = []
ans = []

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

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

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

    else:
        for i in range(1,n+1):
            m = 0
            for j in range(i+1,n+1):
                if not i == j:
                    m = i + j
                    for k in range(j+1,n+1):
                        if not i == k:
                            if not j ==k:
                                if k == x-m:
                                    list.append(sorted([i,j,k]))
        ans.append(len((get_unique_list(list))))
        list =[]

[print(i) for i in ans]

Submission status: Accepted

Solution code:
while(1):
    n,x=map(int,input().split(" "))
    if(not n and not x):
        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+k==x and i!=j and j!=k and i!=k):
                    #print(i,j,k)
                    count=count+1
    print(int(count/6))

Submission status: Accepted

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

    print(cnt)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
while True:
    n, x = input().split(" ")
    n, x = int(n), int(x)
    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:
while True:
    n, x = map(int, input().split())
    if not n and not x:
        break
    count = 0
    for a in range(1, n+1):
        for b in range(1, a):
            for c in range(1, b):
                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):
    break
  ans = 0
  for i1 in range(1, n+1):
    for i2 in range(i1+1, n+1):
      for i3 in range(i2+1, n+1):
        if(i1 + i2 + i3 == x):
          ans += 1
          
  print(ans)

Submission status: Accepted

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

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