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 1:
    n,x=map(int,raw_input().split())
    conbi = 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:
                    conbi = conbi + 1
    print conbi

Submission status: Accepted

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

import sys


def main():
    while True:
        count = 0
        n, r = map(int, sys.stdin.readline().split())
        if n == r == 0:
            break
        for n1 in range(1, n-1):
            for n2 in range(n1+1, n):
                for n3 in range(n2+1, n+1):
                    if n1 + n2 + n3 == r:
                        count += 1
        print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while 1:
    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+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
	
	ctr = 0
	
	for i in range(1, N+1):
		for j in range(i+1, N+1):
			k = x - i -j
			if k <= j:
				break
			elif k <= N and j < k:
				ctr += 1
				#print("{} {} {}".format(i, j, k))
			
	print(ctr)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, goal = [int(x) for x in input().split(" ")]
    res =[]

    if n == goal == 0:
        break

    for first in range(1, n+1):
        for second in range(first+1, n+1):
            rem = goal - (first + second)
            if rem > second and n >= rem:
                res.append([first, second, rem])

    print(len(res))

Submission status: Accepted

Solution code:
import itertools
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    i = 0
    l = range(1, n+1)
    for elem in itertools.combinations(l, 3):
        if sum(elem) == x:
            i += 1
    print(str(i))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = []
while True:
    n, x = map(int, input().strip().split())
    if n == x == 0:break
    c = 0
    for i in range(1, x // 3):
        c += max(0, max(0,(x - 3 * i - 1) // 2) - max(0,(x - 2 * i - 1 - n)))
    s.append(str(c))
print('\n'.join(s))

Submission status: Accepted

Solution code:
array = []
while 1 :
    n = input()
    if n == "0 0":
        break
    array.append(n.split())
for i in range(len(array)):
    count = 0
    for i2 in range(1,int(array[i][0])+1):
        for i3 in range(i2+1,int(array[i][0])+1):
            number =int(array[i][1])-(i2+i3)
            if number > i3 and number <= int(array[i][0]):
                count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import os


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

while True:
    lst = input_to_list()
    if lst[0] == lst[1] == 0:
        break
    else:
        n = lst[0]
        x = lst[1]
        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(c)

Submission status: Accepted

Solution code:
from itertools import combinations
original_vals = []
original_labels = []

while True:
    n, x = list(map(int, input().split()))
    if n+x == 0:
        break
    l = [ i for i in range(1,n+1)]
    original_vals.append(l)
    original_labels.append(x)

for i,row in enumerate(original_vals):
    cs = list(combinations(row, 3))
    count = 0
    for c in cs:
        if sum(c) == original_labels[i]:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if (n,x) == (0,0) : break
    cnt = 0
    if 3*(n-1) >= x:
        a_max = x//3 - 1
        if 2*n -1 < x:
            a_min = x - (2*n-1)
        else :
            a_min = 1
        for a in range(a_min,a_max+1):
            b_max = (x-a-1)//2
            b_min = (x-a) - n
            b_min = b_min if b_min > a+1 else a+1
            cnt += b_max - b_min +1
    print(cnt)

Submission status: Accepted

Solution code:
n = 1
x = 1
while n!=0 or x!=0:
	n,x = [int(i) for i in input().split()]
	if n!=0 or x!=0:
		list = [int(i) for i in range(1,n+1)]
		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(1):
    n, x = map(int, input().split())

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

    count = 0
    for i in range(1, n-1):
        if i*3 >= x:
            break
        for j in range(i+1, n):
            if i+2*j >= x:
                break
            if x-i-j <= n:
                count += 1

    print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

def func():
    data=[]
    while(True):
        try:
            line=[ int(item) for item in input().rstrip().split(" ") ]
            if(line == [0,0]):
                break
            data.append(line)
        except EOFError:
            break
        except:
            return inputError()
    
    left=1
    numbers=3
    [print(len(sumcombination(left,line[0],numbers,line[1]))) for line in data]

def sumcombination(left,right,numbers,total):
    '''
    left ~ right??????????????°??????(numbers)????????´??°???????¨????total?????????????????????????????????????????????
    '''
    result=[]
    if(numbers==1):
        if( (left <= total) and (right >= total) ):
            result=[total]
        return(result)
    
    for i in range(left,right+1):
        if( numbers == 2):
            if(i >= total-i):
                break
            elif( (i != total-i) and (left <= total-i) and (right >= total-i) ):
                result.append([i,total-i])
        elif( ( len( range(i,right+1) ) < numbers ) or ( sum( range(i+1,i+numbers) ) > total-i ) ):
            break
        elif( sum( range(right-numbers+2,right+1) ) < total-i ):
            continue
        else:
            sub = sumcombination(i+1,right,numbers-1,total-i)
            if(len(sub)>0):
                [items.insert(0,i) for items in sub]
                result.extend(sub)

    return(result)

def inputError():
    print("input error")
    return -1

func()

Submission status: Accepted

Solution code:
dataset = []
wayset = []

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

for x in dataset:
    ways = 0
    for i in range(x[0]):
        for j in range(x[0]):
            for k in range(x[0]):
                if k > j and j > i:
                    if i + j + k + 3 == x[1]:
                        ways += 1
    wayset.append(ways)

for x in wayset:
    print(x)

Submission status: Accepted

Solution code:
while True:
    n, x = [int(i) for i in input().split(" ")]
    if n == x == 0:
        break
    count = 0
    for r1 in range(1, n -1):
        for r2 in range(r1 + 1, n):
            for r3 in range(r2 + 1, n + 1):
                if r1 + r2 + r3 == x:
                    count += 1
    print(count)

Submission status: Accepted

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

    count = 0 

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

Submission status: Accepted

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

    count = 0 

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

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    numbers = set()
    N = [i for i in range(1, n+1)]
    for i in N:
        for j in N:
            if i == j:
                break
            for k in N:
                if i == j or i == k or j == k:
                    break
                else:
                    numbers.add((i, j, k))
    count = 0
    numbers = list(numbers)
    for i in numbers:
        if i[0] + i[1] + i[2] == x:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    for l in stdin:
        n, x = map(int, l.split(' '))
        if 0 == n == x:
            break

        print(len(num_sets(n, x)))

def num_sets(n, x):
    num_sets = []

    for i in range(1, n-1):
        for j in [m for m in range(i+1, n)]:
            k = x - (i+j)

            if n < k:
                continue

            if k <= j:
                break

            num_sets.append((i, j, k))

    return num_sets

if __name__ == '__main__': main()

Submission status: Accepted

Solution code:
L = []
n,x = map(int, input().split())
while not(n == 0 and x == 0):
 L.append([n, x])
 n, x = map(int, input().split())

for i in L:
 ans = 0
 for j in range(1, i[0] - 1):
  if j > i[1] - 3:
   break
  else:
   for k in range(j + 1, i[0]):
    m = i[1] - (j + k)
    if m <= k:
     break
    elif m <= i[0]:
     ans += 1
    else:
     continue
 print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    c = []
    c = sorted(b)

    if len(c) == 0:
        cnt = 0
    else:
        cnt = 1
        t = c[0]
        for i in c:
            if t != i:
                cnt += 1
                t = i
    print(cnt)

Submission status: Accepted

Solution code:
#coding:utf-8

import itertools

def goukei(b , x):
    count = 0
    for i in range(len(b)):
        if sum(b[i]) == x:
            count += 1
    return count

n =1
x =1

while n+x != 0:
    n , x = [int(i) for i in input().rstrip().split(" ")]

    if n + x == 0:
        break
    
    a = [i for i in range(1,n+1)]
#?????????????????????????????????
    kumi = list(itertools.combinations(a ,3))
    
    print(goukei(kumi,x))

Submission status: Accepted

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

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(x//3+1,n+1):
        for j in range((x-i)//2+1,i):
            if 0<x-i-j<j :   
                sum+=1
    print(int(sum))

Submission status: Accepted

Solution code:
while True:
    s = input().split(" ")
    n = int(s[0])
    x = int(s[1])
    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):
                if i + j + k == x:
                    cnt += 1
    print(cnt)

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

Submission status: Accepted

Solution code:
list = []

while 1:
    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
        list.append(cnt)

for i in list:
    print(i)

Submission status: Accepted

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

    a = [i for i in range(1, n+1)]
    b = [i for i in itertools.combinations(a, 3)]
    c = 0
    cnt = 0
    for i in range(len(b)):
        for j in range(3):
            c += b[i][j]
        if c == x:
            cnt += 1
        c = 0
    print(cnt)

Submission status: Accepted

Solution code:
while True:
    n,x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break
    res = 0
    i = 1
    while n-1 > i:
        j = i+1
        while n > j:
            k = j+1
            if x < i+k:
                break
            while n >= k:
                sum = i+j+k
                if sum == x:
                    res += 1
                elif x < sum:
                    break
                k += 1
            j += 1
        i += 1
    print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1 :
    n,x=[int(i) for i in input().split()]
    count=0
    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:
                    count=count+1
    print(count)

Submission status: Accepted

Solution code:
from itertools import combinations

def f(n,x):
	is3 = [sum(c)==x for c in combinations(range(1,n+1),3)]
	return sum(is3)

data = []
while True:
	temp = [int(s) for s in input().split(' ')]
	if temp == [0,0]:
		break
	else:
		data.append(temp)

ans = [f(n,x) for n,x in data]
[print(a) for a in ans]

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""

while True:
    inp = input().strip().split(" ")
    n = int(inp[0]) + 1
    x = int(inp[1])
    cnt = 0
    if n < 2 and x < 1:
        break
    for i in range(1, n-2):
        for j in range(i + 1, n-1):
            for k in range(j + 1, n):
                t = i + j + k
                if t == x:
                    cnt = cnt + 1
                elif t > x:
                    break
    print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x=1
y=1
list=[]
while x>0:
    if x ==0 and y == 0:
        break
    x,y = map(int,input().split())
    list.append([x,y])

list.remove([0,0])

for L in list:
    ans = 0
    for i in range(1,L[0]-1):
        for j in range(i+1,L[0]):
            for k in range(j+1,L[0]+1):
                if L[1]== i + j+ k:
                    ans += 1
                else:
                    pass
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

  ans = 0

  for i in range(1,n+1):
    for j in range(i+1,n+1):
      k = x-(i+j)
      if k >= 1 and k <= n and k > j:
        ans += 1

  print(ans)

Submission status: Accepted

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

    num_set = []
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if i < j < k and i+j+k ==x:
                    li = [i,j,k]
                    if not li in num_set:
                        num_set.append(li)
    print(len(num_set))

Submission status: Accepted

Solution code:
while True:
    n, x = map(int,input().split())
    count=0
    if n == x == 0:
        break
    else:
        ls = []
        for i in range(1,n+1):
            ls.append(i)

        for s in ls:
            num1 = s

            for j in ls:
                if num1 == j:
                    break
                else:
                    num2 = j
                    if x < num1+num2:
                        break

                for k in ls:
                    if num1 == k:
                        break
                    elif num2 == k:
                        break
                    elif num1+num2+k == x:
                        count+=1
                    else:
                        pass
    print(count)

Submission status: Accepted

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

    cnt = 0

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

    print(cnt)

Submission status: Accepted

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

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

    print(cnt)

Submission status: Accepted

Solution code:
while True:
    n, x = (int(x) for x in input().split())
    if (n, x) == (0, 0): break
    cnt = sum(1 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)
    print(cnt)

Submission status: Accepted

Solution code:
while True:
    result = set()
    n, x = map(int, raw_input().split())
    if n == 0 and 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 + k == x and i != j and j != k and k != i:
                        temp = [i, j, k]
                        sorted(temp)
                        temp = tuple(temp)
                        result.add(temp)
        print(len(result))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    if n <= x: max = n  
    for _ in range(max):
        if max == 2: break
        mid = max - 1
        for _ in range(mid):
            min = x - max - mid

            if min <= 0: mid -= 1
            elif min >= mid:

                break
            else: 
                ret += 1
                mid -= 1
        max -= 1
    print(ret)

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)):
           for k in range(j + 1, len(num_arr)):
               work = num_arr[i] + num_arr[j] + num_arr[k]
               if x == work:
                   cnt += 1
   ret += [cnt]
for i in ret:
    print i

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

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(n, 0, -1):
       if x - i <= 2:
           continue
       #print "i : %d" % i
       for j in range(i -1, 0, -1):
          if x-i-j <= 0:
              continue
          #print "j : %d" % j
          for k in range(j - 1, 0 , -1):
              if x-i-j-k < 0:
                  continue
              if x -i-j-k == 0:
                  cnt += 1
                  #print "k : %d" % k
                  break
   ret += [cnt]
for i in ret:
    print i

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

Submission status: Accepted

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

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

   for i in range(n, 0, -1):
       for j in range(i -1, 0, -1):
           if 0 < x - i - j < j:
               cnt += 1
   ret += [cnt]
for i in ret:
    print i

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Aizu Problem ITP_1_7_B: How many ways?
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    n, x = [int(_) for _ in input().split()]
    if n == x == 0:
        break
    cnt = 0
    for a in range(1, x // 3):
        for b in range(a + 1, x // 2):
            c = x - a - b
            if b < c <= n:
                cnt += 1
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

for n in numbers:
    num = list(range(1, n[0]+1))
    count = 0
    for i in itertools.combinations(num, 3):
        if sum(i) == n[1]:
            count += 1
    print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = 0
x = 0
cnt = 0

while True:
    
    I = input().split()
    n = int(I[0])
    x = int(I[1])
    if n == 0 and x == 0:
        break
    
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                if (i + j + k) == x:
                    cnt += 1
                    continue
    print(cnt)
    cnt = 0

Submission status: Accepted

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

while n + x != 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):
                if i + j + k == x:
                    count += 1

    print(count)

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

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    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:
from itertools import combinations

def f(s):
    n, x = list(map(int, s.split()))
    return len(tuple(filter(lambda it: sum(it) == x,
                            combinations(range(1, n+1), 3))))

while True:
    s = input()
    if s == "0 0":
        break
    print(f(s))

Submission status: Accepted

Solution code:
ways_list=[]

while True:
    by_goal=[]
    ways=0
    by_goal=input().split()
    by_goal[0]=int(by_goal[0])
    by_goal[1]=int(by_goal[1])
    if by_goal[0]==0 and by_goal[1]==0:
        break
    for i in range(1,by_goal[0]+1):
        for j in range(1,by_goal[0]+1):
            for k in range(1,by_goal[0]+1):
                if i+j+k==by_goal[1]:
                    if i != j and j!=k and k!=i:
                            ways+=1
    ways_list.append(ways//6)
for i in range(0,len(ways_list)):
    print(ways_list[i])