Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
total = 0
def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok


for i in range(N):
  for j in range(i + 1, N):
    a = L[i] - L[j]
    total += max(bisect_left_reverse(L, a) - j - 1, 0)

print(total)


Fixed submission:
import sys
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))
L.sort()
total = 0
for i in range(N):
  for j in range(i + 1, N):
    a = L[i] + L[j]
    total += max(bisect_left(L, a) - j - 1, 0)

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)

comb=itertools.combinations(L,2)
comb=list(comb)
total=0
for c in comb:
    s = c[0] - c[1]
    for l in L:
        if(l > s and c[1] > l):
            total+=1
print(total)

Fixed submission:
import sys
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))
L.sort()
total = 0
for i in range(N):
  for j in range(i + 1, N):
    a = L[i] + L[j]
    total += max(bisect_left(L, a) - j - 1, 0)

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
total=0
large=L.pop(0)
def func(lst, value):
   tmp = [i for i, x in enumerate(lst) if x > value]
   return len(tmp)


while L != []:
    for n,i in enumerate(L[:]):
        s = large - i
        length=func(L[n+1:],s)
        if(length==0):
            large=L.pop(0)
            break
        else:
            total+=length
    
print(total)

Fixed submission:
import sys
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))
L.sort()
total = 0
for i in range(N):
  for j in range(i + 1, N):
    a = L[i] + L[j]
    total += max(bisect_left(L, a) - j - 1, 0)

print(total)

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

p=itertools.combinations(L,3)
total=0
for e in p:
    a=e[0]
    b=e[1]
    c=e[2]
    if(a < b + c and b < c + a and c < a + b):
        total+=1
print(total)


Fixed submission:
import sys
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))
L.sort()
total = 0
for i in range(N):
  for j in range(i + 1, N):
    a = L[i] + L[j]
    total += max(bisect_left(L, a) - j - 1, 0)

print(total)

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

p=itertools.permutations(L,3)
total=0
for e in p:
    a=e[0]
    b=e[1]
    c=e[2]
    if(a < b + c and b <c + a and c < a + b):
        total+=1
print(total//6)

Fixed submission:
import sys
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))
L.sort()
total = 0
for i in range(N):
  for j in range(i + 1, N):
    a = L[i] + L[j]
    total += max(bisect_left(L, a) - j - 1, 0)

print(total)