import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



# 長さじゃなくて、棒自体で区別してるやんけー！



import numpy as np



N = int(readline())

L = np.array(read().split(),np.int32)



L.sort()



U=1000

counter = np.bincount(L,minlength=U+U+10)

cum = counter.cumsum()



add = L[:,None] + L[None,:]

max_c = cum[add-1]

cnt_c = max_c - np.arange(len(L)) - 1



answer = np.triu(cnt_c,1).sum()

print(answer)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



import numpy as np

from numpy.fft import rfft,irfft



N = int(readline())

L = np.array(read().split(),np.int32)



fft_len = 2048



counter = np.bincount(L,minlength=1001)

add = (irfft(rfft(counter,fft_len)**2)+.5).astype(int)



# 同じものを2回使うパターンを除外

add[:2002:2] -= counter

add //= 2



# a+b <= c となる(a,b,c)を除外する



cum = counter.cumsum()

remove = ((N-cum+counter) * add[:1001]).sum()



answer = N*(N-1)*(N-2)//6 - remove

print(answer)
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 長さじゃなくて、棒自体で区別してるやんけー！
import numpy as np

N = int(readline())
L = np.array(read().split(), np.int32)
L.sort()
U = 1000
counter = np.bincount(L, minlength=U + U + 10)
cum = counter.cumsum()
add = L[:, None] + L[None, :]
max_c = cum[add - 1]
cnt_c = max_c - np.arange(len(L)) - 1
answer = np.triu(cnt_c, 1).sum()
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numpy.fft import rfft, irfft

N = int(readline())
L = np.array(read().split(), np.int32)
fft_len = 2048
counter = np.bincount(L, minlength=1001)
add = (irfft(rfft(counter, fft_len) ** 2) + 0.5).astype(int)
# 同じものを2回使うパターンを除外
add[:2002:2] -= counter
add //= 2
# a+b <= c となる(a,b,c)を除外する
cum = counter.cumsum()
remove = ((N - cum + counter) * add[:1001]).sum()
answer = N * (N - 1) * (N - 2) // 6 - remove
print(answer)

-# 長さじゃなくて、棒自体で区別してるやんけー！ +from numpy.fft import rfft, irfft -L.sort() -U = 1000 -counter = np.bincount(L, minlength=U + U + 10) +fft_len = 2048 +counter = np.bincount(L, minlength=1001) +add = (irfft(rfft(counter, fft_len) ** 2) + 0.5).astype(int) +# 同じものを2回使うパターンを除外 +add[:2002:2] -= counter +add //= 2 +# a+b <= c となる(a,b,c)を除外する -add = L[:, None] + L[None, :] -max_c = cum[add - 1] -cnt_c = max_c - np.arange(len(L)) - 1 -answer = np.triu(cnt_c, 1).sum() +remove = ((N - cum + counter) * add[:1001]).sum() +answer = N * (N - 1) * (N - 2) // 6 - remove