Buggy python submission (verdict: Time Limit Exceeded):
def Triangles(N, L):
    asc = sorted(L)
    desc = sorted(L, reverse=True)
    cnt = 0
    for i in range(N-2):
        if desc[i] >= desc[i+1]*2: break
        for j in range(i+1, N-1):
            nokori = desc[i] - desc[j]
            tmp = [asc[i] for i in range(N-j-1) if asc[i] > nokori]
            cnt += len(tmp)
    return cnt

N = int(input())
L = [int(x) for x in input().split()]
print(Triangles(N, L))

Fixed submission:
from bisect import bisect_left

def Triangles(N, L):
    asc = sorted(L)
    cnt = 0
    for i in range(N-2):
        l1 = asc[i]
        for j in range(i+1, N-1):
            l2 = asc[j]
            pos = bisect_left(asc, l1+l2)
            cnt += pos - 1 - j
    return cnt

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

Buggy python submission (verdict: Time Limit Exceeded):
def Triangles(N, Lrand):
    asc = sorted(Lrand)
    desc = sorted(Lrand, reverse=True)
    cnt = 0
    for i in range(N-2):
        if desc[i] >= desc[i+1]*2: break
        for j in range(i+1, N-1):
            if desc[i] >= desc[j] + desc[i+1]: break
            for k in range(N-j-1):
                if desc[i] - desc[j] < asc[k]:
                    cnt += N-j-k-1
                    break
    return cnt

N = int(input())
L = [int(x) for x in input().split()]
print(Triangles(N, L))

Fixed submission:
from bisect import bisect_left

def Triangles(N, L):
    asc = sorted(L)
    cnt = 0
    for i in range(N-2):
        l1 = asc[i]
        for j in range(i+1, N-1):
            l2 = asc[j]
            pos = bisect_left(asc, l1+l2)
            cnt += pos - 1 - j
    return cnt

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

Buggy python submission (verdict: Time Limit Exceeded):
def Triangles(N, Lrand):
    L = sorted(Lrand, reverse=True)
    cnt = 0
    for i in range(N-2):
        if L[i] >= L[i+1] * 2: break
        for j in range(i+1, N-1):
            if L[i] >= L[j] + L[j+1]: break
            for k in range(j+1, N):
                if L[i] >= L[j] + L[k]: break
                cnt += 1
    return cnt

N = int(input())
L = [int(x) for x in input().split()]
print(Triangles(N, L))

Fixed submission:
from bisect import bisect_left

def Triangles(N, L):
    asc = sorted(L)
    cnt = 0
    for i in range(N-2):
        l1 = asc[i]
        for j in range(i+1, N-1):
            l2 = asc[j]
            pos = bisect_left(asc, l1+l2)
            cnt += pos - 1 - j
    return cnt

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

Buggy python submission (verdict: Time Limit Exceeded):
def Triangles(N, Lrand):
    L = sorted(Lrand, reverse=True)
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            if L[i] >= L[j] * 2: break
            for k in range(j+1, N):
                if L[i] >= L[j] + L[k]: break
                cnt += 1
    return cnt

N = int(input())
L = [int(x) for x in input().split()]
print(Triangles(N, L))

Fixed submission:
from bisect import bisect_left

def Triangles(N, L):
    asc = sorted(L)
    cnt = 0
    for i in range(N-2):
        l1 = asc[i]
        for j in range(i+1, N-1):
            l2 = asc[j]
            pos = bisect_left(asc, l1+l2)
            cnt += pos - 1 - j
    return cnt

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

Buggy python submission (verdict: Time Limit Exceeded):
def Triangles(N, Lrand):
    L = sorted(Lrand)
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            L2 = L[i] + L[j]
            for k in range(j+1, N):
                if L[k] >= L2: break
                cnt += 1
    return cnt

N = int(input())
L = [int(x) for x in input().split()]
print(Triangles(N, L))

Fixed submission:
from bisect import bisect_left

def Triangles(N, L):
    asc = sorted(L)
    cnt = 0
    for i in range(N-2):
        l1 = asc[i]
        for j in range(i+1, N-1):
            l2 = asc[j]
            pos = bisect_left(asc, l1+l2)
            cnt += pos - 1 - j
    return cnt

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