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: Runtime Error

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)

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

Submission status: Runtime Error

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 < 1 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: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
def counter(n, x):
    count = 0
    for i in range(n-2):
        for j in range(1, n-1):
            for k in range(2, n):
                if i + j + k == x:
                    count += 1
    return count

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split())
ans = 0
while not (n == 0 and m == 0):
 for i in range(N):
  for j in range(N):
   for k in range(N):
    if ( i==j or i==k or j==k):
    elif(i + j + k == M): ans += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
Answer = []
flg = 1

def Taxed(p,q):
    T = int(p*(1+q/100))
    return T

while flg > 0:
    inp = input().split()
    x = int(inp[0])
    y = int(inp[1])
    s = int(inp[2])

    flg = x**2+y**2+s**2
    if flg == 0:
        break

    M = 0
    for i in range(1,s-1):
        for j in range(1,s-1):
            a = Taxed(i,x)
            b = Taxed(j,x)
            if (a+b) == s:
                M_temp = Taxed(i,y) + Taxed(j,y) 
                M = max(M,M_temp)
    Answer.append(M)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
while True:
    n, x = map(int, 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)
                Sum = a + b + c
                if (Sum == x):
                    count += 1 
    print(count)

Submission status: Runtime Error

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: Runtime Error

Solution code:
while True:
    n, x = map(int, 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):
                Sum = a + b + c
                if (Sum == x):
                    count += 1 
    print(count)

Submission status: Runtime Error

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(_list, 3))
        print(sum((True if sum(i) == x else False) for i in comb))


main()

Submission status: Runtime Error

Solution code:
import Control.Monad
import Control.Applicative

combinations :: Int -> [a] -> [[a]]
combinations 0 _ = [[]]
combinations _ [] = []
combinations n (x:xs) = (map (x:) (combinations (n-1) xs)) ++ (combinations n xs)

solve :: [Int] -> String
solve [n, x] =
   show $ length [nc3 | nc3<-combinations 3 [1..n], sum nc3==x]

main =
    mapM_ putStrLn =<< map solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = takeWhile (not . all (== 0)) . map (map read . words)

Submission status: Runtime Error

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: Runtime Error

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

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

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

Solution code:
while(1):
    count =0
    inp = raw_input().split(" ")
    if inp == "0 0":
        break
    for i in range(1,int(inp[0])+1):
        for j in range(1,int(inp[0])+1):
            if i != j:
                sum = i + j
                if sum == int(inp[1]):
                    count += 1
    print count

Submission status: Runtime Error

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

Submission status: Runtime Error

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) not in nums))
    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: Runtime Error

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) not in nums)))
    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: Runtime Error

Solution code:
import numpy as np

def countCombinations(n, x, size=3):
    dp = np.zeros((x + 1, size + 1), dtype=int)
    dp[0][0] = 1
    for i in range(1, n + 1):
        dp[i:, 1:] += dp[:-i, :-1]
        print(dp)
    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: Runtime Error

Solution code:
import numpy as np

def countCombinations(n, x, size=3):
    dp = [[0 for i in range(size + 1)] for j in range(x + 1)]
    dp[0][0] = 1
    for i in range(1, n + 1):
        for j in range(x + 1 - i):
            for k in range(size + 1 - 1):
                dp[i+j][1+k] += dp[j][k]
    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: Runtime Error

Solution code:
def countCombinationsNumpy(n, x, size=3):
    dp = np.zeros((x + 1, size + 1), dtype=int)
    dp[0, 0] = 1
    for i in range(1, n + 1):
        dp[i:, 1:] += dp[:-i, :-1]
        print(dp)
    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: Runtime Error

Solution code:
while(True):
    n, x = map(int, input().spilt())
    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: Runtime Error

Solution code:
def transnum(int: n):
    if n % 3 != 0:
        return n + 3 - n % 3
    else:
        return n

while True:
    x,n = tuple(int(i) for i in input().split())
    r = 0
    if x == n == 0:
        break
    amin = n // 3 + 1
    amax = 2 * transnum(n) // 3
    if amax > x:
        amax = x

    A = [j for j in range(amin, amax+1)]

    #print(A)

    for a in A:
        bmin = (n-a) // 3 + 1
        bmax = 2 * transnum(n-a) // 3
        if bmax > a:
            bmax = a

        B = [j for j in range(bmin, bmax) if j+j != n-a]
        #print(B)
        for b in B:
            cmin = (n-a-b) // 3 + 1
            cmax = 2 * transnum(n-a-b) // 3
            if cmax > b:
                cmax = b
            C = [k for k in range(cmin, cmax) if k == n-a-b]
            #print(C)
            r += len(C)
            C.clear()
        B.clear()
    
    print(r)

Submission status: Runtime Error

Solution code:
def transnum(int: n):
    if n % 3 != 0:
        return n + 3 - n % 3
    else:
        return n
 
while True:
    x,n = tuple(int(i) for i in input().split())
    r = 0
    if x == n == 0:
        break
    amin = n // 3 + 1
    amax = 2 * transnum(n) // 3
    if amax > x:
        amax = x
 
    A = [j for j in range(amin, amax+1)]
 
    #print(A)
 
    for a in A:
        bmin = (n-a) // 3 + 1
        bmax = 2 * transnum(n-a) // 3
        if bmax > a:
            bmax = a
 
        B = [j for j in range(bmin, bmax) if j+j != n-a]
        #print(B)
        for b in B:
            cmin = (n-a-b) // 3 + 1
            cmax = 2 * transnum(n-a-b) // 3
            if cmax > b:
                cmax = b
            C = [k for k in range(cmin, cmax) if k == n-a-b]
            #print(C)
            r += len(C)
            C.clear()
        B.clear()
     
    print(r)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n = 1, x = 0, ans;
	while(!(n == 0 && x == 0)){
		cin >> n >> x;
		ans = 0;
		for(int i = 1; i <= n; i++){
			for(int j = i + 1; j <= n; j++){
				for(int k = j + 1; k <= n; k++){
					if(i + j + k == x) ans++;
				}
			}
		}
		cout << ans << '¥n ';
	}
}

Submission status: Runtime Error

Solution code:
# AOJ ITP1_7_B

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    while True:
        a = numinput()
        n = a[0]; x = a[1]
        if n == 0 and x == 0: break
        # 1からnまでの異なる3つの数の和がxになる数の組の個数。
        count = 0
        for i in range(1, (x // 3) + 1):
            for j in range(i + 1, (x // 3) + 1):
                if j < x - i - j: count++
        print(count)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

Solution code:
# 12-Structured_Program_II-How_many_ways.py

# ????????????????????°
# 1 ?????? n ?????§?????°?????????????????????????????§???????????°?????????????????????????¨???? x ??¨??????
# ????????????????????°????±???????????????°?????????????????????????????????
# ????????°???1 ?????? 5 ?????§?????°???????????????????????§????????????????¨???? 9 ??¨???????????????????????????

# 1 + 3 + 5 = 9
# 2 + 3 + 4 = 9
# ??????????????????????????????

# Input
# ?????°??????????????????????????\?????¨???????????????????????????
# ???????????????????????§??????????????§??????????????? n???x ??? 1 ???????????????????????????

# n???x ?????¨?????? 0 ?????¨?????\?????????????????¨????????????
# n ??? 3 ??\??? 100?????\?????¨????????????

# Output
# ????????????????????????????????????????????????????????°????????????????????????????????????

# Sample Input
# 5 9
# 0 0
# Sample Output
# 2

result = []
n=[]
x=[]

while 1:
	temp = input().split() 
	if temp[0]=="0" and temp[1]=="0":
		break;
	else:
		n.append( int( temp[0] ))
		x.append( int( temp[1] ))

for i in range( len(n) ):
	count =0
	for n1 in range(1,n[i]+1-2):
		for n2 in range(n1+1, n[i]+1-1):
			for n3 in range(n2+1, n[i]+1):
				sum = n1+n2+n3
				if sum == x[i]:
					count+=1
	print("{0} ".format(count),end="")

Submission status: WA: Presentation Error

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

    if n == x == 0:
        break

    count = 0
    for s in range(1, n // 2 + 1):
        for e in range(n, n // 2, -1):
            m = x - s - e
            if m != s and m != e and m > s and m < e and m <= n:
                count += 1
            
            else:
                print()
                
    print(count)