Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, n):
            if l[a]<l[b]+l[c] and l[b]<l[c]+l[a] and l[c]<l[a]+l[b]: ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
ans = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, n):
            if l[a]<l[b]+l[c] and l[b]<l[c]+l[a] and l[c]<l[a]+l[b]: ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
L = list(map(int, input().split()))

ans = 0
for v in itertools.combinations(L,3):
  a,b,c = v[0],v[1],v[2]
  if a < b+c and b < c+a and c < a+b: ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(1,N-1):
  for j in range(i+1, N):
    a = l[:-j]
    L = len(a)
    if l[-j] - (l[-i]-1) < (l[-i] + 1) - l[-j]: m = (l[-i]+1) - l[-j]
    else : m = l[-j]-(l[-i]-1)
    n = bisect.bisect_left(a, m)
    ans += (L - n)
print(ans)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(1,N-1):
  for j in range(i+1, N):
    a = l[:-j]
    L = len(a)
    Min = l[-j]-(l[-i]-1)
    Max = (l[-i]+1) - l[-j]
    n = max(bisect.bisect_left(a, Min), bisect.bisect_left(a, Max))
    ans += (L - n)
print(ans)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    a = l[j+1:]
    for x in range(len(a)):
      if l[i] < l[j] + a[x] and abs(l[j] - a[x]) < l[i]:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

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

import itertools
l = list(itertools.combinations(L, 3))

a = 0
n = 0

for x in range(len(l)):
  m = max(l[n])
  if m < sum(l[n]) - m:
    a += 1
    n += 1
  else:
    n += 1
    
print(a)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

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

import itertools
l = list(itertools.combinations(L, 3))

a = 0
n = 0

for x in range(len(l)):
  if max(l[n]) < sum(l[n]) - max(l[n]):
    a += 1
    n += 1
  else:
    n += 1
    
print(a)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

Buggy python submission (verdict: Runtime Error):
= int(input())
L = map(int, input().split())

import itertools
l = list(itertools.combinations(L, 3))

a = 0
n = 0

for x in range(len(l)):
  if max(l[n]) < sum(l[n]) - max(l[n]):
    a += 1
    n += 1
  else:
    n += 1
    
print(a)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)