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

v = L[:]
v.sort()

res = 0

import bisect

for mid in range(N-1,-1,-1):
    a = v[mid]
    for low in range(mid-1,-1,-1):
        b = v[low]
        sup = a + b
        inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += max(low-iterI,0)

print(res)


Fixed submission:
N = int(input())
L = list(map(int,input().split()))

v = L[:]
v.sort()

res = 0

import bisect

for i in range(N-2):
    a = v[i]
    for j in range(i+1,N-1):
        b = v[j]
        sup = a + b
        #inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        #iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += iterS - (j+1)

print(res)

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

res = 0

for i in range(N-2):
    L1 = L[i+1:]
    a = L[i]
    for j in range(len(L1)-1):
        L2 = L1[j+1:]
        b = L1[j]
        sup = a + b
        inf = max(a-b,b-a)
        SL2 = set(L2)
        test = {x for x in range(inf+1,sup)}
        Scan = SL2 & test
        if len(Scan) == 0:
            break

        LScan = list(Scan)
        M = len(LScan)
        for c in LScan:
            res += L2.count(c)

print(res)


Fixed submission:
N = int(input())
L = list(map(int,input().split()))

v = L[:]
v.sort()

res = 0

import bisect

for i in range(N-2):
    a = v[i]
    for j in range(i+1,N-1):
        b = v[j]
        sup = a + b
        #inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        #iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += iterS - (j+1)

print(res)

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

res = 0

for i in range(N-2):
    L1 = L[i+1:]
    a = L[i]
    for j in range(len(L1)-1):
        L2 = L1[j+1:]
        b = L1[j]
        temp1 = max(L2)
        temp2 = min(L2)
        if temp2 >= a + b:
            break
        elif temp1 <= a - b:
            break
        elif temp1 <= b - a:
            break
        LS2 = list(set(L2))
        M2 = len(LS2)
        for k in range(M2):
            c = LS2[k]
            sum = a + b + c
            if (sum > 2*a) & (sum > 2*b) & (sum > 2*c):
                res += L2.count(c)

print(res)


Fixed submission:
N = int(input())
L = list(map(int,input().split()))

v = L[:]
v.sort()

res = 0

import bisect

for i in range(N-2):
    a = v[i]
    for j in range(i+1,N-1):
        b = v[j]
        sup = a + b
        #inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        #iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += iterS - (j+1)

print(res)

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

res = 0

for i in range(N-2):
    L1 = L[i+1:]
    a = L[i]
    for j in range(len(L1)-1):
        L2 = L1[j+1:]
        b = L1[j]
        temp1 = max(L2)
        temp2 = min(L2)
        if temp2 >= a + b:
            break
        elif temp1 <= a - b:
            break
        elif temp1 <= b - a:
            break
        for k in range(len(L2)):
            c = L2[k]
            sum = a + b + c
            if (sum > 2*a) & (sum > 2*b) & (sum > 2*c):
                res += 1

print(res)


Fixed submission:
N = int(input())
L = list(map(int,input().split()))

v = L[:]
v.sort()

res = 0

import bisect

for i in range(N-2):
    a = v[i]
    for j in range(i+1,N-1):
        b = v[j]
        sup = a + b
        #inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        #iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += iterS - (j+1)

print(res)

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

res = 0

for i in range(N-2):
    L1 = L[i+1:]
    for j in range(len(L1)-1):
        L2 = L1[j+1:]
        for k in range(len(L2)):
            sum = L[i] + L1[j] + L2[k]
            if (sum > 2*L[i]) & (sum > 2*L1[j]) & (sum > 2*L2[k]):
                res += 1

print(res)


Fixed submission:
N = int(input())
L = list(map(int,input().split()))

v = L[:]
v.sort()

res = 0

import bisect

for i in range(N-2):
    a = v[i]
    for j in range(i+1,N-1):
        b = v[j]
        sup = a + b
        #inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        #iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += iterS - (j+1)

print(res)