Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = [ int(x) for x in sys.stdin.readline().strip().split() ]
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)


Fixed submission:
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = list(map(int,sys.stdin.readline().strip().split()))
    
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = [ int(x) for x in sys.stdin.readline().strip().split() ]
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)


Fixed submission:
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = list(map(int,sys.stdin.readline().strip().split()))
    
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = [ int(x) for x in sys.stdin.readline().strip().split() ]
l.sort()
c = 0
for i in range(n-1):
    for j in range(i+1,n-1):
        k = bisect_left(l,l[j]+l[i],lo=j)
        c += k-j-1
#
print(c)


Fixed submission:
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = list(map(int,sys.stdin.readline().strip().split()))
    
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = [ int(x) for x in sys.stdin.readline().strip().split() ]
l.sort()

c = 0
for i in range(1,n):
    for j in range(i+1,n):
        k = bisect_left(l,l[j]-l[i]+1,hi=i)
        if k==i: continue
        c += i-k
#
print(c)



Fixed submission:
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = list(map(int,sys.stdin.readline().strip().split()))
    
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

def search(a,x,offset=0,iend=None):
    n = len(a)
    if iend is None: iend = n
    assert 0<=offset<iend<=n

    n = iend - offset
    if a[iend-1]<x: return -1
    if n==1:
        assert a[offset]>=x
        return offset
    #
    mid = (n+1)//2 - 1 + offset
    mid1 = mid + 1
    
    if x<=a[mid]: return search(a,x,offset=offset,iend=mid1)
    else: return search(a,x,offset=mid1,iend=iend)
#
n = int(sys.stdin.readline().strip())
l = [ int(x) for x in sys.stdin.readline().strip().split() ]
l.sort()

c = 0
for i in range(1,n):
    for j in range(i+1,n):
        k = search(l, l[j]-l[i]+1, iend=i)
        if k<0: continue
        c += i-k
#
print(c)


Fixed submission:
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = list(map(int,sys.stdin.readline().strip().split()))
    
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

def search(a,x):
    if a[-1]<=x: return -1
    if len(a)==1:
        if a[0]>x: return 0
        else: return -1
    #
    mid = (len(a)+1)//2 - 1
    if x<a[mid]: return search(a[:mid+1],x)
    else: return mid + 1 + search(a[mid+1:],x)
        
    
n = int(sys.stdin.readline().strip())
l = [ int(x) for x in sys.stdin.readline().strip().split() ]
l.sort()

c = 0
for i in range(1,n):
    for j in range(i+1,n):
        k = search(l[:i], l[j]-l[i])
        if k<0: continue
        c += i-k
#
print(c)


Fixed submission:
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = list(map(int,sys.stdin.readline().strip().split()))
    
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)