Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
count = 0
l.sort()
print(l)
'''
def binary_search(key,l,n):
    key_number = int((n-1)//2)
    L = 0
    R = n-1
    while True:
        if l[key_number] < key:
            L = key_number
            key_number = (L+R)//2
        else:
            R = key_number
            key_number = (L+R)//2
        if key == l[key_number]:
            return key_number
        if (R-L) == 1:
            return L+1
'''
def binary_search(key,l,n):
    L = 0
    R = n-1
    while L < R:
        key_number = int((n-1)//2)
        if l[key_number] < key:
            L = key_number + 1
        else:
            R = key_number
    return key_number

for i in range(n-2):
    for j in range(i+1,n-1):
        double_count = 0
        a = l[i]
        b = l[j]
        key_numberR = binary_search(a+b,l,n)
        key_numberL = binary_search(b-a,l,n)
        print("{} <c< {} b-a = {} a+b = {}".format(key_numberL,key_numberR,b-a,a+b))

        if key_numberL<= i and i<=key_numberR:
            double_count += 1
        if key_numberL<= j and j <= key_numberR:
            double_count += 1

        #print('i={} j={} key_numberL={} key_numberR={} count={}'.format(i,j,key_numberL,key_numberR,-key_numberL-double_count))
        count += key_numberR-key_numberL-double_count
print(count)

Fixed submission:
import bisect
n = int(input())
l = list(map(int,input().split()))
count = 0
l.sort()

def binary_search(key,l,n):
    key_number = int((n-1)//2)
    L = 0
    R = n-1
    while True:
        if l[key_number] < key:
            L = key_number
            key_number = (L+R)//2
        else:
            R = key_number
            key_number = (L+R)//2

        if key == l[key_number]:
            return key_number
        if (R-L) == 1:
            return L+1

def binary_search(key,l,n):
    L = 0
    R = n-1
    while L < R:
        key_number = int((n-1)//2)
        if l[key_number] < key:
            L = key_number + 1
        else:
            R = key_number
    return key_number

ans = 0
#print(binary_search(7+8,l,n))

for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]

        ans += bisect.bisect_left(l,a+b)- j -1

        #print("{} <c< {} b-a = {} a+b = {}".format(key_numberL,key_numberR,b-a,a+b))

        #print('i={} j={} key_numberL={} key_numberR={} count={}'.format(i,j,key_numberL,key_numberR,-key_numberL-double_count))
        #count += key_numberR-key_numberL-double_count
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

l = list(map(int,input().split()))
l.sort()
ans = [1 for a in range(n-2) for b in range(a+1,n-1) for c in range(b+1,n) if l[a]+l[b]>l[c] and l[b]+l[c]>l[a] and l[c]+l[b]>l[a]]
print(sum(ans))


Fixed submission:
import bisect
n = int(input())
l = list(map(int,input().split()))
count = 0
l.sort()

def binary_search(key,l,n):
    key_number = int((n-1)//2)
    L = 0
    R = n-1
    while True:
        if l[key_number] < key:
            L = key_number
            key_number = (L+R)//2
        else:
            R = key_number
            key_number = (L+R)//2

        if key == l[key_number]:
            return key_number
        if (R-L) == 1:
            return L+1

def binary_search(key,l,n):
    L = 0
    R = n-1
    while L < R:
        key_number = int((n-1)//2)
        if l[key_number] < key:
            L = key_number + 1
        else:
            R = key_number
    return key_number

ans = 0
#print(binary_search(7+8,l,n))

for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]

        ans += bisect.bisect_left(l,a+b)- j -1

        #print("{} <c< {} b-a = {} a+b = {}".format(key_numberL,key_numberR,b-a,a+b))

        #print('i={} j={} key_numberL={} key_numberR={} count={}'.format(i,j,key_numberL,key_numberR,-key_numberL-double_count))
        #count += key_numberR-key_numberL-double_count
print(ans)