Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = sorted([int(i) for i in input().split()])

def count(ls, n):
    left = 0
    right = len(ls)
    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] < n: left = mid
        if ls[mid] >= n: right = mid

    return left

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += count(L, L[i]+L[j]) - j

print(ans)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L[j+1:], L[i]+L[j])

print(ans)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = sorted([int(i) for i in input().split()])

S = [0 for i in range(max(L)+1)]
for i in range(N):
    S[L[i]] += 1
for i in range(1, max(L)+1):
    S[i] += S[i-1]

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += S[min(L[i]+L[j]-1, max(L))] - S[L[j]]

print(ans)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = sorted([int(i) for i in input().split()], reverse=True)

def count(ls, n):
    left = 0
    right = len(ls)
    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] > n: left = mid
        if ls[mid] <= n: right = mid

    return left

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += count(L[j:], L[i]-L[j])

print(ans)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = sorted([int(i) for i in input().split()], reverse=True)

def count(l, m, ls):
    left = 0
    right = len(ls)
    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] > l-m: left = mid
        if ls[mid] <= l-m: right = mid

    return right - 1

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += count(L[i], L[j], L[j:])

print(ans)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = sorted([int(i) for i in input().split()], reverse=True)

def count(l, m, ls):
    if ls[0] <= l - m:
        return 0
    if ls[-1] > l - m:
        return len(ls)

    left = 0
    right = len(ls) - 1
    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] > l-m: left = mid
        if ls[mid] <= l-m: right = mid

    return left + 1

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += count(L[i], L[j], L[j+1:])

print(ans)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)