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

n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-1, 1, -1):
    for j in range(i-1, 0, -1):
        S = L[:j]
        ans += j - bisect.bisect_right(S, L[i]-L[j])

print(ans)


Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

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

print(ans)

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

n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-1, 1, -1):
    for j in range(i-1, 0, -1):
        ans += j - bisect.bisect_right(L[:j], L[i]-L[j])

print(ans)


Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

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

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-1, 1, -1):
    for j in range(i-1, 0, -1):
        ans += j - bisect.bisect_right(L[:j], L[i]-L[j])

print(ans)

Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

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

print(ans)

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

n = int(input())
L = sorted(list(map(int, input().split())), reverse=True)

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        S = sorted(L[j+1:])
        ans += len(S) - bisect.bisect_right(S, L[i]-L[j])

print(ans)


Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
L = np.array(sorted(list(map(int, input().split()))))

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        m = L[j]-L[i]
        M = L[j]+L[i]
        res = L[j+1:]
        res_m = np.where(m < res, 1, 0)
        res_M = np.where(res >= M, 1, 0)
        ans += sum(res_m)-sum(res_M)

print(ans)


Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if L[j] - L[i] < L[k] < L[i] + L[j]:
                ans += 1
            elif L[k] >= L[i] + L[j]:
                break

print(ans)


Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = sorted(list(map(int, input().split())))

tri = []
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                tri.append((L[i], L[j], L[k]))
            elif L[k] >= L[i] + L[j]:
                break

print(len(set(tri)))


Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = sorted(list(map(int, input().split())))

tri = []
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                tri.append((L[i], L[j], L[k]))

print(len(set(tri)))


Fixed submission:
import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

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

print(ans)