Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)

CNT = Counter(l)
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        temp0 = l[j] - l[i]
        temp1 = l[j] + l[i]
        for k in range(l[j] + 1, temp1):
            #print(k,CNT[k])
            cnt += CNT[k]
            if k == l[j]:cnt += -1
            if k == l[i]:cnt += -1
print(cnt)
#print(CNT)

Fixed submission:
#ABC143-D
n=int(input())
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
ans=0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        b=l[i]
        c=l[j]

        #二分探索
        ok=j
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if l[mid]>b-c:
                #b>=cはわかってる
                ok=mid

            else:
                ng=mid

        ans+=ok-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)

CNT = Counter(l)
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        temp0 = l[j] - l[i]
        temp1 = l[j] + l[i]
        for k in range(l[j] + 1, temp1):
            #print(k,CNT[k])
            cnt += CNT[k]
            if k == l[j]:cnt += -1
            if k == l[i]:cnt += -1
print(cnt)
#print(CNT)

Fixed submission:
#ABC143-D
n=int(input())
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
ans=0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        b=l[i]
        c=l[j]

        #二分探索
        ok=j
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if l[mid]>b-c:
                #b>=cはわかってる
                ok=mid

            else:
                ng=mid

        ans+=ok-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#ABC143-D:二分探索
n=int(input())
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
ans=0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        b=l[i]
        c=l[j]

        #二分探索
        ok=j
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if l[mid]>b-c:
                #b>=cはわかってる
                ok=mid

            else:
                ng=mid

        ans+=ok-j
print(ans)

Fixed submission:
#ABC143-D
n=int(input())
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
ans=0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        b=l[i]
        c=l[j]

        #二分探索
        ok=j
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if l[mid]>b-c:
                #b>=cはわかってる
                ok=mid

            else:
                ng=mid

        ans+=ok-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
count=0
l=sorted(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            
            if abs(l[j]-l[k])<l[i]<l[j]+l[k]:
                count+=1
            elif abs(l[j]-l[k])>=l[i]:
                break
            
print(count)

Fixed submission:
#ABC143-D
n=int(input())
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
ans=0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        b=l[i]
        c=l[j]

        #二分探索
        ok=j
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if l[mid]>b-c:
                #b>=cはわかってる
                ok=mid

            else:
                ng=mid

        ans+=ok-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
count=0
l=sorted(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            
            if abs(l[j]-l[k])<l[i]<l[j]+l[k]:
                count+=1
            elif abs(l[j]-l[k])>=l[i]:
                break
            
print(count)

Fixed submission:
#ABC143-D
n=int(input())
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
ans=0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        b=l[i]
        c=l[j]

        #二分探索
        ok=j
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if l[mid]>b-c:
                #b>=cはわかってる
                ok=mid

            else:
                ng=mid

        ans+=ok-j
print(ans)