import math

N = int(eval(input()))

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



ans = 0



for a in range(N - 2):

    b = a + 1

    c = a + 2

    while c < N and b < N - 1:

        if L[c] >= L[a] + L[b]:

            ans += c - 1 - b

            b += 1

            if b == c:

                c += 1

        else:

            if c == N - 1:

                ans += (c - b) * (c - b + 1) // 2 

                break

            else:

                c += 1

        

print(ans)        
N = int(eval(input()))

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

ans = 0

for i in range(0, N - 2):

    a = L[i]

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

        b = L[j]

        ok = j + 1

        ng = N - 1

        if L[ng] < a + b:

            ans += ng - j

            continue

        if L[ok] >= a + b:

            continue

        while ok + 1 < ng:

            c = (ok + ng) // 2

            if L[c] < a + b:

                ok = c

            else:

                ng = c

        ans += ok - j

print(ans)
import math

N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N - 2):
    b = a + 1
    c = a + 2
    while c < N and b < N - 1:
        if L[c] >= L[a] + L[b]:
            ans += c - 1 - b
            b += 1
            if b == c:
                c += 1
        else:
            if c == N - 1:
                ans += (c - b) * (c - b + 1) // 2
                break
            else:
                c += 1
print(ans)

N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(0, N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        ok = j + 1
        ng = N - 1
        if L[ng] < a + b:
            ans += ng - j
            continue
        if L[ok] >= a + b:
            continue
        while ok + 1 < ng:
            c = (ok + ng) // 2
            if L[c] < a + b:
                ok = c
            else:
                ng = c
        ans += ok - j
print(ans)

-import math - -for a in range(N - 2): -    b = a + 1 -    c = a + 2 -    while c < N and b < N - 1: -        if L[c] >= L[a] + L[b]: -            ans += c - 1 - b -            b += 1 -            if b == c: -                c += 1 -        else: -            if c == N - 1: -                ans += (c - b) * (c - b + 1) // 2 -                break +for i in range(0, N - 2): +    a = L[i] +    for j in range(i + 1, N - 1): +        b = L[j] +        ok = j + 1 +        ng = N - 1 +        if L[ng] < a + b: +            ans += ng - j +            continue +        if L[ok] >= a + b: +            continue +        while ok + 1 < ng: +            c = (ok + ng) // 2 +            if L[c] < a + b: +                ok = c -                c += 1 +                ng = c +        ans += ok - j