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

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(l, item):

    if len(l) == 0 or l[0] <= item:
        return -1

    if item < l[-1]:
        return len(l) - 1

    list2 = [1001] + l + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2

        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:

            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1

    return -1


import heapq


N = int(input())
L = []
for l in map(int, input().split(' ')):
    heapq.heappush(L, l*(-1))

L = [heapq.heappop(L)*(-1) for _ in range(N)]
# L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L[:-2:]):
    for j, b in enumerate(L[i+1:-1:]):
        k = binary_search(L[i+j+2::], a-b)
        if k == -1:
            break
        result += k + 1


print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(l, item):

    if len(l) == 0 or l[0] <= item:
        return -1

    if item < l[-1]:
        return len(l) - 1

    list2 = [1001] + l + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2

        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:

            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1

    return -1


import heapq


N = int(input())
L = []
for l in map(int, input().split(' ')):
    heapq.heappush(L, l*(-1))

L = [heapq.heappop(L)*(-1) for _ in range(N)]
# L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L[:-2:]):
    for j, b in enumerate(L[i+1:-1:]):
        k = binary_search(L[i+j+2::], a-b)
        if k == -1:
            break
        result += k + 1


print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(l, item):

    if len(l) == 0 or l[0] <= item:
        return -1

    if item < l[-1]:
        return len(l) - 1

    list2 = [1001] + l + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2

        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:

            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1

    return -1


import heapq


N = int(input())
L = []
for l in map(int, input().split(' ')):
    heapq.heappush(L, l*(-1))

L = [heapq.heappop(L)*(-1) for _ in range(N)]
# L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1::]):
        k = binary_search(L[i+j+2::], a-b)
        if k == -1:
            break
        result += k + 1


print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(l, item):

    if len(l) == 0 or l[0] <= item:
        return -1

    if item < l[-1]:
        return len(l) - 1

    list2 = [1001] + l + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2

        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:

            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1

    return -1

N = int(input())
L = list(map(int, input().split(' ')))

L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1::]):
        k = binary_search(L[i+j+2::], a-b)
        if k == -1:
            break
        result += k + 1


print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(l, item):

    if len(l) == 0 or l[0] <= item:
        return -1

    if item < l[-1]:
        return len(l) - 1

    list2 = [1001] + l + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2

        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:

            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1

    return -1

N = int(input())
L = list(map(int, input().split(' ')))

L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1::]):
        k = binary_search(L[i+j+2::], a-b)

        result += k + 1


print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

Buggy python submission (verdict: Time Limit Exceeded):

def binary_search(list, item):

    if len(list) == 0 or list[0] <= item:
        return -1

    list2 = [1001] + list + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2

        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:

            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1

    return -1

N = int(input())
L = list(map(int, input().split(' ')))

L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1::]):
        k = binary_search(L[i+j+2::], a-b)

        result += k + 1


print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

Buggy python submission (verdict: Time Limit Exceeded):

def binary_search(list, item):

    if len(list) == 0 or item > list[-1]:
        return -1

    list2 = [1001] + list + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2
        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:
            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1


N = int(input())
L = list(map(int, input().split(' ')))

L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1::]):
        k = binary_search(L[i+j+2::], a-b)

        result += k + 1


print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

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

N = int(input())
L = map(int, input().split(' '))

hq = []
for l in L:
    heapq.heappush(hq, l*(-1))

result = 0
while hq:
    a = heapq.heappop(hq)

    hq1 = []
    while hq:
        b = heapq.heappop(hq)

        hq2 = []
        while hq:
            c = heapq.heappop(hq)
            hq2.append(c)

            if a > b + c:
                result += 1

            else:
                break

        hq1.append(b)
        for v in hq2:
            heapq.heappush(hq, v)

    for v in hq1:
        heapq.heappush(hq, v)

print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)

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

N = int(input())
L = map(int, input().split(' '))

hq = []
for l in L:
    heapq.heappush(hq, l*(-1))

result = 0
while hq:
    a = heapq.heappop(hq)

    hq1 = []
    while hq:
        b = heapq.heappop(hq)

        hq2 = []
        while hq:
            c = heapq.heappop(hq)
            heapq.heappush(hq2, c)

            if a > b + c:
                result += 1

            else:
                break

        heapq.heappush(hq1, b)
        while hq2:
            heapq.heappush(hq, heapq.heappop(hq2))

    while hq1:
        heapq.heappush(hq, heapq.heappop(hq1))

print(result)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)