Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
t=0
for i in range(N):
    for j in range(i+1,N):
        if 2*L[j]<L[i]:
            break
        for k in range(j+1,N):
            if L[i]<L[j]+L[k]:
                t+=1
            else:
                break

print(t)


Fixed submission:
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        c=bisect_left(L,l)
        ans+=max(0,c-j-1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
L.append(0)
L.sort(reverse=True)
t=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]<L[j]+L[k]:
                t+=1
            else:
                break

print(t)


Fixed submission:
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        c=bisect_left(L,l)
        ans+=max(0,c-j-1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
t=0
for i in range(N-2):
    for j in range(i+1,N-1):
        if L[i]<L[j]+L[N-1]:
            t+=N-1-j
        elif L[i]>=L[j]+L[j+1]:
            t+=0
        else:
            l=j+1
            h=N-1
            c=int((l+h)/2)
            while L[i]>L[j]+L[c] or L[i]<L[j]+L[c+1]:
                if L[i]>=L[j]+L[c]:
                    h=c
                    c=int((c+l)/2)
                elif L[i]<=L[j]+L[c+1]:
                    l=c
                    c=int((h+c)/2)
                print(c)
            t+=N-1-c

print(t)


Fixed submission:
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        c=bisect_left(L,l)
        ans+=max(0,c-j-1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
t=0
for i in range(N-2):
    for j in range(i+1,N-1):
        if L[i]<L[j]+L[N-1]:
            t+=N-1-j
        elif L[i]>=L[j]+L[j+1]:
            t+=0
        else:
            c=int((2*N-2-j)/2)
            while L[i]>L[j]+L[c] or L[i]<L[j]+L[c+1]:
                if L[i]<=L[j]+L[c]:
                    c=int((c+N-1-j)/2)
                elif L[i]>=L[j]+L[c+1]:
                    c=int((N-1+c)/2)
                print('c')
            t+=N-1-c

print(t)


Fixed submission:
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        c=bisect_left(L,l)
        ans+=max(0,c-j-1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
L.append(0)
L.sort(reverse=True)
t=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]<L[j]+L[k]:
                t+=1

print(t)


Fixed submission:
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        c=bisect_left(L,l)
        ans+=max(0,c-j-1)
print(ans)