N = gets.chomp.to_i
str = gets.split
l = Array.new(N)
m = Array.new(1001,N)
for i in 0...N do
    l[i] = str[i].to_i
end
l.sort!

a = 0
for i in 0...N do
    while a < l[i]
        m[a] = i
        a += 1
    end
end

a1 = 0
for i in 2...1000 do
    for j in i+1..1000 do
        k = (j-i) > i ? (j-i) : i
        a1 += (m[i]-m[i-1]) * (m[j]-m[j-1]) * (m[j-1]-m[k])
    end
end
a2 = 0
for i in 2..1000 do
    j = m[i]-m[i-1]
    max = (i*2-1) < 1000 ? i*2-1 : 1000
    if j >= 2
        a2 += (m[max] - (m[i]-m[i-1])) * j*(j-1)/2 
    end
end
a3 = 0
for i in 1..1000 do
    k = m[i]-m[i-1]
    if k >= 3
       a3 += k*(k-1)*(k-2)/6 
    end
end
answer = a1 + a2 + a3
puts answer