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

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        
        # if L[minInd]> L[i]+L[j]:
        #     continue
        # if MAX<L[i]+L[j]:
        #     count+=N-1-minInd+1
        # else:
        #     ind = bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
        #     count+=ind
        
        count+= bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
print(count)

Fixed submission:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)

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

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        
        # if L[minInd]> L[i]+L[j]:
        #     continue
        # if MAX<L[i]+L[j]:
        #     count+=N-1-minInd+1
        # else:
        #     ind = bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
        #     count+=ind
        
        ind = bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
        count+=ind
print(count)

Fixed submission:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)

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

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        if L[minInd]> L[i]+L[j]:
            continue
        if MAX<L[i]+L[j]:
            count+=N-1-minInd+1
        else:
            ind = bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
            count+=ind
        # print(count)
print(count)

Fixed submission:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)

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

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

MAX=L[-1]
count=0
for i,a in enumerate(L[:-2]):
    for  j,b in enumerate(L[i+1:-1]):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=i+1+j+1
        # print(minInd)
        if L[minInd]> a+b:
            continue
        if MAX<a+b:
            count+=N-1-minInd+1
        else:
            ind = bisect.bisect_left(L[minInd:], a+b) # number of < a+b
            count+=ind
        # print(count)
print(count)

Fixed submission:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def find_lt(a, x):
    'Find rightmost index less than x'
    i = bisect.bisect_left(a, x)
    if i:
        return i-1
    # raise ValueError
    return -1

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

count=0
for i,a in enumerate(L[:-2]):
    for  j,b in enumerate(L[i+1:-1]):
        minInd=i+1+j+1
        ind=find_lt(L[minInd:], a+b)
        count+=ind+1
print(count)

Fixed submission:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def find_lt(a, x):
    'Find rightmost index less than x'
    i = bisect.bisect_left(a, x)
    if i:
        return i-1
    # raise ValueError
    return -1

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

count=0
for i,a in enumerate(L):
    for  j,b in enumerate(L[i+1:]):
        minInd=i+1+j+1
        ind=find_lt(L[minInd:], a+b)
        count+=ind+1
print(count)

Fixed submission:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)

Buggy python submission (verdict: Time Limit Exceeded):

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

count=0
for i,a in enumerate(L):
    for  j,b in enumerate(L[i+1:]):
        MAX=N-1 # index
        MIN=i+1+j+1
        gap=MAX-MIN
        while gap>1:
            mid=(MAX+MIN)//2
            if L[mid] < a+b:
                MIN=mid
            else:
                MAX=mid
            gap=MAX-MIN
        if L[MAX]<a+b:
            count+=MAX-(i+1+j+1)+1
        elif L[MIN]<a+b:
            count+=MIN-(i+1+j+1)+1
print(count)

Fixed submission:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)

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

count=0
for i,a in enumerate(L):
    for  j,b in enumerate(L[i+1:]):
        for c in L[i+1+j+1:]:
            if a<b+c and b<a+c and c<a+b:
                count+=1
print(count)

Fixed submission:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)