Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            if L[i]+L[j]>L[k]:
                counter+=1
            else:
                break
print(counter)
    



Fixed submission:

N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(N-2):
    k=i+2
    for j in range(i+1,N-1):    
        while k < N and L[k] < L[i] + L[j]:
            k += 1
        counter += k - j -1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
import sys 
N=int(input())
L=list(map(int,sys.stdin.readline().split()))
counter=0
L.sort()
for i,A in enumerate(L[:-2]):
    for j,B in enumerate(L[i+1:-1],i+1):
        l=j
        r=len(L)-1
        c=(r+l)//2
        while abs(r-l)>1:    
            if A>abs(L[c]-B):
                b=c
                c=(r+c)//2
                l=b
            else:
                b=c
                c=(c+l)//2
                r=b
        if A-abs(L[l]-B)>0 and A-abs(L[r]-B)>0:
            c=r
        elif A-abs(L[l]-B)>0 and A-abs(L[r]-B)<0:
            c=l
        if A>abs(L[c]-B):
            counter+=c-j
print(counter)
    



Fixed submission:

N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(N-2):
    k=i+2
    for j in range(i+1,N-1):    
        while k < N and L[k] < L[i] + L[j]:
            k += 1
        counter += k - j -1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(len(L)):
    for j in range(i+1,len(L)-1):
        l=j
        r=len(L)-1
        c=(r+l)//2
        while abs(r-l)>1:    
            if L[i]>abs(L[c]-L[j]):
                b=c
                c=(r+c)//2
                l=b
            else:
                b=c
                c=(c+l)//2
                r=b
        if L[i]-abs(L[l]-L[j])>0 and L[i]-abs(L[r]-L[j])>0:
            c=r
        elif L[i]-abs(L[l]-L[j])>0 and L[i]-abs(L[r]-L[j])<0:
            c=l
        if L[i]>abs(L[c]-L[j]):
            counter+=c-j
print(counter)
    



Fixed submission:

N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(N-2):
    k=i+2
    for j in range(i+1,N-1):    
        while k < N and L[k] < L[i] + L[j]:
            k += 1
        counter += k - j -1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            if L[i]>abs(L[j]-L[k]):
                counter+=1
            else:
                break
print(counter)
    

Fixed submission:

N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(N-2):
    k=i+2
    for j in range(i+1,N-1):    
        while k < N and L[k] < L[i] + L[j]:
            k += 1
        counter += k - j -1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            if L[i]>abs(L[j]-L[k]):
                counter+=1
            else:
                break
print(counter)
    

Fixed submission:

N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(N-2):
    k=i+2
    for j in range(i+1,N-1):    
        while k < N and L[k] < L[i] + L[j]:
            k += 1
        counter += k - j -1
print(counter)