import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda :sys.stdin.readline().rstrip()

def resolve():

    n=int(eval(input()))

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

    L.sort()

    ans=0

    for b in range(1,n-1):

        c=b+1

        for a in range(b):

            while(c<n and L[a]+L[b]>L[c]): c+=1

            ans+=c-b-1

    print(ans)

resolve()
import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda :sys.stdin.readline().rstrip()

def resolve():

    n=int(eval(input()))

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

    L.sort()

    C=[0]*(3001)

    for l in L: C[l]+=1

    for i in range(3000): C[i+1]+=C[i]

    ans=0

    for i in range(n):

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

            ans+=C[L[i]+L[j]-1]-j-1

    print(ans)

resolve()
import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


def resolve():
    n = int(eval(input()))
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for b in range(1, n - 1):
        c = b + 1
        for a in range(b):
            while c < n and L[a] + L[b] > L[c]:
                c += 1
            ans += c - b - 1
    print(ans)


resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


def resolve():
    n = int(eval(input()))
    L = list(map(int, input().split()))
    L.sort()
    C = [0] * (3001)
    for l in L:
        C[l] += 1
    for i in range(3000):
        C[i + 1] += C[i]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += C[L[i] + L[j] - 1] - j - 1
    print(ans)


resolve()

+    C = [0] * (3001) +    for l in L: +        C[l] += 1 +    for i in range(3000): +        C[i + 1] += C[i] -    for b in range(1, n - 1): -        c = b + 1 -        for a in range(b): -            while c < n and L[a] + L[b] > L[c]: -                c += 1 -            ans += c - b - 1 +    for i in range(n): +        for j in range(i + 1, n): +            ans += C[L[i] + L[j] - 1] - j - 1