Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        for k in range(N-dj):
            dk=dj+k+1
            a=Ln[di-1]
            b=Ln[dj-1]
            c=Ln[dk-1]
            if((a+b)>c)&((b+c)>a)&((c+a)>b) :
                Ans +=1
 
print(Ans)

Fixed submission:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break
 
        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)
 
print(Ans)

Buggy python submission (verdict: Time Limit Exceeded):
#import random
import numpy as np

N=int(input())
Ln_d=list(map(int,input().split()))
Ln=np.array(Ln_d)

#for i in range(N):
#    Ln=np.append(Ln,[random.randint(1,1000)])

Ln=np.sort(Ln)[::-1]

Ans=0
left=0
right=0
count=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break

        right=N-1
        left=dj
        while left<=right :
            count +=1
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)

print(Ans)

Fixed submission:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break
 
        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)
 
print(Ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break

        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)

print(Ans)


Fixed submission:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break
 
        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)
 
print(Ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
ln=list(map(int,input().split()))
ln.sort(reverse=true)
ans=0

for i in range(n-2):
  for j in range(n-i-1):
    a=ln[i]
    b=ln[i+j+1]
    #b+c>aを探す
    
    right=n-1
    left=i+j+2
    while left<=right :
      mid=int((right+left)/2)
      c=ln(mid)
      if(b+c)<a:    
        right=mid-1
      else :
        left=mid+1
    c=ln[left]
    if b+c>a :
      ans+=left-(i+j+1)

print(ans)
        
                

Fixed submission:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break
 
        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)
 
print(Ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        if (Ln[dj-1]+Ln[dj])<Ln[di-1] : break
        for k in range(N-dj):
            dk=dj+k+1
            a=Ln[di-1]
            b=Ln[dj-1]
            c=Ln[dk-1]
            if((b+c)>a)&((c+a)>b) :
                Ans +=1
            else : break

print(Ans)

Fixed submission:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break
 
        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)
 
print(Ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        for k in range(N-dj):
            dk=dj+k+1
            a=Ln[di-1]
            b=Ln[dj-1]
            c=Ln[dk-1]
            if((a+b)>c)&((b+c)>a)&((c+a)>b) :
                Ans +=1

print(Ans)


Fixed submission:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break
 
        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)
 
print(Ans)