Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for b in range(1, N - 1):
    for a in range(b):
        ans += bisect_left(L[b + 1:], L[a] + L[b])
        
print(ans)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for b in range(1, N - 1):
    for a in range(b):
        ans += bisect_left(L, L[a] + L[b]) - b - 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Triangles
from bisect import bisect_left
import numpy as np
N = int(input())
L = sorted(np.array(list(map(int, input().split()))))

ans = 0
for i, a in enumerate(L):
    if i == N - 2:
        break
        
    for j, b in enumerate(L[i + 1:]):
        j += i + 1
        if j == N - 1:
            break
            
        s = a + b
        ans += bisect_left(L[j + 1:], s)
                
print(ans)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for b in range(1, N - 1):
    for a in range(b):
        ans += bisect_left(L, L[a] + L[b]) - b - 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Triangles
import numpy as np
N = int(input())
L = sorted(np.array(list(map(int, input().split()))))

ans = 0
for i, a in enumerate(L):
    if i == N - 2:
        break
        
    for j, b in enumerate(L[i + 1:]):
        j += i + 1
        if j == N - 1:
            break
            
        s = a + b
        ans += np.count_nonzero(L[j + 1: ] < s)
                
print(ans)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for b in range(1, N - 1):
    for a in range(b):
        ans += bisect_left(L, L[a] + L[b]) - b - 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Triangles
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i, a in enumerate(L):
    if i == N - 2:
        break
        
    for j, b in enumerate(L[i + 1:]):
        j += i + 1
        if j == N - 1:
            break
            
        s = a + b
        for k, c in enumerate(L[j + 1:]):
            k += j + 1
            if c < a + b:
                ans += 1
            else:
                break
                
print(ans)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for b in range(1, N - 1):
    for a in range(b):
        ans += bisect_left(L, L[a] + L[b]) - b - 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Triangles
N = int(input())
L = sorted(list(map(int, input().split())))

ans = []
for i, a in enumerate(L):
    if i == N - 2:
        break
        
    for j, b in enumerate(L[i + 1:]):
        j += i + 1
        if j == N - 1:
            break
            
        s = a + b
        for k, c in enumerate(L[j + 1:]):
            k += j + 1
            if c < a + b:
                ans.append((a, b, c))
            else:
                break
                
print(len(ans))

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for b in range(1, N - 1):
    for a in range(b):
        ans += bisect_left(L, L[a] + L[b]) - b - 1
        
print(ans)