Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = sorted(list(map(int,input().split())))
 
count = 0 
 
for i in range(n - 2):
    for j in range(i+1,n-1):
        
        if l[i] + l[j] > l[n-1]:
            count += n-j-1
            
            continue
        
        low = j+1
        high = n-1
        
        while low < high:
            
            mid = (low + high)//2
            
            if l[i] + l[j] > l[mid]:
                
                low = mid +1
            
            else:    
                
                high = mid 
        else:
            
            count += low - j -1
print(count)            

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

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

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

#print(l)
co=0
for i in range(n-2):
    c=l[i]
    x=0
    for j in range(i+1,n-1):
        b=l[j]
        for k in range(j+1,n):
            a=l[k]
            if c<(a+b):
                co+=1
            else:
                if k==j+1:
                    x=1
                break
        if x==1:
            break

print(co)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

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

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

check_i = 0
check_j = 0
count = 0 

for i in reversed(range(0,n)):
    if l[i] == check_i:
        check_i = l[i]
        continue
    
    for j in reversed(range(1,i)):
        
        if l[j] == check_j:
            check_j = l[j]
            continue
        
        
        
        if l[i] - l[j] >= l[j-1]:
            continue
        
        low = 0
        high = j-1
        
        while low < high:
            
            mid = (low + high)//2
            
            if l[i] - l[j] >= l[mid]:
                
                low = mid +1
            
            else:    
                
                high = mid
        else:
            
            count += len(set(l[low:j]))
print(count)            

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

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

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

check_i = 0
check_j = 0
count = 0 

for i in reversed(range(0,n)):
    if l[i] == check_i:
        check_i = l[i]
        continue
    
    for j in reversed(range(1,i)):
        
        if l[j] == check_j:
            check_j = l[j]
            continue
        
        if l[i] - l[j] >= l[j-1]:
            continue
        
        low = 0
        high = j-1
        
        while low < high:
            
            mid = (low + high)//2
            
            if l[i] - l[j] >= l[mid]:
                
                low = mid +1
            
            else:    
                
                high = mid
        else:
            
            count += len(set(l[low:j]))
print(count)            

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

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

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

n = int(input())
l = list(map(int,input().split()))


a = list(itertools.combinations(l, 3))
b = []

for i in a:
    b.append(tuple(sorted(i)))

c = list(set(b))

count = 0

for i in c:
    if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[0] + i[1]:
        count += 1

print(count)        

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

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