Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
L=list(map(int,input().split()))
l=[]
L.sort()
lis=[0]*(max(L)+1)
cnt=0
ans=0
c=collections.Counter(L)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
l1=0
l2=0
mi=0
ma=0
le=0
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
l.sort(key=lambda x:x[0])
#print(lis,L)
for i in range(max(L)+1):
    #print(cnt)
    cnt=cnt+c[i]
    lis[i]=cnt
for i in range(len(L)-1):
    for j in range(i+1,len(L)):
        l1=L[i]
        l2=L[j]#l1<=l2
        ma=min(l1+l2-1,max(L))
        mi=max(l2-l1+1,min(L))
        le=lis[ma]-lis[mi-1]
        if mi<=l1<=ma:
            le=le-1
        if mi<=l2<=ma:
            le=le-1
        #print(l1, l2,c[l1],c[l2],ma,mi,le)
        ans=ans+c[l1]*c[l2]*max(le,0)
print(ans//3)



Fixed submission:
import collections
N=int(input())
L=list(map(int,input().split()))
l=[]
L.sort()
lis=[0]*(max(L)+1)
cnt=0
ans=0
c=collections.Counter(L)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
l1=0
l2=0
mi=0
ma=0
le=0
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
l.sort(key=lambda x:x[0])
#print(lis,L)
for i in range(max(L)+1):
    #print(cnt)
    cnt=cnt+c[i]
    lis[i]=cnt
for i in range(len(L)-1):
    for j in range(i+1,len(L)):
        l1=L[i]
        l2=L[j]#l1<=l2
        ma=min(l1+l2-1,L[len(L)-1])
        mi=max(l2-l1+1,L[0])
        le=lis[ma]-lis[mi-1]
        if mi<=l1<=ma:
            le=le-1
        if mi<=l2<=ma:
            le=le-1
        #print(l1, l2,c[l1],c[l2],ma,mi,le)
        ans=ans+max(le,0)
print(ans//3)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
L=list(map(int,input().split()))
l=[]
L.sort()
lis=[0]*(max(L)+1)
cnt=0
ans=0
c=collections.Counter(L)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
l1=0
l2=0
mi=0
ma=0
le=0
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
l.sort(key=lambda x:x[0])
#print(lis,L)
for i in range(max(L)+1):
    #print(cnt)
    cnt=cnt+c[i]
    lis[i]=cnt
for i in range(len(L)-1):
    for j in range(i+1,len(L)):
        l1=L[i]
        l2=L[j]#l1<=l2
        ma=min(l1+l2-1,max(L))
        mi=max(l2-l1+1,min(L))
        le=lis[ma]-lis[mi-1]
        if mi<=l1<=ma:
            le=le-1
        if mi<=l2<=ma:
            le=le-1
        #print(l1, l2,c[l1],c[l2],ma,mi,le)
        ans=ans+c[l1]*c[l2]*max(le,0)
print(ans//3)



Fixed submission:
import collections
N=int(input())
L=list(map(int,input().split()))
l=[]
L.sort()
lis=[0]*(max(L)+1)
cnt=0
ans=0
c=collections.Counter(L)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
l1=0
l2=0
mi=0
ma=0
le=0
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
l.sort(key=lambda x:x[0])
#print(lis,L)
for i in range(max(L)+1):
    #print(cnt)
    cnt=cnt+c[i]
    lis[i]=cnt
for i in range(len(L)-1):
    for j in range(i+1,len(L)):
        l1=L[i]
        l2=L[j]#l1<=l2
        ma=min(l1+l2-1,L[len(L)-1])
        mi=max(l2-l1+1,L[0])
        le=lis[ma]-lis[mi-1]
        if mi<=l1<=ma:
            le=le-1
        if mi<=l2<=ma:
            le=le-1
        #print(l1, l2,c[l1],c[l2],ma,mi,le)
        ans=ans+max(le,0)
print(ans//3)