Buggy python submission (verdict: Time Limit Exceeded):
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
lis.append(inf)
ans = 0
for i in range(n-2):
    a = lis[i]
    for j in range(i + 1, n-1):
        b = lis[j]
        l = j
        r = n
        while r > l+1:
            mid = (l+r) // 2
            if lis[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l - j
print(ans)

Fixed submission:
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
lis.append(inf)
ans = 0
for i in range(n-2):
    a = lis[i]
    for j in range(i + 1, n-1):
        b = lis[j]
        l = j
        r = n
        while r > l+1:
            mid = (l+r) // 2
            if lis[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l - j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
ans = 0
for i in range(n-1):
    a = lis[i]
    for j in range(i + 1, n):
        b = lis[j]
        nl = lis[j:]
        nl.append(inf)
        l = 0
        r = n-j
        while r > l+1:
            mid = (l+r) // 2
            if nl[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l
print(ans)

Fixed submission:
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
lis.append(inf)
ans = 0
for i in range(n-2):
    a = lis[i]
    for j in range(i + 1, n-1):
        b = lis[j]
        l = j
        r = n
        while r > l+1:
            mid = (l+r) // 2
            if lis[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l - j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
ans = 0
for i in range(n-1):
    a = lis[i]
    for j in range(i + 1, n):
        b = lis[j]
        nl = lis[j:] + [inf]
        l = 0
        r = n-j
        while r > l+1:
            mid = (l+r) // 2
            if nl[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l
print(ans)

Fixed submission:
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
lis.append(inf)
ans = 0
for i in range(n-2):
    a = lis[i]
    for j in range(i + 1, n-1):
        b = lis[j]
        l = j
        r = n
        while r > l+1:
            mid = (l+r) // 2
            if lis[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l - j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
ans = 0
for i in range(n-1):
    a = lis[i]
    for j in range(i + 1, n):
        b = lis[j]
        nl = lis[j:] + [inf]
        l = 0
        r = n-j
        while r > l+1:
            mid = (l+r) // 2
            if nl[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l
print(ans)

Fixed submission:
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
lis.append(inf)
ans = 0
for i in range(n-2):
    a = lis[i]
    for j in range(i + 1, n-1):
        b = lis[j]
        l = j
        r = n
        while r > l+1:
            mid = (l+r) // 2
            if lis[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l - j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
ans = 0
for i in range(n-1):
    a = lis[i]
    for j in range(i + 1, n):
        b = lis[j]
        nl = lis[j:] + [inf]
        l = 0
        r = len(nl) -1
        while r > l+1:
            mid = (l+r) // 2
            if nl[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l
print(ans)

Fixed submission:
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
lis.append(inf)
ans = 0
for i in range(n-2):
    a = lis[i]
    for j in range(i + 1, n-1):
        b = lis[j]
        l = j
        r = n
        while r > l+1:
            mid = (l+r) // 2
            if lis[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l - j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
ans = 0
for i in range(n-1):
    a = lis[i]
    for j in range(i + 1, n):
        b = lis[j]
        nl = [0] + lis[j+1:] + [inf]
        l = 0
        r = len(nl) -1
        while r > l+1:
            mid = (l+r) // 2
            if nl[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l
print(ans)

Fixed submission:
inf = 1001001001
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
lis.append(inf)
ans = 0
for i in range(n-2):
    a = lis[i]
    for j in range(i + 1, n-1):
        b = lis[j]
        l = j
        r = n
        while r > l+1:
            mid = (l+r) // 2
            if lis[mid] < a + b:
                l = mid
            else:
                r = mid
        ans += l - j
print(ans)