Buggy python submission (verdict: Time Limit Exceeded):
def dfs(i, j, s):
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        dfs(k, j + 1, s + k)

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

    for i in range(1, n + 1):
        dfs(i, 1, i)

print(sum(ans))


Fixed submission:
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            if i + j < x < i + 2 * j:
                result += 1
    return str(result)

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

print("\n".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
def dfs(i, j, s):
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        if s + k > x:
            break
        dfs(k, j + 1, s + k)

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

    for i in range(3, n + 1):
        dfs(i, 1, i)

print(sum(ans))


Fixed submission:
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            if i + j < x < i + 2 * j:
                result += 1
    return str(result)

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

print("\n".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
def dfs(i, j, s):
    if j > 3:
        return
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        dfs(k, j + 1, s + k)

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

    for i in range(1, n + 1):
        dfs(i, 1, i)

    print(sum(ans))


Fixed submission:
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            if i + j < x < i + 2 * j:
                result += 1
    return str(result)

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

print("\n".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
def dfs(i, j, s):
    if j > 3:
        return
    if j == 3 and sum(s) == x:
        res.append(1)

    for k in range(1, i):
        if k not in s:
            dfs(k, j + 1, s + [k])

ans = []
while True:
    res = []
    n, x = map(int, input().split())
    if n == x == 0:
        break
    for i in range(3, n + 1):
        dfs(i, 1, [i])

    ans.append(sum(res))

print("\n".join(map(str, ans)))


Fixed submission:
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            if i + j < x < i + 2 * j:
                result += 1
    return str(result)

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

print("\n".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
def dfs(i, j, s):
    if j > 3:
        return
    if j == 3 and sum(s) == x:
        res.append(1)

    for k in range(1, i):
        if sum(s) + k > x:
            break
        if k not in s:
            dfs(k, j + 1, s + [k])

ans = []
while True:
    res = []
    n, x = map(int, input().split())
    if n == x == 0:
        break
    for i in range(3, n + 1):
        dfs(i, 1, [i])

    ans.append(sum(res))

print("\n".join(map(str, ans)))


Fixed submission:
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            if i + j < x < i + 2 * j:
                result += 1
    return str(result)

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

print("\n".join(ans))