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

n = int(input())
arr = list(map(int, input().split()))

ans = 0
for a, b, c in combinations(arr, 3):
    if a < b + c and b < c + a and c < a + b:
        ans += 1

print(ans)

Fixed submission:
from bisect import bisect_left
import copy

n = int(input())
l = list(map(int, input().split()))
l.sort()


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right
from itertools import combinations_with_replacement

n = int(input())
l = list(map(int, input().split()))
l.sort()

li = list(combinations_with_replacement(l, 2))
li = [x for x in li if x[0] != x[1] and x[1] != max(l)]

ans = 0
for small, mid in li:
    right = bisect_right(l, small + mid - 1)
    left = bisect_left(l, mid)
    ans += max(right - left - 1, 0)

print(ans)

Fixed submission:
from bisect import bisect_left
import copy

n = int(input())
l = list(map(int, input().split()))
l.sort()


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

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


n = int(input())
l = list(map(int, input().split()))
l.sort()

li = list(combinations(l, 2))


ans = 0
for i in li:
    x = copy.deepcopy(l)
    x.remove(i[0])
    x.remove(i[1])
    left = abs(i[0] - i[1])
    small = min(i[0], i[1])
    x = [i for i in x if i < small]

    if len(x) != 0:
        left_div = bisect_left(x, left+1)
        ans += max(0, len(x) - left_div)

print(ans)

Fixed submission:
from bisect import bisect_left
import copy

n = int(input())
l = list(map(int, input().split()))
l.sort()


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right
import copy
from itertools import combinations


n = int(input())
l = list(map(int, input().split()))
l.sort()

li = list(combinations(l, 2))


ans = 0
for i in li:
    x = copy.deepcopy(l)
    x.remove(i[0])
    x.remove(i[1])
    left = abs(i[0] - i[1])
    right = min(i[0], i[1])

    left_div = bisect_left(x, left+1)
    right_div = bisect_right(x, right-1)
    ans += max(0, right_div - left_div)

print(ans)

Fixed submission:
from bisect import bisect_left
import copy

n = int(input())
l = list(map(int, input().split()))
l.sort()


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right
import copy
from itertools import combinations


n = int(input())
l = list(map(int, input().split()))
l.sort()

li = list(combinations(l, 2))


ans = 0
for i in li:
    x = copy.deepcopy(l)
    x.remove(i[0])
    x.remove(i[1])
    left = abs(i[0] - i[1])
    right = min(i[0], i[1])

    left_div = bisect_left(x, left+1)
    right_div = bisect_right(x, right-1)
    ans += max(0, right_div - left_div)

print(ans)

Fixed submission:
from bisect import bisect_left
import copy

n = int(input())
l = list(map(int, input().split()))
l.sort()


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

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


n = int(input())
l = list(map(int, input().split()))
l.sort()

li = list(combinations(l, 2))


ans = 0
for i in li:
    x = copy.deepcopy(l)
    x.remove(i[0])
    x.remove(i[1])
    left = abs(i[0] - i[1])
    right = min(i[0], i[1])

    left_div = bisect.bisect_left(x, left+1)
    right_div = bisect.bisect_right(x, right-1)
    ans += max(0, right_div - left_div)

print(ans)

Fixed submission:
from bisect import bisect_left
import copy

n = int(input())
l = list(map(int, input().split()))
l.sort()


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

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


def solve(a, b, c):
    x = a < b + c
    y = b < c + a
    z = c < a + b

    return all([x, y, z])


n = int(input())
l = list(map(int, input().split()))

li = list(combinations(l, 3))

ans = 0
for a, b, c in li:
    if solve(a, b, c):
        ans += 1

print(ans)

Fixed submission:
from bisect import bisect_left
import copy

n = int(input())
l = list(map(int, input().split()))
l.sort()


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)