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

n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      cnt = bisect.bisect_left(li[a+1+b+1:], aa + bb)
      ans += cnt
            
print(ans)

Fixed submission:
import bisect

n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for i in range(n):
  for j in range(i+1, n):
    cnt = bisect.bisect_left(li, li[i]+li[j])
    ans += cnt - j - 1
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      for c, cc in enumerate(li[a+1+b+1:]):
        if aa + bb <= cc:
          break
        else:
          ans += 1
            
print(ans)

Fixed submission:
import bisect

n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for i in range(n):
  for j in range(i+1, n):
    cnt = bisect.bisect_left(li, li[i]+li[j])
    ans += cnt - j - 1
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for a in range(n):
  if a < n - 2:
    for b in range(a+1, n-1, 1):
      for c in range(b+1, n, 1):
        if li[a] + li[b] <= li[c]:
          break
        if li[a] < li[b] + li[c] and li[b] < li[c] + li[a] and li[c] < li[a] + li[b]:
          ans += 1
            
print(ans)

Fixed submission:
import bisect

n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for i in range(n):
  for j in range(i+1, n):
    cnt = bisect.bisect_left(li, li[i]+li[j])
    ans += cnt - j - 1
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort(reverse=True)

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      for cc in li[a+1+b+1:]:
        if bb + cc <= aa:
          break
        if aa < bb + cc and bb < cc + aa and cc < aa + bb:
          ans += 1
            
print(ans)

Fixed submission:
import bisect

n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for i in range(n):
  for j in range(i+1, n):
    cnt = bisect.bisect_left(li, li[i]+li[j])
    ans += cnt - j - 1
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      for c, cc in enumerate(li[a+1+b+1:]):
        if aa + bb <= cc:
          break
        if aa < bb + cc and bb < cc + aa and cc < aa + bb:
          ans += 1
            
print(ans)

Fixed submission:
import bisect

n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for i in range(n):
  for j in range(i+1, n):
    cnt = bisect.bisect_left(li, li[i]+li[j])
    ans += cnt - j - 1
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))
ans = 0

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      for c, cc in enumerate(li[a+1+b+1:]):
        if aa < bb + cc and bb < cc + aa and cc < aa + bb:
          ans += 1
            
print(ans)

Fixed submission:
import bisect

n = int(input())
li = list(map(int, input().split()))
ans = 0

li.sort()

for i in range(n):
  for j in range(i+1, n):
    cnt = bisect.bisect_left(li, li[i]+li[j])
    ans += cnt - j - 1
            
print(ans)