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 itertools
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
         s=list(range(1,n+1))
         l=list(itertools.combinations(s,3))
         c=0
         for i in l:
              if sum(i) == x:
                   c+=1
         print(c)

Submission status: Accepted

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

Submission status: Accepted

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

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

    result = 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:
                    result += 1

    print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
c = 1
Answer = []

while c > 0:
    inp = input().split()
    n = int(inp[0])
    x = int(inp[1])
    c = n**2+x**2
    if c == 0:
        break

    flg = 0
    for i in range(1,min(int(x/3),n-1)):
        for j in range(i+1,min(int(x/2),n)):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    flg += 1
    Answer.append(flg)

for l in range(0,len(Answer)):
    print(Answer[l])

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if (n, x) == (0, 0):
        break
    ways = {tuple(sorted([a, b, c])) for a in range(1, n+1) for b in range(1, n+1) for c in range(1, n+1) if sum((a, b, c)) == x and len({a, b, c}) == 3}
    print(len(ways))

Submission status: Accepted

Solution code:
# (c) midandfeed
while(1):
	n, x = [int(x) for x in input().split()]
	c = 0
	if ( (n==0) and (x==0) ):
		break
	while(n > 0):
		for i in range(1, n):
			for j in range(i+1, n):
				if (i+j+n == x):
					c += 1
		n -= 1
	print(c)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations

while True:
    c, n = map(int, raw_input().split())
    if c == n == 0:
        break

    # sum(cC3) == 9
    count = 0
    for i in combinations(range(1, c + 1),3):
        if sum(i) == n:
            count += 1
    print count

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    for line in sys.stdin:
        n, x = map(int, line.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)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
while True:
	numbers = map(int, raw_input().split())
	max_ = numbers[0]
	goal = numbers[1]
	cnt = 0
	if max_ == 0 and goal == 0:
		break
	else:
		i = max_
		while 3 * i - 3 >= goal:
			j = i-1
			while goal - i - j < j:
				if goal - i - j > 0:
					cnt += 1
				j -= 1
			i -= 1
	print cnt

Submission status: Accepted

Solution code:
import itertools

def main():

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

    for [n, x] in data:
        _list = list(range(1, n+1))
        comb = set(itertools.combinations(_list, 3))
        print(sum((True if sum(i) == x else False) for i in comb))


main()

Submission status: Accepted

Solution code:
import itertools

def main():

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

    for [n, x] in data:
        _set = set(range(1, n+1))
        comb = set(itertools.combinations(_set, 3))
        print(sum((True if sum(i) == x else False) for i in comb))


main()

Submission status: Accepted

Solution code:
import math
while True:
    n,x=list(map(int,input().split()))
    if n==x==0: break
    c=0
    for i in range(1,x//3):
        if i>n: break
        for j in range(i+1,(x-i)//2+1):
            if j>n: break
            k=x-i-j
            if not (n<k or k<=j):
                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, int(x/3)+2):
        for j in range(i+1, int(x/2)+2):
            k = x - i - j
            if k <= j:
                break
            elif k <= n:
                c += 1
    print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp

"""
import sys
from sys import stdin
from itertools import combinations
input = stdin.readline


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

        ans = 0
        for c in combinations(range(1, n+1), 3):
            if sum(c) == x:
                ans += 1

        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# -*-coding:utf-8

def main():

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

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

        print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=[]
w=""
while(w!="0 0"):
    w=input()
    a.append(w)
a.pop()
for st in a:
    s=st.split()
    n=int(s[0])
    x=int(s[1])
    count=0
    for a in range(1,x//3+1):
        for b in range(a+1,(x-a)//2+1):
            if (x-a-b)<=n and b<(x-a-b):
                count+=1
    print("{0}".format(count))

Submission status: Accepted

Solution code:
from itertools import combinations


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

        ans = 0
        for nums in combinations(range(1, n + 1), 3):
            if x == sum(nums):
                ans += 1

        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
    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):
            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
 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 itertools

while True:
    n,x = [int(i) for i in input().split()]
    if not(n or x):
        break
    s = list(itertools.combinations(list(range(1,n+1)), 3))
    c = 0
    for i in s:
        if sum(i) == x:
            c += 1
    print(c)

Submission status: Accepted

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

Submission status: Accepted

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

    count = 0
    
    for i in range(1,n):
        for j in range(i+1,n):
            if (x - i - j) <= n and (x - i - j) > j:
                
                count = count + 1
                
    print('{}'.format(count))

Submission status: Accepted

Solution code:
while 1:
	n, x = map(int, raw_input().split())
	if n == 0 and x == 0:
		break
	a = [int(m) for m in range(1, n+1)]
	N = 0
	for k in range(2, n):
		for j in range(1, k):
			for i in range(j):
				if a[i]+a[j]+a[k] == x:
					N += 1
				else:
					pass
	print N

Submission status: Accepted

Solution code:
def find_ways(n, x):
    number_list = [i+1 for i in range(n)]
    cnt = 0
    for j in number_list:
        if j > n-2:
            break
        for k in number_list:
            if k <= j:
                continue
            l = x - j - k
            if l > n or l <= k:
                continue
            else:
                cnt += 1
    return cnt
 
while True:
    data = list(map(int, list(input().split())))
    if data[0] == 0 and data[1] == 0:
        break
    else:
        comb = find_ways(data[0], data[1])
        print(comb)

Submission status: Accepted

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

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

    ot = 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:
                    ot += 1

    print(ot)

Submission status: Accepted

Solution code:
# coding:utf-8
while True:
    cnt = 0
    n,x = map(int, raw_input().split())
    if n == 0 and x == 0:
        break
    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 and i + j + k == x:
                    cnt += 1
    print cnt

Submission status: Accepted

Solution code:
ret = []
while True:
   n, x = map(int, raw_input().split())
   num_arr = [i for i in range(1, n+1)]
   if (n, x) == (0, 0):
       break

   cnt = 0
   for i in range(len(num_arr)):
       for j in range(i + 1, len(num_arr)):
           k_flg = False
           for k in range(j + 1, len(num_arr)):
               work = num_arr[i] + num_arr[j] + num_arr[k]
               if x == work:
                   cnt += 1
                   k_flg = True
                   break
   ret += [cnt]
for i in ret:
    print i

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    print(len([1 for a, b, c in combinations(range(1, n + 1), 3) if a + b + c == x]))

Submission status: Accepted

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

    ans=0
    if n == 0 and x == 0:
        break
    for n1 in range(1,n-1):
        for n2 in range(n1+1,n):
            n3=x-n1-n2
            if n2<n3<=n:
                ans+=1
    print(ans)

Submission status: Accepted

Solution code:
while(1):
    comb = []
    count =0
    inp = raw_input().split(" ")
    if inp[0] == "0" and inp[1] == "0":
        break
    for i in range(1,int(inp[0])+1):
        for j in range(1,int(inp[0])+1):
            if i == j:
                break
            sum = i + j
            if sum > int(inp[1]):
                j = int(inp[0])
                break
            for k in range(1,int(inp[0])+1):
                if i == j or i == k or j == k:
                    break
                sum = i + j + k
                if sum > int(inp[1]):
                    k = int(inp[0])
                    break
                if sum == int(inp[1]):
                    if not ([i,j,k] in comb or [i,k,j] in comb or [j,k,i] in comb or [j,i,k] in comb or [k,i,j]  in comb or [k,j,i] in comb):
                        comb.append([i,j,k])
                        count += 1
    print count

Submission status: Accepted

Solution code:
from itertools import combinations as comb
def get_ans(m, n):
	ans = 0
	for nums in comb(list(range(1, min(m+1,n-2))), 3):
		if sum(nums) == n:
			ans += 1
	print(ans)
	
while True:
	m, n = (int(x) for x in input().split())
	if m==0 and n==0:
		quit()
	get_ans(m, n)

Submission status: Accepted

Solution code:
while True:
  (n, x) = input().rstrip('\r\n').split(' ')
  n = int(n)
  x = int(x)

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

  a = []
  for ii in range(n):
    a.append(ii + 1)

  c = 0
  for ii in range(len(a)):
    for jj in range(ii + 1, len(a)):
      for kk in range(jj + 1, len(a)):
        if a[ii] + a[jj] + a[kk] == x:
          c += 1
  print(c)

Submission status: Accepted

Solution code:
from itertools import combinations as comb
def get_ans(m, n):
    ans = sum(1 for nums in comb(list(range(1, min(m+1,n-2))), 3) if sum(nums)==n)
    return ans
     
while True:
    m, n = (int(x) for x in input().split())
    if m==0 and n==0:
        quit()
    ans = get_ans(m, n)
    print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as comb
def get_ans(m, n):
    ans = sum(1 for nums in comb(range(1, min(m+1,n-2)), 3) if sum(nums)==n)
    return ans
      
while True:
    m, n = (int(x) for x in input().split())
    if m==0 and n==0:
        quit()
    ans = get_ans(m, n)
    print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

inputs = []
n,x = map(int,input().split())
while n != 0 or x != 0:
     inputs.append((n,x))
     n,x = map(int,input().split())

for n,x in inputs:
    print(len([c for c in combinations(range(1,n+1),3) if sum(c) == x]))

Submission status: Accepted

Solution code:
from itertools import combinations as comb
def get_ans(m, n):
    ans = sum(1 for nums in comb(range(1, min(m+1,n-2)), 2) if ((n-sum(nums)>0) and (n-sum(nums) > max(nums)) and (n-sum(nums)<=m)))
    return ans
      
while True:
    m, n = (int(x) for x in input().split())
    if m==0 and n==0:
        quit()
    ans = get_ans(m, n)
    print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

inputs = []
n,x = map(int,input().split())
while n != 0 or x != 0:
     inputs.append((n,x))
     n,x = map(int,input().split())

for n,x in inputs:
    print(len([0 for c in combinations(range(1,n+1),3) if sum(c) == x]))

Submission status: Accepted

Solution code:
def countCombinations(n, x, size=3):
    dp = [[0 for j in range(x + 1)] for i in range(size + 1)]
    dp[0][0] = 1
    for i in range(1, n + 1):
        for row in range(size - 1, -1, -1):
            for col in range(x + 1 - i):
                dp[1+row][i+col] += dp[row][col]
    return dp[-1][-1]



while True:
    m, n = (int(x) for x in input().split())
    if m==0 and n==0:
        quit()
    ans = countCombinations(m, n)
    print(ans)

Submission status: Accepted

Solution code:
def countCombinations(n, x, size=3):
    dp = [[0 for j in range(x + 1)] for i in range(size + 1)]
    dp[0][0] = 1
    for i in range(1, n + 1):
        for row in range(size - 1, -1, -1):
            for col in range(x + 1 - i):
                dp[1+row][i+col] += dp[row][col]
    return dp[-1][-1]

while True:
    m, n = (int(x) for x in input().split())
    if m==0 and n==0:
        quit()
    print(countCombinations(m, n))

Submission status: Accepted

Solution code:
# coding: UTF-8
def find_comb(n,x):
    count = 0
    #探索
    for i in range(1,n-1):
        for j in range(i+1,n):
            k = x - i - j #←がi < j < k <= nを満たせばその時点で総和がxとなる
            if  j < k <= n:
                count += 1
    print count
while(1):
    n,x = map(int, raw_input().split(" "))
    if(n == 0 and x == 0):
        break
    find_comb(n,x)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
"""
import sys
from sys import stdin
from math import factorial
input = stdin.readline


def solve(n, x):
    ans = 0
    for a in range(1, n+1):
        for b in range(a+1, n+1):
            if b < (x - a - b) <= n:
                ans += 1
    return ans


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


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def HMW(n,x):

    answer = 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:
                    answer += 1
                else:
                    pass

    print(answer)

while True:
    NX = input().split()
    n = int(NX[0])
    x = int(NX[1])
    if n==0 and x==0:
        break
    else:

        HMW(n, x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8

while True:
    a,b = (int(i) for i in input().split())
    if a == b == 0:
        break

    c = 0
    for i in range(1,a-1):
        for j in range(i+1, a):
            for k in range(j+1, a+1):
                if i + j + k == b:
                    c+=1
    print(c)

Submission status: Accepted

Solution code:
for _ in range(10000):
    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
    print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

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

    combi = 0
    for a in range(1, n-1):
        for b in range(a+1, n): # b > a
            c = x - a - b
            if c <= b:  # c must be > b
                break
            if c > n:
                continue
            # print(a, b, c)
            combi += 1

    print(combi)

Submission status: Accepted

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

Submission status: Accepted

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

while n != 0 or x != 0:
	cnt = 0
	i = 1
	while i <= n - 2:
		j = i + 1
		if i >= x:
			break
		while j <= n - 1:
			k = j + 1
			if i + j >= x:
				break
			while k <= n:
				if i + j + k > x:
					break
				if i + j + k == x:
					cnt += 1
				k += 1
			j += 1
		i += 1
	print(cnt)
	n, x = map(int, input().split())

Submission status: Accepted

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

while n != 0 or x != 0:
	cnt = 0
	i = 1
	while i <= n - 2:
		j = i + 1
	#	if i >= x:
	#		break
		while j <= n - 1:
			k = j + 1
	#		if i + j >= x:
	#			break
			while k <= n:
	#			if i + j + k > x:
	#				break
				if i + j + k == x:
					cnt += 1
				k += 1
			j += 1
		i += 1
	print(cnt)
	n, x = map(int, input().split())

Submission status: Accepted

Solution code:
import sys
'import math'
while(1):
    n,m=input().split()
    if n=='0' and m=='0':
        sys.exit()
    n=int(n)+1
    m=int(m)
    cnt=0
    for a in range(1,n):
        for b in range(a+1,n):
            for c in range (b+1,n):
                if a+b+c==m:
                    cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
'''
むー
たとえば、5 8とかなら…
1+2+3
1+2+4
1+2+…

1+3+4
1+3+5
1+3+…
みたいな形で総当たりすればいいのか。
ああー、でかい方から調べた方が効率良い？
いや見落とされるか。

それよりも、方法ない？
たとえば最小は6。1,2,3の組み合わせしかありえない。
7は1,2,4だけ。
8は1,2,5と1,3,4の2つ。
9は1,2,6、1,3,5、2,3,4の3つ
10は1,2,7、1,3,6、1,4,5、2,3,5の4つ
11は1,2,8、1,3,7、1,4,6、2,3,6、2,4,5の5つ
12は1,2,9、1,3,8、1,4,7、1,5,6、2,3,7、2,4,6、3,4,5で7つ
こんなかんじで1を含むものは
1//2x-2
2を含むものは
1//3x-2ちがう
1/2x-2
1/2x-3.5
1/2x-5
…

x-n>=3が最大
差が1増えるごとに1ずつ、5を超えると2ずつ、7を超えると3ずつ減る
1を含むものはx-n-3
2を含むものはx-n-3-2違うね。
x-n-3-2-()
3を含むものはx-n-3-2-2
…

リストで処理しなきゃダメじゃん…
'''

#テスト値
#n = 5
#x = 9



def countingWays(n,x):
    r = [
        i+j+k 
        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
        ]
        
    c = len(r)
    print(c)

#countingWays(n+1,x)
#print(c)

#s = []

while True:
    t = input()
    if t == "0 0":
        break
    else:
        n,x = map(int, t.split())
        countingWays(n+1, x)
#t = [s.pop(i*2) for i in range(len(s)/2)]

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

Submission status: Accepted

Solution code:
def count_combinations(max_, sum_):
    """return the number of combinations of three numbers
    (in 1..max_) which sum to sum_
    """
    result = 0 
    for i in range(1, max_-1):
        for j in range(i+1, max_):
            if j < (sum_ - (i + j)) <= max_:
                result += 1

    return result


def run():
    while True:
        (n, x) = [int(v) for v in input().split()]
        if n == 0 and x == 0:
            break
        else:
            print(count_combinations(n, x))


run()

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

Submission status: Accepted

Solution code:
def f(n, x):
    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 += 1
    return a

ans = ''
while True:
    n, x = map(int, input().split(' '))
    if n == 0:
        break
    else:
        ans += str(f(n, x)) + '\n'
print(ans[:-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
  n, x = map(int, input().split())
  if n == x == 0: break
  arr = []
  for a in range(1, n + 1):
    for b in range(1, n + 1):
      c = x - (a + b)
      if (a != b) & (b != c) & (c != a) & (c > 0) & (max(a, b, c) <= n):
        s = {a, b, c}
        if s not in arr: arr.append(s)
  print(len(arr))

Submission status: Accepted

Solution code:
import sys

l = []
for i in sys.stdin:
    l.append(i.split())

for i in range(0,len(l)-1):
    count = 0
    for a in range(1,int(l[i][0])+1):
        for b in range(a+1,int(l[i][0])+1):
            for c in range(b+1,int(l[i][0])+1):
                if a + b + c == int(l[i][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 j in range(1, n+1):
        for y in range(j+1, n+1):
            for z in range(y+1, n+1):
                if j + y + z == x:
                    count += 1

    print(count)

Submission status: Accepted

Solution code:
num,pat,sum=[],[],[]
i=int(0)
N=int(0)
while 1:
    num=list(map(int,input().split(' ')))
    pat.append(num[0])
    sum.append(num[1])
    if(pat[i]==0 and sum[i]==0):
        break
    i=i+1
    N=N+1
i=0
s=0
while(i<N):
    s=0
    for k in range(1,pat[i]+1):
        for l in range(k+1,pat[i]+1):
            for m in range(l+1,pat[i]+1):
                if(sum[i]==k+l+m):
                    s=s+1
    print(s)
    i=i+1

Submission status: Accepted

Solution code:
n = []
x = []
while(True):
    N,X = map(int,input().split())
    if N ==0 and X == 0:
        break
    else:
        n.append(N)
        x.append(X)
for l in range(len(n)):
    sum = []
    for i in range(1,n[l]+1):
        for j in range(1,n[l]+1):
            for k in range(1,n[l]+1):
                if i==j or j==k or i==k:break
                sum.append(i+j+k)
    print(int(sum.count(x[l])/2))