Buggy python submission (verdict: Time Limit Exceeded):
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            if st > L[j+1]:
                m2 = 0
            else:
                m2 = bisect_right(L[j+1:],st)
            c += max(0,m1-m2)
print (c)

Fixed submission:
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            c += max(0,m1)
print (c)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            m1 = bisect_right(L[j+1:],lg)
            m2 = bisect_left(L[j+1:],st)
            c += max(0,m1-m2)
print (c)

Fixed submission:
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            c += max(0,m1)
print (c)

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

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):
        lg = L[i] + L[j] - 0.5
        st = L[j] - L[i] + 0.5
        m2 = bisect_left(L[j+1:],st)
        m1 = bisect_right(L[j+1:],lg)
        c += max(0,m1-m2)
print (c)

Fixed submission:
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            c += max(0,m1)
print (c)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j] - 0.5
        st = L[j] - L[i] + 0.5
        m2 = bisect_left(L[j+1:],st)
        m1 = bisect_right(L[j+1:],lg)
        c += max(0,m1-m2)
print (c)

Fixed submission:
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            c += max(0,m1)
print (c)

Buggy python submission (verdict: Time Limit Exceeded):
import math
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):
        lg = L[i] + L[j]
        st = L[j] - L[i]

        BL = j + 1
        BH = n - 1

        if L[BL] >= lg or L[BH] <= st:
            continue

        if L[BH] < lg:
            m1 = BH
        else:
            m1 = math.ceil((BL + BH) / 2)
            while True:
                if L[m1] >= lg:
                    BH = m1 - 1
                else:
                    BL = m1
                if BH <= BL:
                    m1 = BH
                    break
                m1 = math.ceil((BH + BL)/2)

        BL = j + 1
        BH = n - 1
        if L[BL] > st:
            m2 = BL
        else:
            m2 = (BL + BH) // 2
            while True:
                if L[m2] <= st:
                    BL = m2 + 1
                else:
                    BH = m2
                if BH <= BL:
                    m2 = BL
                    break
                m2 = (BH + BL) // 2

        c += max(0,m1-m2+1)


print (c)

Fixed submission:
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            c += max(0,m1)
print (c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int,input().split()))
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if L[i] + L[j] > L[k] and abs(L[i] - L[j]) < L[k]:
                c += 1
print (c)

Fixed submission:
import math
from bisect import bisect_right
from bisect import bisect_left

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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            c += max(0,m1)
print (c)