from bisect import bisect_left, bisect_right



def solve():

    N = int(eval(input()))

    Ls = list(map(int, input().split()))



    Ls.sort()



    ans = 0

    for i in range(N):

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

            k = bisect_left(Ls, Ls[i]+Ls[j]) - 1

            ans += k-j



    print(ans)





solve()

from itertools import accumulate



maxL = 10**3



N = int(eval(input()))

Ls = list(map(int, input().split()))



nums = [0] * (2*maxL+1)

for L in Ls:

    nums[L] += 1



accNums = list(accumulate(nums))



ans = 0

for A in range(1, maxL+1):

    if nums[A] == 0: continue

    for B in range(A+1, maxL+1):

        if nums[B] == 0: continue

        ans += nums[A] * nums[B] * (accNums[A+B-1]-accNums[B])



for A in range(1, maxL+1):

    if nums[A] < 2: continue

    ans += nums[A] * (nums[A]-1) // 2 * (accNums[2*A-1]-nums[A])



for A in range(1, maxL+1):

    if nums[A] < 3: continue

    ans += nums[A] * (nums[A]-1) * (nums[A]-2) // 6



print(ans)

from bisect import bisect_left, bisect_right


def solve():
    N = int(eval(input()))
    Ls = list(map(int, input().split()))
    Ls.sort()
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = bisect_left(Ls, Ls[i] + Ls[j]) - 1
            ans += k - j
    print(ans)


solve()

from itertools import accumulate

maxL = 10**3
N = int(eval(input()))
Ls = list(map(int, input().split()))
nums = [0] * (2 * maxL + 1)
for L in Ls:
    nums[L] += 1
accNums = list(accumulate(nums))
ans = 0
for A in range(1, maxL + 1):
    if nums[A] == 0:
        continue
    for B in range(A + 1, maxL + 1):
        if nums[B] == 0:
            continue
        ans += nums[A] * nums[B] * (accNums[A + B - 1] - accNums[B])
for A in range(1, maxL + 1):
    if nums[A] < 2:
        continue
    ans += nums[A] * (nums[A] - 1) // 2 * (accNums[2 * A - 1] - nums[A])
for A in range(1, maxL + 1):
    if nums[A] < 3:
        continue
    ans += nums[A] * (nums[A] - 1) * (nums[A] - 2) // 6
print(ans)

-from bisect import bisect_left, bisect_right +from itertools import accumulate - -def solve(): -    N = int(eval(input())) -    Ls = list(map(int, input().split())) -    Ls.sort() -    ans = 0 -    for i in range(N): -        for j in range(i + 1, N): -            k = bisect_left(Ls, Ls[i] + Ls[j]) - 1 -            ans += k - j -    print(ans) - - -solve() +maxL = 10**3 +N = int(eval(input())) +Ls = list(map(int, input().split())) +nums = [0] * (2 * maxL + 1) +for L in Ls: +    nums[L] += 1 +accNums = list(accumulate(nums)) +ans = 0 +for A in range(1, maxL + 1): +    if nums[A] == 0: +        continue +    for B in range(A + 1, maxL + 1): +        if nums[B] == 0: +            continue +        ans += nums[A] * nums[B] * (accNums[A + B - 1] - accNums[B]) +for A in range(1, maxL + 1): +    if nums[A] < 2: +        continue +    ans += nums[A] * (nums[A] - 1) // 2 * (accNums[2 * A - 1] - nums[A]) +for A in range(1, maxL + 1): +    if nums[A] < 3: +        continue +    ans += nums[A] * (nums[A] - 1) * (nums[A] - 2) // 6 +print(ans)