Problem:


How many ways?

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

  
You should select three distinct integers from 1 to n.

  
A total sum of the three integers is x.

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

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

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

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

Constraints

  
3 ≤ n ≤ 100

  
0 ≤ x ≤ 300

Output

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

Sample Input

5 9
0 0

Sample Output

2

Note

      解説      

	


Sample input:
5 9
0 0


Sample output:
2

Submission status: Accepted

Solution code:
while True:
    num = list(map(int,input().split()))
    if(num[0] == 0 and num[1] == 0): break
    c = 0
    for i in range(1,num[0] - 1):
        for j in range(i+1,num[0]):
            for k in range(j+1,num[0]+1):
                if(i+j+k == num[1]): c += 1
    
    print(c)

Submission status: Accepted

Solution code:
while True:
    num = list(map(int,input().split()))
    if(num[0] == 0 and num[1] == 0): break
    c = 0
    for i in range(1,num[0]+1):
        for j in range(i+1,num[0]+1):
            if j <= i:
                continue
            k = num[1]-(i+j)
            if k > j and k <= num[0]:
                c+= 1
    print(c)

Submission status: Accepted

Solution code:
while True:
  N,X = map(int,input().split())
  if N==0 and X==0:
    break
  ans = 0
  for a in range(1,N+1):
    for b in range(a+1,N+1):
      if b >= N+1:
        break
      c = X-(a+b)
      if c > b and c <=N:
        ans +=1
  print("{:d}".format(ans))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    count=0
    n, s = tuple([int(x) for x in raw_input().split(" ")])

    if n==0 and s==0:
        break
    
    for i in range(1, n+1):
        for j in range(1, n+1):
            if j==i:
                continue
            for k in range(1, n+1):
               if k==i or k==j:
                   continue
               if i+j+k==s:
                   count+=1
    
    print count / 6

Submission status: Accepted

Solution code:
while True:
    count=0
    n, s = tuple([int(x) for x in raw_input().split(" ")])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    dataset = []
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            for c in range(b + 1, n + 1):
                dataset.append([a,b,c])

    count = 0
    for data in dataset:
        if sum(data) == x:
            count += 1

    print(count)

Submission status: Accepted

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

    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):
                if sum([a,b,c]) == x:
                    count += 1

    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

    count = 0
    limit = n if n < x else x
    for a in range(1, limit + 1):
        for b in range(a + 1, limit + 1):
            for c in range(b + 1, limit + 1):
                if sum([a,b,c]) == x:
                    count += 1

    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

    count = 0
    start = n if n < x else x
    for a in range(start, 0, -1):
        if a >= x:
            continue
        for b in range(a - 1, 0, -1):
            if sum([a,b]) >= x:
                continue
            for c in range(b - 1, 0, -1):
                if sum([a,b,c]) == x:
                    count += 1
    print(count)

Submission status: Accepted

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

    count = 0
    for a in range(1, n + 1):
        if a >= x:
            break
        for b in range(a + 1, n + 1):
            if sum([a,b]) >= x:
                break
            for c in range(b + 1, n + 1):
                if sum([a,b,c]) == x:
                    count += 1

    print(count)

Submission status: Accepted

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

    count = 0
    start = n if n < x else x
    for a in range(start, 0, -1):
        if a >= x:
            continue
        for b in range(a - 1, 0, -1):
            if a + b >= x:
                continue
            for c in range(b - 1, 0, -1):
                if a + b + c == x:
                    count += 1
    print(count)

Submission status: Accepted

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

    count = 0
    start = n if n < x else x
    for a in range(start, 0, -1):
        if a >= x:
            continue
        for b in range(a - 1, 0, -1):
            if a + b >= x:
                continue
            for c in range(b - 1, 0, -1):
                total = a + b + c
                if total == x:
                    count += 1
                elif total < x:
                    break
    print(count)

Submission status: Accepted

Solution code:
while True:
    (n, x) = [int(i) for i in 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
                elif (i + j + k) > x:
                    break
    print(cnt)

Submission status: Accepted

Solution code:
result = []

def combination(n, x):
    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
    result.append(count)


while True:
    (n, x) = [int(i) for i in input().split()]

    if n == x == 0:
        break

    combination(n, x)

[print(result[x]) for x in range(len(result))]

Submission status: Accepted

Solution code:
while True:
    n,x = map(int, raw_input().split())
    count = 0
    if(n != 0 or x != 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
    else:
        break

Submission status: Accepted

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

  print(count)

Submission status: Accepted

Solution code:
import sys
while True:
    (n, x) = [int(i) for i in sys.stdin.readline().split()]
    if n == x == 0:
        break
    count = 0
    for i in range(1, n + 1):
        if i >= x: break
        for j in range(i + 1, n + 1):
            if i + j >= x: break
            for k in range(j + 1, n + 1):
                if i + j + k == x: count += 1
                elif i + j + k > x: break
    print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
while True:
    try:
        n,x = map(int,raw_input().split())
        if n == x == 0:
            break
    except EOFError:
        break
    
    total = 0
    for k in range(1,n+1):
        for j in range(1,n+1):
            for l in range(1,n+1):
                if k!=j!=l and k + j + l == x and k<j<l:
                    total +=1
    print total

Submission status: Accepted

Solution code:
import itertools as itr

def solve(n, x):
    return [sum(i) for i in itr.combinations(range(1, n+1), 3)].count(x)

if __name__ == '__main__':
    while True:
        n, x = [int(i) for i in input().split()]
        if n == x == 0: break
        print(solve(n, x))

Submission status: Accepted

Solution code:
#coding:utf-8
#1_7_B 2015.4.5
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(1 , n + 1):
            for k in range(1 , n + 1):
                if i + j + k == x and i < j < k:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
#coding:utf-8
#1_7_B 2015.4.5
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(1 , n + 1):
            if (x - i - j) <= n and i < j < (x - i -j):
                count += 1
    print(count)

Submission status: Accepted

Solution code:
#coding:utf-8
#1_7_B 2015.4.5
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(1 , n + 1):
            if i < j < (x - i - j) <= n:
                count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, raw_input().split())
    if (n, x) == (0, 0):
        break
    ans = 0
    for a in xrange(1, n+1):
        for b in xrange(a+1, n+1):
            for c in xrange(b+1, n+1):
                if a + b + c == x:
                    ans += 1
    print ans

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

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	for i in range( 1, n-1 ):
		if  x <= i:
			break
		for j in range( i+1, n ):
			if  x <= ( i+j ):
				break
			for k in range( j+1, n+1 ):
				s = ( i + j + k )
				if x == s:
					cnt += 1
					break
				elif   x < s:
					break
	
	print( cnt )

Submission status: Accepted

Solution code:
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	goto = False
	for i in range( 1, n-1 ):
		if  x < 3*(i+1):
			break
		for j in range( i+1, n ):
			if  x <= ( i+j ):
				break
			for k in range( j+1, n+1 ):
				s = ( i + j + k )
				if x == s:
					cnt += 1
					break
				elif   x < s:
					goto = True
					break
			goto = False
	
	print( cnt )

Submission status: Accepted

Solution code:
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	for i in range( 1, n-1 ):
		if  x < 3*(i+1):
			break
		for j in range( i+1, n ):
			if  x <= ( i+j ):
				break
			for k in range( j+1, n+1 ):
				s = ( i + j + k )
				if x == s:
					cnt += 1
					break
				elif   x < s:
					break
	
	print( cnt )

Submission status: Accepted

Solution code:
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	ave = x / 3
	for i in range( 1, ave ):
		for j in range( i+1, n ):
			if  x <= ( i+j ):
				break
			for k in range( j+1, n+1 ):
				s = ( i + j + k )
				if x == s:
					cnt += 1
					break
				elif   x < s:
					break
	
	print( cnt )

Submission status: Accepted

Solution code:
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	ave = x // 3
	for i in range( 1, ave ):
		for j in range( i+1, n ):
			if  x <= ( i+j ):
				break
			for k in range( j+1, n+1 ):
				s = ( i + j + k )
				if x == s:
					cnt += 1
					break
				elif   x < s:
					break
	
	print( cnt )

Submission status: Accepted

Solution code:
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	ave = x // 3
	for i in range( 1, ave ):
		ave2 = (x-i) // 2
		for j in range( i+1, ave2+1 ):
			k = x-i-j
			if j < k and k <= n:
				cnt += 1
	
	print( cnt )

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding=utf-8
import itertools


def main():
    while True:
        n, t = map(int, raw_input().split())
        if n + t == 0:
            break
        print sum([1 if sum(three) == t else 0 for three in itertools.combinations(xrange(1, n+1), 3)])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

while 1:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    L = list(range(1, n + 1))
    count = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = x - L[i] - L[j]
            idx = bisect.bisect_left(L, a, lo=j + 1)
            if idx < n and L[idx] == a:
                count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for a in range(n if n < x else x, 2, -1):
        for b in range(a-1, 1, -1):
            if a + b > x:
                continue
            for c in range(b-1, 0, -1):
                s = a + b + c
                if s == x:
                    count += 1
                    break
                elif s < x:
                    break
    print(count)

Submission status: Accepted

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

    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):
                if (a + b + c) == x:
                    count += 1
                elif (a + b + c) > x:
                    break
    print(count)

Submission status: Accepted

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

    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):
                if (a + b + c) == x:
                    count += 1
    print(count)

Submission status: Accepted

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

    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):
                if (a + b + c) == x:
                    count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    for i in range(1,n+1):
        for j in range(1,n):
            for k in range(1,n-1):
                if i+j+k==x and i>j>k and not i==j==k:
                    count += 1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getWays(n, x):
  ways = []
  for i in xrange(1, n - 1):
    j = i + 1
    while j < n:
      # print "i = " + str(i) + ", j = " + str(j)
      remain = x - i - j
      if remain <= n and remain > j:
        list = [i, j, remain]
        ways.append(list)
      j+= 1
  return ways

while True:
  line = raw_input().split(" ")
  n = int(line[0])
  x = int(line[1])
  if n == 0 and x == 0:
    break
  else:
    print len(getWays(n, x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = []
while True:
    b = map(int, raw_input().split())
    if b == [0, 0]:
        break
    a.append(b)
for list in a:
    n, x = list
    c = 0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i + j + k == x - 3 and i < j and j < k:
                    c += 1
    print c

Submission status: Accepted

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

    comb = []
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            c = i + j
            tmp = x - c
            if (tmp <= n) & (tmp > j):
                comb.append([i, j, tmp])

    print len(comb)

Submission status: Accepted

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

    comb = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            c = i + j
            tmp = x - c
            if (tmp <= n) & (tmp > j):
                comb += 1

    print comb

Submission status: Accepted

Solution code:
while True :
	n,x=map(int,raw_input().split())
	if not( n==0 and x==0) :
		p_count = 0
		i,j,k = [1,2,3]
		while i <= n-2 :
			j = i+1
			while j <= n-1:
				k = j+1
				while k <= n:
					if (i+j+k)==x :
						p_count += 1
						k += 1
						break
					else :
						k += 1
				j += 1
			i += 1
		print(p_count)
 	else :
 		break

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):
            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
    cnt = 0
    for i in range(1, min(n - 1, int(x / 3))):
        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
    cnt = 0
    upper_max_value = min(x - 3, n)
    lower_max_value = max(int(x / 3), 3)
    for i in range(upper_max_value, lower_max_value - 1, -1):
        for j in range(i - 1, 1, -1):
            for k in range(j - 1, 0, -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
    max_a = min(x - 3, n)
    min_a = max(x // 3 + 1, 3)
    cnt = 0
    for i in range(min_a, max_a + 1):
        max_b = min(i - 1, x - i - 1)
        min_b = (x - i) // 2 + 1
        cnt += (max_b - min_b + 1)
    print(cnt)

Submission status: Accepted

Solution code:
data = []
while True:
    in_line = raw_input().split()
    n = int(in_line[0])
    x = int(in_line[1])
    if n == 0 and x == 0:
        break
    data.append([n,x])
for n in data:
    count = 0
    for i in range(1,n[0]+1):
        for j in range(i+1,n[0]+1):
            for k in range(j+1,n[0]+1):
                if i+j+k == n[1]:
                    count += 1
    print count

Submission status: Accepted

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

    count = 0
    for n1 in range(1, n+1):
        for n2 in range(n1+1, n+1):
            for n3 in range(n2+1, n+1):
                if n1 + n2 + n3 == x:
                    count += 1

    print(count)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, raw_input().split(" "))
    if n==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
                    break
    print ans

Submission status: Accepted

Solution code:
ans = 0
def do(x,c,index):
    global ans
    # print "c : " + str(c)
    # print "x : " + str(x)
    # print "index : "+ str(index)
    # print "###############"
    if index < 0:
        return
    if x < 0:
        return
    if c>=3 and x!=0:
        return
    if x == 0 and c!=3:
        return
    if c==3 and x==0:
        # print "detect!"
        ans += 1
        return
    for i in reversed(xrange(1,index+1)):
        # print "i : "+ str(i)
        do(x-i,c+1,i-1)
    return

while True:
    n,x = map(int,raw_input().split())
    if n==0 and x == 0:
        break
    # nlist = [i for i in xrange(1,n+1)]
    # print nlist
    do(x,0,n)
    # print "ans : "+str(ans)
    print ans
    ans = 0

Submission status: Accepted

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