Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    a, b = l[i], l[j]
    s = a+b
    bit_l, bit_r = j+1, n
    while bit_r-bit_l > 1:
      key = (bit_l+bit_r)//2
      if s > l[key]:
        bit_l = key
      else:
        bit_r = key
    if bit_r == n and l[bit_l] >= s:
      bit_r = n-1
    elif bit_l == j+1 and l[bit_l] >= s:
      bit_r = j+1
    ans += bit_r-j-1
print(ans)

Fixed submission:
import bisect

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = bisect.bisect_left(l, l[j]-l[i]+1)
        ans += max([0, i-key])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def BinarySearch(lis, i, j):
    low, high = 0, len(lis)
    border = j-i
    while low < high:
        key = (low+high)//2
        value = lis[key]
        if value <= border:
            low = min([key, low]) + 1
        else:
            high = max([key, high]) - 1
    return low

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = i-BinarySearch(l, l[i], l[j])
        ans += max([key, 0])
print(ans)

Fixed submission:
import bisect

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = bisect.bisect_left(l, l[j]-l[i]+1)
        ans += max([0, i-key])
print(ans)

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

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

Fixed submission:
import bisect

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = bisect.bisect_left(l, l[j]-l[i]+1)
        ans += max([0, i-key])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def BinarySearch(lis, i, j):
    low, high = 0, len(lis)
    border = j-i
    while low < high:
        key = (low+high)//2
        value = lis[key]
        if value <= border:
            low = min([key, low]) + 1
        else:
            high = max([key, high]) - 1
    return low

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = i-BinarySearch(l[:i], l[i], l[j])
        ans += key
print(ans)

Fixed submission:
import bisect

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = bisect.bisect_left(l, l[j]-l[i]+1)
        ans += max([0, i-key])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = set()
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i]+l[j]>l[k]:
                if l[i] > l[k]-l[j]:
                    ans.add((l[i], l[j], l[k]))
            else:
                break
print(len(ans))

Fixed submission:
import bisect

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = bisect.bisect_left(l, l[j]-l[i]+1)
        ans += max([0, i-key])
print(ans)