Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

from bisect import bisect_right,bisect_left

ans = 0
for i, a in enumerate(L[:-2]):
    for j, b in enumerate(L[i+1:-1]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_right(L[j+1:], abs(a-b))
        r = bisect_left(L[j+1:], a+b)
        #print(r-l)
        ans += r-l
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

from bisect import bisect_right,bisect_left

ans = 0
for i, a in enumerate(L[:-2]):
    for j, b in enumerate(L[i+1:-1]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_left(L, abs(a-b),j+1)
        r = bisect_left(L, a+b,j+1)
        #print(r-l)
        ans += r-l
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

from bisect import bisect_right,bisect_left

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1:]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_right(L[j+1:], abs(a-b))
        r = bisect_left(L[j+1:], a+b)
        #print(r-l)
        ans += r-l
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

from bisect import bisect_right,bisect_left

ans = 0
for i, a in enumerate(L[:-2]):
    for j, b in enumerate(L[i+1:-1]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_left(L, abs(a-b),j+1)
        r = bisect_left(L, a+b,j+1)
        #print(r-l)
        ans += r-l
print(ans)

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

L.sort()
L2 = [(l, 1) for l in L]
LR = []
#print(L)

from bisect import bisect_left

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1:]):
        j=i+1+j
        L2.append((abs(a-b), 0))
        L2.append((a+b, 0))
        LR.append((abs(a-b), a+b, i, j))

L2.sort()
L_dict = {}

cnt = 0
for v, f in L2:
    if f == 0:
        L_dict[v] = cnt
    else:
        cnt += 1
        
ans = 0
for l, r, i, j in LR:
    x = max(L_dict[l], j+1)
    y = max(L_dict[r], j+1)
    ans += y-x
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

from bisect import bisect_right,bisect_left

ans = 0
for i, a in enumerate(L[:-2]):
    for j, b in enumerate(L[i+1:-1]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_left(L, abs(a-b),j+1)
        r = bisect_left(L, a+b,j+1)
        #print(r-l)
        ans += r-l
print(ans)

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

L.sort()
#print(L)

from bisect import bisect_left

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1:]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_left(L[j+1:], abs(a-b))
        r = bisect_left(L[j+1:], a+b)
        #print(r-l)
        ans += r-l
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

from bisect import bisect_right,bisect_left

ans = 0
for i, a in enumerate(L[:-2]):
    for j, b in enumerate(L[i+1:-1]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_left(L, abs(a-b),j+1)
        r = bisect_left(L, a+b,j+1)
        #print(r-l)
        ans += r-l
print(ans)

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

L.sort()
#print(L)

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1:]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        for k, c in enumerate(L[j+1:]):
            if abs(a-b) < c and c < a+b:
                ans += 1
            if c >= a+b:
                break
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

from bisect import bisect_right,bisect_left

ans = 0
for i, a in enumerate(L[:-2]):
    for j, b in enumerate(L[i+1:-1]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_left(L, abs(a-b),j+1)
        r = bisect_left(L, a+b,j+1)
        #print(r-l)
        ans += r-l
print(ans)