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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

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

L=sorted(L, reverse=True)
count=0
for i in range(0, N-2):
    stop_count = 0
    for j in range(i+1, N-1):
        for k in range(N-1, j, -1):
            if L[i] < L[j] + L[k]:
                count+=k-j
                break


print(count)

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

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

L=sorted(L, reverse=True)
count=0
for i in range(0, N-2):
    stop_count = 0
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            #print(i, j, k)
            if L[i] < L[j] + L[k]:
                count+=1
                stop_count=1
        if stop_count==0:
            break


print(count)

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

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

L=sorted(L, reverse=True)


count=0
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):

            if L[i] < L[j] + L[k]:
                count+=1
print(count)

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N=int(input())
lst=list(map(int, input().split()))

#max wo erabu

lst=sorted(lst, reverse=True)
count=0
for i in range(N-2):
    for pair in itertools.combinations(lst[i+1:], 2):
        if sum(pair)>lst[i]:
            count+=1

print(count)



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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N=int(input())
lst=list(map(int, input().split()))

#max wo erabu

lst=sorted(lst, reverse=True)
count=0
for i in range(N-2):
    for pair in itertools.combinations(lst[i+1:], 2):
        if sum(pair)>lst[i]:
            count+=1

print(count)



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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)