Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        left = j
        right = N
        v = L[i] + L[j]
        while right - left > 1:
            mid = (left + right) // 2
            if L[mid] < v:
                left = mid
            else:
                right = mid
        cnt += left - j
print(cnt)


Fixed submission:
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        v = bisect.bisect_left(L, a + b)
        cnt += v - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        left = j
        right = N
        v = L[i] + L[j]
        while right - left > 1:
            mid = (left + right) // 2
            if L[mid] < v:
                left = mid
            else:
                right = mid
        cnt += left - j
print(cnt)


Fixed submission:
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        v = bisect.bisect_left(L, a + b)
        cnt += v - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        v = L[i] + L[j]
        left = j + 1
        right = n
        while left < right:
            mid = (left + right) // 2
            if L[mid] == v:
                cnt += mid - 1 - j
                break
            elif L[mid] > v:
                right = mid
            else:
                left = mid + 1
        else:
            if left == n:
                cnt += n - 1 - j
            elif L[left] < v:
                cnt += left - j
            else:
                cnt += left - 1 - j
print(cnt)


Fixed submission:
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        v = bisect.bisect_left(L, a + b)
        cnt += v - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n, *x = map(int, open(0).read().split())
y = sorted(x)[::-1]
cnt = 0
for i in range(n - 2):
    a = y[i]
    for j in range(i + 1, n - 1):
        b = y[j]
        c = j + 1
        while c < n and a < b + y[c]:
            cnt += 1
            c += 1
print(cnt)


Fixed submission:
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        v = bisect.bisect_left(L, a + b)
        cnt += v - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n, *x = map(int, open(0).read().split())
y = sorted(x)[::-1]
cnt = 0
for i in range(n - 2):
    a = y[i]
    for j in range(i + 1, n - 1):
        b = y[j]
        for k in range(j + 1, n):
            c = y[k]
            if a < b + c:
                cnt += 1
            else:
                break
print(cnt)

Fixed submission:
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        v = bisect.bisect_left(L, a + b)
        cnt += v - j - 1
print(cnt)