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

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):
        a = bisect.bisect_right(l, l[j]-l[i])
        b = bisect.bisect_left(l, l[i]+l[j])
        a = max(j+1, a)
        b = max(j+1, b)
        ans += b - a

print(ans)

Fixed submission:
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))


a.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        x = bisect_left(a, a[i] + a[j])
        count += x - (j+1)

print(count)

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

a.sort()
count = 0


def binary_search(numbers, target_number):
    # 最小値を仮決め
    low = 0
    # 範囲内の最大値
    high = len(numbers)


    # 目的地を探し出すまでループ
    while low <= high:
        if low == high:
            return low
        # 中央値を求める（index）
        middle = (low + high) // 2
        # 中央値のnumbersの値とtarget_numberが等しい場合
        if numbers[middle] == target_number:
            return middle
        # 中央値のnumbersの値がtarget_numberより小さい場合
        elif numbers[middle] < target_number:
            low = middle + 1
        # 中央値のnumbersの値がtarget_numberより大きい場合
        else:
            high = middle - 1
    return max(low, high)


for i in range(n-2):
    for j in range(i+1, n-1):
        if a[i] + a[j] > max(a):
            count += n - (j+1)
            continue
        elif a[i] + a[j] == max(a):
            count += n - (j+1) - 1
            continue
        index = binary_search(a, (a[i]+a[j]))
        if a[i] + a[j] == a[index] or a[i] + a[j] < a[index]:
            count += (index-(j+1))
        else:
            count += (index - j)


print(count)




Fixed submission:
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))


a.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        x = bisect_left(a, a[i] + a[j])
        count += x - (j+1)

print(count)

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

a.sort()
count = 0


def binary_search(numbers, target_number):
    # 最小値を仮決め
    low = 0
    # 範囲内の最大値
    high = len(numbers)


    # 目的地を探し出すまでループ
    while low <= high:
        if low == high:
            return low
        # 中央値を求める（index）
        middle = (low + high) // 2
        # 中央値のnumbersの値とtarget_numberが等しい場合
        if numbers[middle] == target_number:
            return middle
        # 中央値のnumbersの値がtarget_numberより小さい場合
        elif numbers[middle] < target_number:
            low = middle + 1
        # 中央値のnumbersの値がtarget_numberより大きい場合
        else:
            high = middle - 1


for i in range(n-2):
    for j in range(i+1, n-1):
        if a[i] + a[j] > max(a):
            count += n - (j+1)
            continue
        index = binary_search(a, (a[i]+a[j]))
        if a[i] + a[j] == a[index]:
            count += (index-(j+1))
        else:
            count += (index - j)


print(count)



Fixed submission:
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))


a.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        x = bisect_left(a, a[i] + a[j])
        count += x - (j+1)

print(count)

Buggy python submission (verdict: Runtime Error):
import itertools
from math import factorial

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
original = a.copy()

count = [0]
daburi = []
c_list = []
c = 1

for i in range(2000):
    if a[0] > a[1] * 2:
        a.pop(0)

for i in range(len(a)-1):
    if a[i] == a[i+1]:
        if a[i] not in daburi:
            daburi.append(a[i])
        c += 1
    else:
        c_list.append(c)
        c = 1

for i in range(len(daburi)):
    if c_list[i] == 2:
        count[0] += n - original.index(2*daburi[i]-1) - 2
    else:
        count[0] += n - original.index(2 * daburi[i] - 1) - c_list[i]
        count[0] += factorial(c_list[i]) / factorial(3) /factorial(c_list[i] - 3)

a = sorted(set(a), key=a.index)

x = list(itertools.combinations(a, 3))

def check_triangle(li):
    li.sort(reverse=True)
    if li[0] < li[1] + li[2]:
        count[0] += 1


for i in x:
    check_triangle(list(i))

print(count[0])


Fixed submission:
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))


a.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        x = bisect_left(a, a[i] + a[j])
        count += x - (j+1)

print(count)

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

n = int(input())
a = list(map(int, input().split()))

count = [0]

x = list(itertools.combinations(a, 3))

def check_triangle(li):
    li.sort(reverse=True)
    if li[0] < li[1] + li[2]:
        count[0] += 1


for i in x:
    check_triangle(list(i))

print(count[0])





Fixed submission:
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))


a.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        x = bisect_left(a, a[i] + a[j])
        count += x - (j+1)

print(count)