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,raw_input().split())
    if n == 0 and x == 0:
        break
    num = 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:
                    num += 1
    print num

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

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

Submission status: Accepted

Solution code:
while 1:
    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 += 1
    print(count)

Submission status: Accepted

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

  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 and n2 != n3 and n3 != n1:
          if n1+n2+n3 == x:
            cnt += 1

  print(cnt)

Submission status: Accepted

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

    hoge = range(1, n + 1)

    data = []
    for x in range(0, n - 2):
        for y in range(x + 1, n - 1):
            for z in range(y + 1, n):
                s = hoge[x] + hoge[y] + hoge[z]
                if s == m:
                    data.append(s)

    print(len(data))

Submission status: Accepted

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

    hoge = range(1, n + 1)

    data = []
    for x in range(n - 1, 1, -1):
        for y in range(x - 1, 0, -1):
            for z in range(y - 1, -1, -1):
                # print((x, y, z))
                s = hoge[x] + hoge[y] + hoge[z]
                if s < m:
                    break
                if s == m:
                    data.append(s)

    print(len(data))

Submission status: Accepted

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

    data = []
    for x in range(n, 2, -1):
        for y in range(x - 1, 1, -1):
            for z in range(y - 1, 0, -1):
                s = x + y + z
                if s < m:
                    break
                if s == m:
                    data.append(s)

    print(len(data))

Submission status: Accepted

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

    data = []
    for x in range(n, 2, -1):
        if 3 * x - 2 < m:
            break
        for y in range(x - 1, 1, -1):
            for z in range(y - 1, 0, -1):
                s = x + y + z
                if s < m:
                    break
                if s == m:
                    data.append(s)

    print(len(data))

Submission status: Accepted

Solution code:
def get_num(n, m):
    ans = 0
    for x in range(n, 2, -1):
        if 3 * x - 2 < m:
            return ans
        for y in range(x - 1, 1, -1):
            if x + 2 * y - 1 < m:
                break
            for z in range(y - 1, 0, -1):
                s = x + y + z
                if s == m:
                    ans += 1
    return ans


while True:
    [n, m] = [int(x) for x in raw_input().split()]
    if [n, m] == [0, 0]:
        break
    print(get_num(n, m))

Submission status: Accepted

Solution code:
def get_num(n, m):
    ans = 0
    for x in range(n, 2, -1):
        if 3 * x - 2 < m:
            return ans
        for y in range(x - 1, 1, -1):
            if x + 2 * y - 1 < m:
                break
            for z in range(y - 1, 0, -1):
                s = x + y + z
                if s == m:
                    ans += 1
                    break 
    return ans


while True:
    [n, m] = [int(x) for x in raw_input().split()]
    if [n, m] == [0, 0]:
        break
    print(get_num(n, m))

Submission status: Accepted

Solution code:
def get_num(n, m):
    ans = 0
    for x in range(min(n, m), (m + 2) / 3, -1):
        for y in range(x - 1, 1, -1):
            if x + 2 * y - 1 < m:
                break
            for z in range(y - 1, 0, -1):
                s = x + y + z
                if s == m:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(n3 - 1, 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                s = n1 + n2 + n3
                if s == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x == 0:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                s = n1 + n2 + n3
                if s == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x == 0:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                s = n1 + n2 + n3
                if s < x:
                    break
                elif s == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x == 0:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x == 0:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        data.append(0)
        # print(0)
    else:
        data.append(get_num(n, x))
        # print(get_num(n, x))

for n in data:
    print(n)

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(n2 - 1, 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        data.append(0)
        # print(0)
    else:
        data.append(get_num(n, x))
        # print(get_num(n, x))

for n in data:
    print(n)

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        data.append(0)
        # print(0)
    else:
        data.append(get_num(n, x))
        # print(get_num(n, x))

for n in data:
    print(n)

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in range(min(n, x), (x + 2) / 3, -1):
        for n2 in range(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1):
            for n1 in range(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


# data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        # data.append(0)
        print(0)
    else:
        # data.append(get_num(n, x))
        print(get_num(n, x))

# for n in data:
#     print(n)

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


# data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x-3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n3 == x - n1 - n2:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 2), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n3 == x - n1 - n2:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n3 == x - n1 - n2:
                    ans += 1
                    break
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        # print(0)
        data.append(0)
    else:
        # print(get_num(n, x))
        data.append(get_num(n, x))
for n in data:
    print(n)

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n3 == x - n1 - n2:
                    ans += 1
                    break
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), x - n3 - n2 - 1, -1):
                if n3 == x - n1 - n2:
                    ans += 1
                    break
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            if n3 + min(n2 - 1, x - n3 - n2):
                ans += 1
            # for n1 in xrange(min(n2 - 1, x - n3 - n2), x - n3 - n2 - 1, -1):
            #     if n3 == x - n1 - n2:
            #         ans += 1
            #         break
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            # if n3-1 > x-n3-1:
            #     # print("fizz")
            #     pass
            # else:
            #     print("buzz")
            if n3 + min(n2 - 1, x - n3 - n2):
                ans += 1
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            if n3 + min(n2 - 1, x - n3 - n2):
                ans += 1
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    # if x < 3:
    #     print(0)
    # else:
    print(get_num(n, x))

Submission status: Accepted

Solution code:
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            if n3 + min(n2 - 1, x - n3 - n2):
                ans += 1
    return ans

while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    print(get_num(n, x))

Submission status: Accepted

Solution code:
while True:
    n, x = [int (x) for x in 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+1):
            for c in range(b+1,n+1):
                if a+b+c == x: count += 1
    print("%d" % count)

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:
from itertools import combinations

if __name__ == '__main__':
    while True:
        # ?????????????????\???
        data = [int(x) for x in input().split(' ')]
        upper_limit = data[0]
        target_number = data[1]
        if upper_limit == 0 and target_number == 0:
            break

        # ????????????????????????
        choices = combinations(range(1, upper_limit+1), 3)

        # ????¨???????X????????´????????°????¢????????????????
        hit_count = 0
        for c in choices:
            # print(c)
            if sum(c) == target_number:
                hit_count += 1
        print(hit_count)

Submission status: Accepted

Solution code:
num_list = []
while True:
    values = [int(x) for x in input().split()]
    if 0 == values[0] and 0 == values[1]:
        break
    num_list.append(values)

for n, t in num_list:
    ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1))
    cnt = 0
    for x in ret.split():
        if str(t) == x:
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
num_list = []
while True:
    values = [int(x) for x in input().split()]
    if 0 == values[0] and 0 == values[1]:
        break
    num_list.append(values)

for n, t in num_list:
    ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1) if t == x + y + z)
    print(ret.count(str(t)))

Submission status: Accepted

Solution code:
num_list = []
while True:
    values = [int(x) for x in input().split()]
    if 0 == values[0] and 0 == values[1]:
        break
    num_list.append(values)

for n, t in num_list:
    ret = ''.join(str(1) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1) if t == x + y + z)
    print(ret.count(str(1)))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(sup,rest,digit,used1,used2):
    if rest<0:
        return 0
    if digit==0:
        if rest==0:
            return 1
        else:
            return 0
    sum=0
    for i in range(1,sup+1):
        if i!=used1 and i!=used2:
            if used1==0:
                sum+=solve(sup,rest-i,digit-1,i,used2)
            elif used2==0:
                sum+=solve(sup,rest-i,digit-1,used1,i)
            else:
                sum+=solve(sup,rest-i,digit-1,used1,used2)
    return sum

N=[]
X=[]
while True:
    n,x=map(int,raw_input().split())
    if (n,x)==(0,0):
        break
    N.append(n)
    X.append(x)
for i in range(len(N)):
    print('%d'%(solve(N[i],X[i],3,0,0)/6))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
while True:
    n,x = map(int, input().split())
    
    if n == x == 0:
        break

    count = 0
    
    for i in range(1,int(x/3)+1):
        for j in range(i+1,int((x-i)/2)+1):
            k = x - (i + j)
            if j < k <= n:
                count += 1
                
    print(count)

Submission status: Accepted

Solution code:
import sys

for i in sys.stdin:
    n,x = map(int,i.split())
    s = 0
    if n==0 and x==0:
      break
    if x <= 3*n-3 and x >= 6:
      for i in range(1,min(n-1,x//3)):
        s += len(range(max(i+1,x-i-n),min(n,(x-i+1)//2)))
    print(s)

Submission status: Accepted

Solution code:
while True:
    n,x = map(int,input().split())
    s = 0
    if n==0 and x==0:
      break
    if x <= 3*n-3 and x >= 6:
      for i in range(1,min(n-1,x//3)):
        s += len(range(max(i+1,x-i-n),min(n,(x-i+1)//2)))
    print(s)

Submission status: Accepted

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

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

    print(sum( [ len(range(max(i+1,x-i-n),min(n,(x-i+1)//2))) for i in range(1,min(n-1,x//3)) ]))

Submission status: Accepted

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

    if n==x==0: break

    print(sum( [ len(range(max(i+1,x-i-n),min(n,(x-i+1)//2))) for i in range(1,min(n-1,x//3)) ]))

Submission status: Accepted

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

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

    print(sum( [ max(min(n,(x-i+1)//2) - max(i+1,x-i-n),0) for i in range(1,min(n-1,x//3)) ]))

Submission status: Accepted

Solution code:
while True:
    n, x = map(int, input().split())
    if not n and not x:
        break
    li = []
    for i in range(1,x//3):
        y = x - i
        li.append((y-1)//2 - max(i, y-n-1))
    print(sum([comb for comb in li if comb > 0]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    c = 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:
                    c += 1
    print(c)

Submission status: Accepted

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


    count = 0
    for i in range(1,n-1):
        for j in range(i+1, n):
            """
            # ?????????????????¨???????????????????????????????????§k???x-(i+j)??§?¨?????????????
            # ?????????k????????????(j+1???n)?????????????????????OK???
            for k in range(j+1, n+1):
                if (i+j+k) == x:
                    #print(i, j, k)
                    count += 1
            """
            k = x - (i+j)
            if k < j+1: # k????°???????????????????????????´??????j??????????????§?¢?????????????????????????????????§break??????
                break
            if k <= n:
                count += 1
    print(count)

Submission status: Accepted

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

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

    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:
    a = 0
    n, x = [int(i) for i in input().split()]
    if n == x == 0:
        break

    s = 1
    m = s+1
    while not m == n:
        for e in range(m+1,n+1):
            result = s+m+e
            if result == x:
                a += 1
        m += 1
        if m == n:
            s += 1
            m = s+1

    print(a)

Submission status: Accepted

Solution code:
#coding:utf-8

while True:
	buff = [int(x) for x in input().split()]
	n = buff[0]
	m = buff[1]
	if n==m==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 (i+j+k)==m:
					ans+=1
	print(ans)

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:
def f(n,k):
    count = 0
    for x in range(1,n+1):
        for y in range(x,n+1):
            for z in range(y,n+1):
                if x + y + z == k:
                    if x != y and y != z and z != x:
                        count += 1
    return count

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
ITP-1_7-B
 ????????????????????°
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
????????????????????????????????????????????????????????°????????????????????????????????????
'''

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

    # EndCheck
    if n == x == 0:
        break

    ansCnt = 0
    for cnt1 in range(1,n+1):
        for cnt2 in range(cnt1+1,n+1):
            for cnt3 in range(cnt2+1,n+1):
                if cnt1 + cnt2 + cnt3 == x:
                    ansCnt += 1
                    break

    print(ansCnt)

Submission status: Accepted

Solution code:
import sys

for line in sys.stdin:
    n,x = map(int,line.split())
    if n==0 and x==0:
        break
    _range = list(range(1,n+1))
    conb = []
    for i in _range[::-1]:
        d = x - i
        if i - 1 <= 0:
            continue
        for j in _range[:i-1][::-1]:
            d2 = d - j
            if j - 1 <= 0:
                continue
            for k in _range[:j-1][::-1]:
                if d2 - k == 0:
                    conb.append((i,j,k))

    print(len(conb))

Submission status: Accepted

Solution code:
import sys

#fin = open("test.txt", "r")
fin = sys.stdin

while True:
	[n, x] = list(map(int, fin.readline().split()))

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

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

	print(counter)

Submission status: Accepted

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