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

Submission status: Accepted

Solution code:
data = []
while True:
  a,b = map(int, input().split())
  if a == 0 and b == 0:
    break
  else:
    ans = 0
    for i in range(1,a-1):
      for j in range(i+1,a+1):
        for k in range(j+1,a+1):
          if i + j + k == b:
            ans += 1
    data.append(ans)

for i in data:
  print(i)

Submission status: Accepted

Solution code:
from itertools import combinations
while 1:
    N, M= map(int,input().split())
    if N == M == 0:
        break
    else:
        li = [n + 1 for n in range(N)]
        combi = list(combinations(li,3))
        cont = 0
        for com in combi:
            if sum(com) == M:
                cont += 1
        print(cont)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n,m=list(map(int,input().split()))
    if n==0&m==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==m:
                    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(1,N+1):
            if b<=a:
                continue
            c = X-(a+b)
            if c>b and c<=N:
                ans +=1
    print("%d"%(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    indatas = []
    while True:
        n, x = map(int, input().split())
        if n == 0 and x == 0:
            break
        indatas.append((n, x))
    for data in indatas:
        n, x, ans = data[0], data[1], 0
        for i in range(1, n+1):
            for j in range(i, n+1):
                if i == j:
                    continue
                k = x - i - j
                if k <= i or k <= j:
                    continue
                if k <= 0 or k > n:
                    continue
                ans += 1
        print(ans)
# EOF

Submission status: Accepted

Solution code:
while True:
    c=0
    a,b=map(int,input().split())
    for l in range(1,a+1):
        for m in range(1,a+1):
            for n in range(1,a+1):
                if l+m+n==b:
                  if l==m or m==n or l==n:
                    c=c
                  else:
                    c+=1
    if a==0 and b==0:
        break
    print(int(c/6))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

flag=True
while flag == True:
    N,X = map(int,input().split())
    if N==0 and X==0:
        exit()

    seq = (i for i in range(1,N+1))
    ptr = list(itertools.combinations(seq,3)) # 組み合わせ列挙
    #print(ptr)

    ans=0
    for i in ptr:
        if sum(i) == X:
            ans+=1

    print(ans)

Submission status: Accepted

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

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

  count = 0
  for 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:
if __name__ == '__main__':
    N = []
    X = []
    M = 0
    while True:
        n, x = map(int, input().split())
        if n==0 and x==0:
            break
        N.append(n)
        X.append(x)
        M += 1
    
    for i in range(M):
        num_size = N[i]
        target = X[i]
        cnt = 0
        for j in range(1, num_size+1):
            for k in range(j+1, num_size+1):
                l = target-(j+k)
                if j<l<k:
                    cnt += 1
        print(cnt)

Submission status: Accepted

Solution code:
#関数リスト
import sys
input = sys.stdin.readline


def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))

def main():
    while True:
        n, x = MI()
        if n == 0 and x == 0:
            exit()
        result = 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:
                    result += 1
        print(result)

if __name__ == "__main__":
    main()

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,x//3):
            a=i
            for j in range(i+1,(x-a)//2+1):
                b=j
                c=x-(a+b)
                if c<=n and a<b<c:
                    cnt+=1
        print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

while True:
    n,x = LI()
    cnt = 0
    if n == x == 0:
        break
    for b in range(2,n):
        for a in range(1,b):
            for c in range(b+1,n+1):
                if a+b+c == x:
                    cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
while True:
    count = 0
    n, x = map(int, input().split())
    #終了条件
    if n == 0 and x == 0:
        break
    #小さい順にa, b, cとし, 全通り確認する
    for a in range(1, n-1):
        for b in range(a+1, n):
            c = x - a - b
            if b < c <= n:
                count += 1           
    print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

for n, x in nx_list:
    if n == 0 and x == 0:
        break

    targets = range(1, n + 1)
    c = itertools.combinations(targets, 3)

    count = 0
    for i in c:
        if sum(i) == x:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
l=[]
while True:
  e = list(map(int,input().split()))
  if e==[0, 0]:
    break
  l.append(e)

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

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
h=0
while (n>0 or x>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):
                    if (not i==l):
                        if (not i==k):
                            if (not l==k):
                                h+=1
    print(h)
    h=0
    n,x=map(int,input().split())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if (n, x) == (0, 0): break
    ans = []
    for i in range(n, 1, -1):
        for j in range(1, n):
            tmp = x-(i+j)
            if tmp > n: continue
            if tmp > 0 and i > 0 and j > 0:
                if tmp != j and tmp != i and i != j:
                    pmt = sorted([i, j, tmp])
                    if not pmt in ans: ans.append(pmt)
    print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

    print(y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    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+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):
    ans = 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+1):
            c = x-a-b
            if c <= n and c > b:
                ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


while 1:
    n , x =map( int,input().split() )
    count = 0
    if (n,x)==(0,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:
    a, b = map(int, input().split())
    if a == 0 and b == 0: break
    cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))
    

# def sum_num_is_x(n, x):
#     seen = set()
#     for a in range(1, n+1):
#         for b in range(1, n+1):
#             for c in range(1, n+1):
#                 if a != b and a != c and b != c:
#                     if a + b + c == x:
#                         k = tuple(sorted([a,b,c]))
#                         seen.add(k)
#     return len(seen)

from itertools import combinations


def sum_num_is_x(n, x):
    return len([row for row in combinations(range(1, n+1), 3) if sum(row)==x])

def Input():
    while True:
        n, x = mapt(int, input().split(" "))
        if n == x == 0: break
        print(sum_num_is_x(n, x))

Input()

Submission status: Accepted

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

    ans = 0
    for i in numbers:
        for j in numbers:
            if j <= i:
                continue
            k = x - (i + j)
            if j < k and k <= n:
                ans += 1
    print(ans)

Submission status: Accepted

Solution code:
#
# 7b
#

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
n_ = []
x_ = []
while True:
    n,x = inputlist()
    if n == 0 and x == 0:
        break
    n_.append(n)
    x_.append(x)
for i in range(len(n_)):
    n = n_[i]
    x = x_[i]
    tmp = 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:
                    tmp +=1
    print(tmp)

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, 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:
import math

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools

while True:
    # 標準入力を取得
    n, x = list(map(int, input().split()))

    # n, xがともに0のとき終了
    if (n == 0) and (x == 0):
        break

    # 求解処理
    ans = 0
    for i, j, k in itertools.combinations(range(1, n + 1), r=3):
        if i + j + k == x:
            ans += 1

    # 結果出力
    print(ans)

Submission status: Accepted

Solution code:
count = 0
tmp = 0

while True:

    n, x = (int(x) for x in input().split())


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

    else :

        for i in range(n,2,-1):
            for j in range(i-1,1,-1):
                for k in range(j-1,0,-1):
                    tmp = i+j+k

                    if (x == tmp):
                        count += 1

                    else :
                        continue

        print(count)
        count = 0

Submission status: Accepted

Solution code:
while True:
    n , x = [int(x) for x in input().split()]
    if (n , x)==(0 , 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:
import itertools as it
while True:
    N,M=map(int,input().split())
    if N==0 and M==0:
      break
    ans=0
    for i in it.combinations(range(1,N+1),3):
      if sum(i)==M:
        ans+=1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    S=0
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    for i in range(a):
        X=a-i
        for j in range(X-1):
            Y=(X-1)-j
            for k in range(X-2):
                Z=(X-2)-k-j
                if X>0 and Y>0 and Z>0:
                    A=X+Y+Z
                    if A==b:
                        S=S+1
                    
    print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    else:
        a=[i+1 for i in range(n)]                
        b=0
        #c=math.factorial(n)/(6*math.factorial(n-3))
        #for i in range(c):
        for pair in itertools.combinations(a, 3):

                #print(pair)
                #print(sum(pair))

                if sum(pair)==m:
                    b+=1
        print(b)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
while True:
    data = sys.stdin.readline().strip().split(' ')
    n = int(data[0])
    x = int(data[1])
        
    if n == 0 and x == 0:
        break
    
    add = 0
    for i in itertools.combinations(range(1,n + 1),3):
        if sum(i) == x:
            add += 1
    print(add)

Submission status: Accepted

Solution code:
while(True):
  n,x=(int(a) for a in input().split())
  if n==0 and x==0:
    break
  if x-3<3:
    print('0')
    continue

  if x-3>n:
    start=n
  else:
    start=x-3

  count=0
  for i in range(start,2,-1):
    for j in range(i-1,1,-1):
      if i+j>=x:
        continue
      for k in range(j-1,0,-1):
        if i+j+k>x:
          continue
        elif i+j+k==x:
          count+=1
  print(count)

Submission status: Accepted

Solution code:
for i in range(10**8):
    n,x = map(int,input().split())
    if n==0 and x==0:
        exit()
    cou = 0
    for j in range(1,n-1):
        for t in range(j+1,n):
            for p in range(t+1,n+1):
                if j+t+p==x:
                    cou += 1
    print(cou)

Submission status: Accepted

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

for n,x in l:
    ans=0
    for h in range(1,n-1):
        for i in range(h+1,n):
            for k in range(i+1,n+1):
                if h+i+k==x: ans+=1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    listx=[]
    for j in range(1,n-1):
        for k in range(2,n):
            if k<=j:
                continue
            for l in range(3,n+1):
                if l<=k or l<=j:
                    continue
                if j+k+l==x:
#                    print(j,k,l)
                    jkllist=[j,k,l]
                    jkllist.sort()
                    listx.append(jkllist)
#    print(listx)
    print(format(len(listx),'.0f'))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import math

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

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

Submission status: Accepted

Solution code:
while True:
    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):
            target = x - (i+j)
            if j+1 <= target <= n:
                count += 1
    print(count)