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

def b_search(L,key,left,right):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[left]:
        return 0
    elif key > L[len(L)-1]:
        return len(L)
    while left < right:
        mid = (left + right) // 2
        if L[mid] < key and key <= L[mid+1]:
            return mid + 1
        elif L[mid] >= key:
            right = mid
        else:
            left = mid

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += b_search(L,L[i]+L[j],0,len(L))-(j+1)
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 = list(map(int,input().split()))
L.sort()

def b_search(L,key,left,right):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[left]:
        return 0
    elif key > L[len(L)-1]:
        return len(L)
    else:
        mid = (left+right)//2
        if L[mid] < key and key <= L[mid+1]:
            return mid + 1
        elif L[mid] >= key:
            return b_search(L,key,left,mid)
        else:
            return b_search(L,key,mid,right)

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += b_search(L,L[i]+L[j],0,len(L))-(j+1)
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 = 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):
N = int(input())
L = list(map(int,input().split()))
L.sort()

def b_search(L,key,left,right,slice):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[left]:
        return 0
    elif key > L[len(L)-1]:
        return len(L) - slice
    else:
        mid = (left+right)//2
        if L[mid] < key and key <= L[mid+1]:
            return mid + 1 - slice
        elif L[mid] >= key:
            return b_search(L,key,left,mid,slice)
        else:
            return b_search(L,key,mid,right,slice)

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += b_search(L,L[i]+L[j],j+1,len(L),j+1)
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 = list(map(int,input().split()))
L.sort()

def b_search(L,key,left,right):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[left]:
        return 0
    elif key > L[len(L)-1]:
        return len(L)
    else:
        mid = (left+right)//2
        if L[mid] < key and key <= L[mid+1]:
            return mid + 1
        elif L[mid] >= key:
            return b_search(L,key,left,mid)
        else:
            return b_search(L,key,mid,right)

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        L_ = L[j+1:]
        ans += b_search(L_,L[i]+L[j],0,len(L_))
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 = list(map(int,input().split()))
L.sort()

def b_search(L,key,left,right,slice):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[left]:
        return 0
    elif key > L[len(L)-1]:
        return len(L) - slice
    else:
        mid = (left+right)//2
        if L[mid] < key and key <= L[mid+1]:
            return mid+1-slice
        elif L[mid] >= key:
            return b_search(L,key,left,mid,slice)
        else:
            return b_search(L,key,mid,right,slice)

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += b_search(L,L[i]+L[j],j+1,len(L),j+1)
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 = list(map(int,input().split()))
L.sort()

def b_search(L,key,left,right,slice):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[left]:
        return 0
    elif key > L[len(L)-1]:
        return len(L) - slice
    else:
        mid = (left+right)//2
        if L[mid] < key and key <= L[mid+1]:
            return mid+1-slice
        elif L[mid] >= key:
            return b_search(L,key,left,mid,slice)
        else:
            return b_search(L,key,mid,right,slice)

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += b_search(L,L[i]+L[j],j+1,len(L),j+1)
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 = list(map(int,input().split()))
L.sort()

def b_search(L,key,left,right):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[0]:
        return 0
    elif key > L[len(L)-1]:
        return len(L)
    else:
        mid = (left+right)//2
        if L[mid] < key and key <= L[mid+1]:
            return mid+1
        elif L[mid] >= key:
            return b_search(L,key,left,mid)
        else:
            return b_search(L,key,mid,right)

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += b_search(L[j+1:],L[i]+L[j],0,len(L[j+1:]))
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 = list(map(int,input().split()))
L.sort(reverse = True)

def b_search(L,key,left,right):
    #L[i] > keyを満たす最小のi
    #L[i] >= key > L[i+1]
    if key > L[0]:
        return len(L)
    elif key <= L[len(L)-1]:
        return 0
    else:
        mid = (left+right)//2
        if L[mid] >= key and key > L[mid+1]:
            return len(L) - mid - 1
        elif L[mid] < key:
            return b_search(L,key,left,mid)
        else:
            return b_search(L,key,mid,right)

ans = 0
for i in reversed(range(2,N)):
    for j in reversed(range(1,i)):
        ans += b_search(L[:j],L[i]+L[j],0,len(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):
N = int(input())
L = list(map(int,input().split()))
L.sort()

def b_search(L,key,left,right):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[0]:
        return 0
    elif key > L[len(L)-1]:
        return len(L)
    else:
        mid = (left+right)//2
        if L[mid] < key and key <= L[mid+1]:
            return mid+1
        elif L[mid] >= key:
            return b_search(L,key,left,mid)
        else:
            return b_search(L,key,mid,right)

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if j < N-1:
            ans += b_search(L[j+1:],L[i]+L[j],0,len(L[j+1:]))
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)