Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    ans += bisect_left(l[j+1:], l[i]+l[j])
print(ans)


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

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    ans += bisect_left(l[j+1:], l[i]+l[j])
print(ans)


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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
ans = 0
for i in range(n-2):
  c = l[i]
  for j in range(i+1, n-1):
    b = l[j]
    k_max = n-1
    k_min = j
    while k_min!=k_max:
      k = (k_max+k_min)//2+1
      a = l[k]
      if c < a + b:
        k_min = k
      else:
        k_max = k-1
    ans += k_min - j
print(ans)


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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
ans = 0
for i in range(n-2):
  c = l[i]
  for j in range(i+1, n-1):
    b = l[j]
    k_max = n-1
    k_min = j
    while k_min<k_max:
      k = (k_max+k_min)//2+1
      a = l[k]
      if c < a + b:
        k_min = k
      else:
        k_max = k-1
    ans += k_min - j
print(ans)


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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
  a = l[i]
  for j in range(i+1, n-1):
    b = l[j]
    k_max = n-1
    k_min = j
    while k_min!=k_max:
      k = (k_max+k_min)//2+1
      c = l[k]
      if c < a + b:
        k_min = k
      else:
        k_max = k-1
    ans += k_min - j
print(ans)


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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
s = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    k_max = n-1
    k_min = j
    while k_min!=k_max:
      k = (k_max+k_min)//2+1
      if l[k] < l[i] + l[j]:
        k_min = k
      else:
        k_max = k-1
    s += k_min - j
print(s)

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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
s = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if l[k] < l[i] + l[j]:
        s += 1
      else:
        break
print(s)

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