Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
listl = [int(i) for i in input().split()]

listl.sort(reverse=True)

#print(listl)
ans=0
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		elif listl[j]+listl[j+1]<=listl[i]:
			break
		for k in range(j+1,n):
		#	print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)
				 
		

Fixed submission:
n=int(input())
listl = [int(i) for i in input().split()]

"""listl.sort(reverse=True)

#print(listl)
	ans=0
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		for k in range(j+1,n):

			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	

print(ans)"""
from bisect import bisect_right				 
listl.sort()

ans=0

for i in range(n-1,1,-1):
	a=listl[i]
	for j in range(i-1,0,-1):
		b=listl[j]
		c=bisect_right(listl,a-b)
		#print(c)
		num = j-c
		if num>0:
			ans+=num
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
listl = [int(i) for i in input().split()]

listl.sort(reverse=True)

#print(listl)
ans=0
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]+listl[j+1]<=listl[i]:
			break
		for k in range(j+1,n):
		#	print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)
				 
		

Fixed submission:
n=int(input())
listl = [int(i) for i in input().split()]

"""listl.sort(reverse=True)

#print(listl)
	ans=0
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		for k in range(j+1,n):

			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	

print(ans)"""
from bisect import bisect_right				 
listl.sort()

ans=0

for i in range(n-1,1,-1):
	a=listl[i]
	for j in range(i-1,0,-1):
		b=listl[j]
		c=bisect_right(listl,a-b)
		#print(c)
		num = j-c
		if num>0:
			ans+=num
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
listl = [int(i) for i in input().split()]

listl.sort(reverse=True)

#print(listl)
ans=0
"""if n==3:
	if listl[0]>=listl[1]+listl[2]:
		ans=0
	else:
		ans=1
else:"""
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		for k in range(j+1,n):
		#	print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)
				 
	

Fixed submission:
n=int(input())
listl = [int(i) for i in input().split()]

"""listl.sort(reverse=True)

#print(listl)
	ans=0
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		for k in range(j+1,n):

			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	

print(ans)"""
from bisect import bisect_right				 
listl.sort()

ans=0

for i in range(n-1,1,-1):
	a=listl[i]
	for j in range(i-1,0,-1):
		b=listl[j]
		c=bisect_right(listl,a-b)
		#print(c)
		num = j-c
		if num>0:
			ans+=num
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
listl = [int(i) for i in input().split()]

listl.sort(reverse=True)

#print(listl)
ans=0
"""if n==3:
	if listl[0]>=listl[1]+listl[2]:
		ans=0
	else:
		ans=1
else:"""
for i in range(n-2):
	for j in range(i+1,n-1):
		for k in range(j+1,n):
		#	print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)
				 
	

Fixed submission:
n=int(input())
listl = [int(i) for i in input().split()]

"""listl.sort(reverse=True)

#print(listl)
	ans=0
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		for k in range(j+1,n):

			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	

print(ans)"""
from bisect import bisect_right				 
listl.sort()

ans=0

for i in range(n-1,1,-1):
	a=listl[i]
	for j in range(i-1,0,-1):
		b=listl[j]
		c=bisect_right(listl,a-b)
		#print(c)
		num = j-c
		if num>0:
			ans+=num
print(ans)