Buggy python submission (verdict: Time Limit Exceeded):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
from bisect import bisect_left  as bl
from bisect import bisect_right as br
from bisect import insort_left  as il    # insort_leftはO(N)
from bisect import insort_right as ir
#-------------------------------------------------------------------
n = int(input())
L = list( map(int, input().split()) )	# 1 2 3 4 5 ...

L.sort()

ans=0


def bsl(L,c):
	if len(L)==0: return 0
	
	rMax = len(L)-1

	if L[rMax]<c: return rMax+1
	if c<=L[0]: return 0
	
	l=0
	r=rMax
	
	while True:
		k=(l+r)//2
		
		if c<=L[k]: r=k
		if L[k]<c:  l=k+1
		
		if r<=l: return r
		




for i in range(n-2):
	a=L[i]
	
	for j in range(i+1, n-1):
		b=L[j]
		
		#k = bl(L,a+b)
		k = bsl(L,a+b)
		
		ans+=k-j-1

print(ans)





Fixed submission:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
from bisect import bisect_left  as bl
from bisect import bisect_right as br
from bisect import insort_left  as il    # insort_leftはO(N)
from bisect import insort_right as ir
#-------------------------------------------------------------------
n = int(input())
L = list( map(int, input().split()) )	# 1 2 3 4 5 ...

L.sort()

ans=0

for i in range(n-2):
	a=L[i]
	
	for j in range(i+1, n-1):
		b=L[j]
		
		k = bl(L,a+b)
		
		ans+=k-j-1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
from bisect import bisect_left  as bl
from bisect import bisect_right as br
from bisect import insort_left  as il    # insort_leftはO(N)
from bisect import insort_right as ir
#-------------------------------------------------------------------
n = int(input())
L = list( map(int, input().split()) )	# 1 2 3 4 5 ...

L.sort()

ans=0


def bsl(L,c):
	rMax = len(L)-1
	
	l=0
	r=rMax
	
	if L[r]<c: return r+1
	
#	iCount=0
#	while iCount<=rMax:
#		iCount+=1

	while True:
		k=(l+r)//2
		#p("c,iCount,l,r,k ",c,iCount,l,r,k)
		
		if k==0: return k
		#if L[r]<=c: return r+1
		#p(20)
		if l+1==r: return r
		#p(30)
		if L[k-1]<c<=L[k]: return k
		#p(40)
		if L[k]<=c:
			l=k
		#	p(50)
			continue
		if c<L[k]:
			r=k
		#	p(60)
			continue
		#p(70)

#L=[1,3,5,7]
#for i in range(6,10):
#	print(i, bsl(L,i) )



for i in range(n-2):
	a=L[i]
	
	for j in range(i+1, n-1):
		b=L[j]
		
		#k = bl(L,a+b)
		k = bsl(L,a+b)
		
		ans+=k-j-1

print(ans)





Fixed submission:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
from bisect import bisect_left  as bl
from bisect import bisect_right as br
from bisect import insort_left  as il    # insort_leftはO(N)
from bisect import insort_right as ir
#-------------------------------------------------------------------
n = int(input())
L = list( map(int, input().split()) )	# 1 2 3 4 5 ...

L.sort()

ans=0

for i in range(n-2):
	a=L[i]
	
	for j in range(i+1, n-1):
		b=L[j]
		
		k = bl(L,a+b)
		
		ans+=k-j-1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
n = int(input())
L = list( map(int, input().split()) )	# 1 2 3 4 5 ...

L.sort()

ans=0

#p(L)

def bsl(c,L):
	
	rMax = len(L)-1
	
	l=0
	r=rMax
	
	while True:
		m=(l+r)//2
		#p("  [bsl]c,l,r,m ",c,l,L[l],r,L[r],m,L[m] )

		if L[m]==c:
			while True:
				if m==rMax: return m
				if L[m]==L[m+1]:
					m+1
				else:
					return m
		
		if (r-l)==1:
			if L[r]<=c:
				return r
			else:
				return l
		
		if c<L[m]: r=m
		if L[m]<c: l=m


for i in range(n-2):
	a=L[i]
	
	for j in range(i+1, n-1):
		b=L[j]
		#if b>(a*2): break
		
		#p("a,b,a+b-1 ",a,b,a+b-1)
		k = bsl(a+b-1, L)
		
		if j<k: ans += (k-j)
		#p("j,k,(k-j),ans ",j,k,(k-j),ans)

print(ans)





Fixed submission:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
from bisect import bisect_left  as bl
from bisect import bisect_right as br
from bisect import insort_left  as il    # insort_leftはO(N)
from bisect import insort_right as ir
#-------------------------------------------------------------------
n = int(input())
L = list( map(int, input().split()) )	# 1 2 3 4 5 ...

L.sort()

ans=0

for i in range(n-2):
	a=L[i]
	
	for j in range(i+1, n-1):
		b=L[j]
		
		k = bl(L,a+b)
		
		ans+=k-j-1

print(ans)