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

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		rem = lengths[j + 1:]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)

Fixed submission:
from bisect import bisect_left

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)

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

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		rem = lengths[j + 1:]
		res += bisect_left(rem, l1 + l2)

print(res)

Fixed submission:
from bisect import bisect_left

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)

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

n = int(input())
lengths = map(int, input().split())

res = 0
sorted_lengths = sorted(lengths)
for i in range(n):
	l1 = sorted_lengths[i]
	for j in range(i + 1, n - 1):
		l2 = sorted_lengths[j]
		rem = sorted_lengths[j + 1:]
		res += bisect_left(rem, l1 + l2) - bisect_left(rem, l2 - l1)

print(res)


Fixed submission:
from bisect import bisect_left

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)

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

n = int(input())
lengths = map(int, input().split())

res = 0
sorted_lengths = sorted(lengths)
for i in reversed(range(n)):
	l1 = sorted_lengths[i]
	for j in reversed(range(1, i)):
		l2 = sorted_lengths[j]
		rem = sorted_lengths[:j]
		res += bisect(rem, l1 + l2) - bisect(rem, l1 - l2)

print(res)


Fixed submission:
from bisect import bisect_left

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)

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

n = int(input())
lengths = map(int, input().split())

res = 0
sorted_lengths = sorted(lengths)
for i in reversed(range(n)):
	l1 = sorted_lengths[i]
	for j in reversed(range(i + 1, n - 1)):
		l2 = sorted_lengths[j]
		rem = sorted_lengths[j + 1:]
		res += bisect_left(rem, l1 + l2) - bisect_left(rem, l1 - l2)

print(res)


Fixed submission:
from bisect import bisect_left

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lengths = map(int, input().split())

res = 0
sorted_lengths = sorted(lengths)[::-1]
for i in range(n):
	l1 = sorted_lengths[i]
	for j in range(i+1, n):
		l2 = sorted_lengths[j]
		res += sum([l1 - l2 < _ < l1 + l2 for _ in sorted_lengths[j + 1:]])
		
print(res)


Fixed submission:
from bisect import bisect_left

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)

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

n = input()
lengths = map(int, input().split())

len_combs = list(itertools.combinations(lengths, 3))
res = sum([a < b + c and b < c + a and c < a + b for a, b, c in len_combs])

print(res)


Fixed submission:
from bisect import bisect_left

n = int(input())
lengths = sorted(map(int, input().split()))

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)