import sys

input = sys.stdin.readline

import bisect

def main():

    N = int(eval(input()))

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

    L.sort()

    ans = 0

    for i in range(N-2):

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

            idx = bisect.bisect_left(L, L[i]+L[j], j+1, N)

            ans += idx-j-1

    print(ans)

if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline

import bisect

def main():

    N = int(eval(input()))

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

    L.sort()

    MAX = 2000

    C = [0] * MAX

    S = [0] * (MAX+1)

    for val in L:

        C[val] += 1

    for i in range(MAX):

        S[i+1] = C[i] + S[i]

    ans = 0

    for i in range(N):

        for j in range(N):

            if i == j:continue

            left = abs(L[i]-L[j])+1

            right = L[i]+L[j]

            ans += S[right]-S[left]

            if left <= L[i] < right:ans -= 1

            if left <= L[j] < right:ans -= 1

    print((ans//6))

if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline
import bisect


def main():
    N = int(eval(input()))
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            idx = bisect.bisect_left(L, L[i] + L[j], j + 1, N)
            ans += idx - j - 1
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
import bisect


def main():
    N = int(eval(input()))
    L = list(map(int, input().split()))
    L.sort()
    MAX = 2000
    C = [0] * MAX
    S = [0] * (MAX + 1)
    for val in L:
        C[val] += 1
    for i in range(MAX):
        S[i + 1] = C[i] + S[i]
    ans = 0
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            left = abs(L[i] - L[j]) + 1
            right = L[i] + L[j]
            ans += S[right] - S[left]
            if left <= L[i] < right:
                ans -= 1
            if left <= L[j] < right:
                ans -= 1
    print((ans // 6))


if __name__ == "__main__":
    main()

+    MAX = 2000 +    C = [0] * MAX +    S = [0] * (MAX + 1) +    for val in L: +        C[val] += 1 +    for i in range(MAX): +        S[i + 1] = C[i] + S[i] -    for i in range(N - 2): -        for j in range(i + 1, N - 1): -            idx = bisect.bisect_left(L, L[i] + L[j], j + 1, N) -            ans += idx - j - 1 -    print(ans) +    for i in range(N): +        for j in range(N): +            if i == j: +                continue +            left = abs(L[i] - L[j]) + 1 +            right = L[i] + L[j] +            ans += S[right] - S[left] +            if left <= L[i] < right: +                ans -= 1 +            if left <= L[j] < right: +                ans -= 1 +    print((ans // 6))