from bisect import*

N,*L=list(map(int,open(0).read().split()));L.sort()

a=0

l=[]

r=[]

for i in range(1001):

    l.append(bisect_left(L,i))

    r.append(bisect(L,i))

for p in L:

    for q in L:

        x=p+q

        y=abs(p-q)

        a+=(l[x]if x<1001else N)-(r[y]if 0<y<1001else(y>1000)*N)

for p in L:

    x=2*p

    a-=3*(l[x]if x<1001else N)

print(((a+2*N)//6))
from bisect import*

N,*L=list(map(int,open(0).read().split()));L.sort()

a=0

for i in range(N):

    for j in range(i+1,N):

      	a+=bisect_left(L,L[i]+L[j],j+1)-j-1

print(a)
from bisect import *

N, *L = list(map(int, open(0).read().split()))
L.sort()
a = 0
l = []
r = []
for i in range(1001):
    l.append(bisect_left(L, i))
    r.append(bisect(L, i))
for p in L:
    for q in L:
        x = p + q
        y = abs(p - q)
        a += (l[x] if x < 1001 else N) - (r[y] if 0 < y < 1001 else (y > 1000) * N)
for p in L:
    x = 2 * p
    a -= 3 * (l[x] if x < 1001 else N)
print(((a + 2 * N) // 6))

from bisect import *

N, *L = list(map(int, open(0).read().split()))
L.sort()
a = 0
for i in range(N):
    for j in range(i + 1, N):
        a += bisect_left(L, L[i] + L[j], j + 1) - j - 1
print(a)

-l = [] -r = [] -for i in range(1001): -    l.append(bisect_left(L, i)) -    r.append(bisect(L, i)) -for p in L: -    for q in L: -        x = p + q -        y = abs(p - q) -        a += (l[x] if x < 1001 else N) - (r[y] if 0 < y < 1001 else (y > 1000) * N) -for p in L: -    x = 2 * p -    a -= 3 * (l[x] if x < 1001 else N) -print(((a + 2 * N) // 6)) +for i in range(N): +    for j in range(i + 1, N): +        a += bisect_left(L, L[i] + L[j], j + 1) - j - 1 +print(a)