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

def main(N, L):
    L.sort(reverse=True)

    triangles = 0

    for i, P in enumerate(L):
        Q_list = copy.copy(L)
        del Q_list[:i + 1]
        for j, Q in enumerate(Q_list):
            if Q < P / 2:
                break
            minR = P - Q + 1
            R_list = copy.copy(Q_list)
            del R_list[:j + 1]
            R_list.reverse()
            triangles += len(R_list) - bisect.bisect_left(R_list, minR)

    print(triangles)

if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    main(N, L)


Fixed submission:
import copy
import bisect

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

triangles = 0

for i in range(N - 2):
    P = L[i]
    for j in range(i + 1, N - 1):
        Q = L[j]
        if P + Q <= L[j + 1]:
            continue
        maxR = P + Q - 1
        triangles += bisect.bisect_right(L, maxR) - (j + 1)

print(triangles)

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

def main(N, L):
    L.sort(reverse=True)

    triangles = 0

    for i, P in enumerate(L):
        Q_list = copy.copy(L)
        del Q_list[:i + 1]
        for j, Q in enumerate(Q_list):
            if Q < P / 2:
                break
            minR = P - Q + 1
            R_list = copy.copy(Q_list)
            del R_list[:j + 1]
            R_list.reverse()
            # print(R_list, minR, bisect.bisect_left(R_list, minR))
            triangles += len(R_list) - bisect.bisect_left(R_list, minR)

            # for R in R_list:
            #     if R >= minR:
            #         triangles += 1
            #     else:
            #         break

    print(triangles)

if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    main(N, L)


Fixed submission:
import copy
import bisect

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

triangles = 0

for i in range(N - 2):
    P = L[i]
    for j in range(i + 1, N - 1):
        Q = L[j]
        if P + Q <= L[j + 1]:
            continue
        maxR = P + Q - 1
        triangles += bisect.bisect_right(L, maxR) - (j + 1)

print(triangles)

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

def main(N, L):
    L.sort(reverse=True)

    triangles = 0

    for i, P in enumerate(L):
        Q_list = copy.copy(L)
        del Q_list[:i + 1]
        for j, Q in enumerate(Q_list):
            if Q < P / 2:
                break
            minR = P - Q + 1
            R_list = copy.copy(Q_list)
            del R_list[:j + 1]
            for R in R_list:
                if R >= minR:
                    triangles += 1
                else:
                    break

    print(triangles)

if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    main(N, L)


Fixed submission:
import copy
import bisect

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

triangles = 0

for i in range(N - 2):
    P = L[i]
    for j in range(i + 1, N - 1):
        Q = L[j]
        if P + Q <= L[j + 1]:
            continue
        maxR = P + Q - 1
        triangles += bisect.bisect_right(L, maxR) - (j + 1)

print(triangles)

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

def main(N, L):
    L.sort(reverse=True)

    triangles = 0

    for i, P in enumerate(L):
        Q_list = copy.copy(L)
        del Q_list[:i + 1]
        for j, Q in enumerate(Q_list):
            minR = P - Q + 1
            R_list = copy.copy(Q_list)
            del R_list[:j + 1]
            for R in R_list:
                if R >= minR:
                    triangles += 1
                else:
                    break

    print(triangles)

if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    main(N, L)


Fixed submission:
import copy
import bisect

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

triangles = 0

for i in range(N - 2):
    P = L[i]
    for j in range(i + 1, N - 1):
        Q = L[j]
        if P + Q <= L[j + 1]:
            continue
        maxR = P + Q - 1
        triangles += bisect.bisect_right(L, maxR) - (j + 1)

print(triangles)