Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        # r = bisect.bisect_left(tris, a+b)
        # cnt += r - j - 1

        ok = j
        ng = n
        while abs(ok-ng) > 1:
            mid = (ok+ng) // 2
            if tris[mid] < a + b:
                ok = mid
            else:
                ng = mid
        cnt += ok - j
print(cnt)


Fixed submission:
import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]

        low = j
        high = n
        while high - low > 1:
            mid = low + (high - low) // 2
            c = tris[mid]
            if c < a + b:
                low = mid
            else:
                high = mid
        cnt += low - j
print(cnt)


Fixed submission:
import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        low = j
        high = n
        while high - low > 1:
            mid = low + (high - low) // 2
            c = tris[mid]
            if a < b + c and b < c + a and c < a + b:
                low = mid
            else:
                high = mid
        cnt += low - j
print(cnt)


Fixed submission:
import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        low = j
        high = n
        while high - low > 1:
            mid = low + (high - low) // 2
            if tris[i] < tris[j] + tris[mid] and tris[j] < tris[i] + tris[mid] and tris[mid] < tris[i] + tris[j]:
                low = mid
            else:
                high = mid
        cnt += low - j
print(cnt)


Fixed submission:
import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        low = j
        high = n
        while high - low > 1:
            mid = (high + low) // 2
            if tris[i] < tris[j] + tris[mid] and tris[j] < tris[i] + tris[mid] and tris[mid] < tris[i] + tris[j]:
                low = mid
            else:
                high = mid
        cnt += low - j
print(cnt)


Fixed submission:
import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if tris[i] < tris[j] + tris[k] and tris[j] < tris[k] + tris[i] and tris[k] < tris[i] + tris[j]:
                cnt += 1
            else:
                break
print(cnt)


Fixed submission:
import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
tris = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if tris[i] < tris[j] + tris[k] and tris[j] < tris[k] + tris[i] and tris[k] < tris[i] + tris[j]:
                cnt += 1
print(cnt)


Fixed submission:
import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)