CodeEff/ECCO huggingface dataset:
# Original solution
import bisect

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()

ans = 0
# a <= b <= c

for b in range(1,N-1):
  for c in range(b+1,N):
    # search min(c) with a + b > c <=> a > c - b
    idx = bisect.bisect_left(L[:b],L[c]-L[b]+1)
    #print(L[b],L[c],idx)
    ans += max(b-idx,0) if idx >= 0 else 0 
    #print(idx, ans)
#print(L)
print(ans)

# Optimized solution
import bisect

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()

ans = 0
# a <= b <= c

for b in range(1,N-1):
  for c in range(b+1,N):
    # search min(c) with a + b > c <=> a > c - b
    idx = bisect.bisect_left(L,L[c]-L[b]+1)
    #print(L[b],L[c],idx)
    ans += max(b-idx,0) if idx >= 0 else 0 
    #print(idx, ans)
#print(L)
print(ans)
# Original solution
""" nC3 のすべての組み合わせに対して、三角形が成立するかを調べると、O(n^3)で計算量がだめ
ソートしてから、maxの辺を固定する
他の２つのへんをfor loop *２で回すが、a >= b + c になった段階でbreakする
この時の計算量はo(n^3)だけど半分くらいに減るはず。
これでTLEするか試す
"""
n = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    for k in range(j-1,-1,-1):
      ans += 1
      if l[i] >= l[j] + l[k]:
        ans -= 1
        break
print(ans)


# Optimized solution
import sys
input = sys.stdin.readline
n = int(input()[:-1])
li = list(map(int,input().split()))
li.sort()
ans = 0
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    l = 0
    r = j
    while r-l > 0:
      p = (r+l)//2
      if li[p] + li[j] > li[i]:
        r = p
      else:
        l = p + 1
    ans += j - r
print(ans)
# Original solution
import bisect
import sys
input = sys.stdin.readline
n = int(eval(input()))
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1,n-1):
    for j in range(i+1,n):
        if l[j] - l[i] >= l[i-1]:
            break
        elif i - bisect.bisect_right(l,(l[j]-l[i])) > 0:
            ans += i - bisect.bisect_right(l,(l[j]-l[i]))
print(ans)

# Optimized solution
import sys
input = sys.stdin.readline
n = int(eval(input()))
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1,n-1):
    tmp=0
    for j in range(i+1,n):
        if l[j] - l[i] >= l[i-1]:
            break
        else:
            for k in range(tmp,i):
                if l[tmp] > l[j]-l[i]:
                    ans += i-tmp
                    break
                elif l[k] > l[j]-l[i]:
                    tmp = k
                    ans += i-tmp
                    break
print(ans)
# Original solution
import bisect
n = int(eval(input()))
L = sorted([int(i) for i in input().split()])
ans = 0
for b in range(n):
    for a in range(b):
        ab = L[a] + L[b]
        r = bisect.bisect_left(L,ab)
        l = b+1
        ans += max(0,r-l)
print(ans)

# Optimized solution
import bisect

n = int(eval(input()))
l = sorted(list(map(int, input().split())))
ans = 0

for a in range(n):
    for b in range(a):
        over_c = l[a] + l[b]
        over_c_index = bisect.bisect_left(l,over_c)
        quantity = over_c_index - a - 1
        ans += max(quantity,0)
print(ans)
# Original solution
import sys
import itertools

N = int(eval(input()))
L = [int(v) for v in sys.stdin.readline().split()]

print((len([(a, b, c) for a, b, c in itertools.combinations(L, 3) if a + b > c and b + c > a and a + c > b])))



# Optimized solution
import sys
import itertools
 
N = int(eval(input()))
L = [int(v) for v in sys.stdin.readline().split()]

print((len([0 for a, b, c in itertools.combinations(L, 3) if a + b > c and b + c > a and a + c > b])))
# Original solution
import sys
import itertools
 
N = int(eval(input()))
L = [int(v) for v in sys.stdin.readline().split()]

print((len([0 for a, b, c in itertools.combinations(L, 3) if a + b > c and b + c > a and a + c > b])))


# Optimized solution
import sys
from bisect import bisect_left

N = int(eval(input()))
A = [int(v) for v in sys.stdin.readline().split()]

A = sorted(A)

cnt = 0
for i in range(N - 2):
    for j in range(i+1, N - 1):
        ij = A[i] + A[j]
        cnt += bisect_left(A, ij) - (j + 1)
print(cnt)
# Original solution
#3本目を選ぶ時に2本目と同じ長さのものを選べることに注意する
import bisect
n=int(eval(input()))
l=sorted(list(map(int,input().split())))

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        p=bisect.bisect_right(l,l[i]+l[j]-1)
        cnt+=max(p-j-1,0)
print(cnt)


# Optimized solution
import bisect
n=int(eval(input()))
l=sorted(list(map(int,input().split())))

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        p=bisect.bisect_right(l,l[i]+l[j]-1)
        cnt+=p-j-1
print(cnt)
# Original solution
import bisect

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()

ans = 0
for a in range(N-2):
    for b in range(a+1, N-1):
        minc = L[a] + L[b]
        indc = bisect.bisect_left(L[b+1:], minc)
        ans += max(indc, 0)

print(ans)


# Optimized solution
import bisect

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        ans += bisect.bisect_left(L, a+b) - j - 1

print(ans)
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = sorted(list(map(int, input().rstrip('\n').split())))
    cnt = 0
    for i, iv in enumerate(l[:n-2]):
        for j, jv in enumerate(l[i+1:n-1]):
            t = iv + jv
            for k, kv in enumerate(l[i+j+2:n]):
                if t > kv:
                    cnt += 1
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            p = bisect.bisect_left(l, t)
            cnt += (p - j - 1)
    print(cnt)


if __name__ == '__main__':
    slove()
# Original solution
from bisect import bisect_left
N=int(eval(input()))
ll=list(map(int,input().split()))
ll.sort()
ans=0
for i in range(N):
    for j in range(i+1,N):
        delta=bisect_left(ll,ll[i]+ll[j],lo=j)-j-1
        if delta>0:
            ans+=delta
        #print(i,j,delta)
print(ans)



# Optimized solution
from bisect import bisect_left
N=int(eval(input()))
ll=list(map(int,input().split()))
ll.sort()
ans=0
for i in range(N):
    for j in range(i+1,N):
        if j==i+1:
            delta=bisect_left(ll,ll[i]+ll[i+1],lo=i+1)-i-2
            if delta>0:
                ans+=delta
            in_b=delta+i+1+1
        else:
            if in_b!=N:
                delta=bisect_left(ll,ll[i]+ll[j],lo=in_b)-j-1
            else:
                delta=N-j-1
            if delta>0:
                ans+=delta
            in_b=delta+j+1
print(ans)
# Original solution
from bisect import bisect_left, bisect_right
N = int(eval(input()))
L = [int(c) for c in input().split()]
L.sort()
ans = 0
for i in range(N):
  for j in range(i+1, N):
    x = L[i]+L[j]
    ind = bisect_left(L, x)
    IND = bisect_right(L,x)
    ans += ind-j-1 if ind-j>0 else 0
#    print(x,ind)

print(ans)

# Optimized solution
from bisect import bisect_left
N = int(eval(input()))
L = [int(c) for c in input().split()]
L.sort()
ans = 0
for i in range(N):
  for j in range(i+1, N):
    x = L[i]+L[j]
    ind = bisect_left(L, x)
    ans += ind-j-1
#    print(x,ind)

print(ans)
# Original solution
from itertools import combinations
n=int(eval(input()))
li=[int(x) for x in input().split()]
l = list(range(n))
s = combinations(l,3)

d=0
for a,b,c in list(s):
    if li[a]<(li[b]+li[c]):
        if li[b]<(li[a]+li[c]):
            if li[c]<(li[b]+li[a]):
                d=d+1
print(d)

# Optimized solution

def findNumberOfTriangles(arr, n): 
	count = 0
	
	
	 
	for i in range(n): 
		for j in range(i + 1, n): 
			
			
			
			for k in range(j + 1, n): 
				
				 
				 
				if (arr[i] + arr[j] > arr[k] and
					arr[i] + arr[k] > arr[j] and
					arr[k] + arr[j] > arr[i]): 
					count += 1
	return count 
n=int(eval(input()))
li = [int(x) for x in input().split()]

print(( findNumberOfTriangles(li, len(li))))
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)

cnt = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        base = l[i] - l[j]
        for k in range(j + 1, n):
            if l[k] > base:
                cnt += 1
            else:
                break
print(cnt)

# Optimized solution
import bisect
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()

cnt = 0

for i in range(n - 1, 0, -1):
    for j in range(i - 1, -1, -1):
        base = l[i] - l[j]
        idx = bisect.bisect_right(l, base)
        cnt += max(j - idx, 0)
print(cnt)
# Original solution
n=int(eval(input()))
L_lst=sorted(list(map(int,input().split())))
cnt=0
for j in range(n-1,1,-1):
    i=j-1
    x=0
    while x<i:
        if L_lst[i]+L_lst[x]>L_lst[j]:
            cnt+=i-x
            i-=1
            x=0
        else:
            x+=1
print(cnt)

# Optimized solution
n=int(eval(input()))
L_lst=sorted(list(map(int,input().split())))
cnt=0
for j in range(n-1,1,-1):
    i=j-1
    x=0
    while x<i:
        if L_lst[i]+L_lst[x]>L_lst[j]:
            cnt+=i-x
            i-=1
        else:
            x+=1
print(cnt)
# Original solution
import bisect
n = int(eval(input()))
l_li = list(map(int,input().split()))
l_li.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ind = bisect.bisect_left(l_li,l_li[i]+l_li[j])
        num = ind-1 - j
        if num > 0:
            ans += num
print(ans)


# Optimized solution
import bisect
n = int(eval(input()))
l_li = list(map(int,input().split()))
l_li.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ind = bisect.bisect_left(l_li,l_li[i]+l_li[j])
        num = ind-1 - j
        ans += num
print(ans)
# Original solution
import bisect
n = int(eval(input()))
l_li = list(map(int,input().split()))
l_li.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ind = bisect.bisect_left(l_li,l_li[i]+l_li[j])
        num = ind-1 - j
        ans += num
print(ans)


# Optimized solution
import bisect
n = int(eval(input()))
l_li = list(map(int,input().split()))
l_li.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ind = bisect.bisect_left(l_li,l_li[i]+l_li[j])
        ans += ind-1 - j
print(ans)
# Original solution
# -*- coding: utf-8 -*-

n = int(eval(input()))
l = sorted(list(map(int, input().split(' '))), reverse = True)

ans = 0
for ai in range(len(l)-2):
    a = l[ai]
    for bj in range(ai+1, len(l)-1):
        b = l[bj]
        for ck in range(bj+1, len(l)):
            c = l[ck]
            if a < b+c:
                ans += 1
            else:
                break

print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
from bisect import bisect_left

n = int(eval(input()))
l = sorted(list(map(int, input().split(' '))))

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        t = l[i]+l[j]
        idx = bisect_left(l, t)
        ans += max(0, idx-j-1)

print(ans)
# Original solution
import sys

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(list(range(2, N))):
    t_max = l_list[i]
    point = None
    for j in range(0, i-1):
        if l_list[j]+l_list[i-1] > t_max:
            point = j
            break
    if point is None:
        continue
    count += (i-1-point)

    for j in reversed(list(range(point, i-1))):
        point_sec = point
        t_sec = l_list[j]
        flag = False
        for k in range(point_sec, j):
            if l_list[k]+l_list[j] > t_max:
                point_sec = k
                flag = True
                break
        if not flag:
            continue
        count += (j-point_sec)

print(count)

# Optimized solution
import sys

def bi_search(array, target):
    l, r = -1, len(array)-1
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0
#print(l_list)

for i in reversed(list(range(N))):
    a = l_list[i]
    for j in reversed(list(range(i))):
        b = l_list[j]
        index = bi_search(l_list[:j], a-b)
        """
        print("====")
        print(b-a)
        print(i, j, index)
        """
        if index > -1 and index < j and l_list[index] + b > a:
            count += (j-index)

print(count)
# Original solution
import bisect

def main():
    n = int(eval(input()))
    ll = list(map(int, input().split()))
    ll.sort()

    ans = 0
    for i in range(n-2):
        e1 = ll[i]
        for j in range(i+1, n-1):
            e2 = ll[j]
            ans += bisect.bisect_left(ll[j+1:], e1+e2)

    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
import bisect

def main():
    n = int(eval(input()))
    ll = list(map(int, input().split()))
    ll.sort()

    ans = 0
    for i in range(n-2):
        e1 = ll[i]
        for j in range(i+1, n-1):
            e2 = ll[j]
            # ans += bisect.bisect_left(ll[j+1:], e1+e2)
            comb = bisect.bisect_left(ll, e1+e2)
            comb -= (j+1)
            ans += max(comb,0)

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import bisect

def main():
    n = int(eval(input()))
    ll = list(map(int, input().split()))
    ll.sort()

    ans = 0
    for i in range(n-2):
        e1 = ll[i]
        for j in range(i+1, n-1):
            e2 = ll[j]
            # ans += bisect.bisect_left(ll[j+1:], e1+e2)
            comb = bisect.bisect_left(ll, e1+e2)
            comb -= (j+1)
            ans += max(comb,0)

    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
import bisect

n = int(eval(input()))
ll = list(map(int, input().split()))
ll.sort()

ans = 0
for i in range(n-2):
    e1 = ll[i]
    for j in range(i+1, n-1):
        e2 = ll[j]
        comb = bisect.bisect_left(ll, e1+e2)
        comb -= (j+1)
        ans += max(comb,0)

print(ans)
# Original solution
import bisect

n = int(eval(input()))
ll = list(map(int, input().split()))
ll.sort()

ans = 0
for i in range(n-2):
    e1 = ll[i]
    for j in range(i+1, n-1):
        e2 = ll[j]
        comb = bisect.bisect_left(ll[j+1:], e1+e2)
        # comb -= (j+1)
        ans += max(comb,0)

print(ans)



# Optimized solution
import bisect

n = int(eval(input()))
ll = list(map(int, input().split()))
ll.sort()

ans = 0
for i in range(n-2):
    e1 = ll[i]
    for j in range(i+1, n-1):
        e2 = ll[j]
        cnt = bisect.bisect_left(ll, e1+e2)
        cnt -= (j+1)
        ans += max(cnt,0)

print(ans)
# Original solution
n = int(eval(input()))
L = [int(i) for i in input().split()]

L.sort()

ans = 0
for a in range(len(L)):
    for b in range(a+1,len(L)):
        c_max = L[a]+L[b]-1
        left = b+1
        right = len(L)
        mid = (right+left)//2
        while left<right:
            mid = (right+left)//2
            if c_max < L[mid]:
                right = mid
            else:
                left = mid+1
        ans += left-(b+1)
       
        
        
print(ans)

# Optimized solution
n = int(eval(input()))
L = [int(i) for i in input().split()]

L.sort()
ans = 0
"""
#二分探索ver　-> import bisectと同じでもTLE.
#importはC言語veっで実行してるらしい．積極的に使おう 
for a in range(len(L)):
    for b in range(a+1,len(L)):
        c_max = L[a]+L[b]-1
        left = b+1
        right = len(L)
        mid = (right+left)//2
        while left<right:
            mid = (right+left)//2
            if c_max < L[mid]:
                right = mid
            else:
                left = mid+1
        ans += left-(b+1)
"""
for i in range(0,n-2):
    j = i+1
    k = j+1
    while j<n-1:
        while(k<n):
            if (L[j]-L[i]<L[k] and L[k]<L[i]+L[j]):
                k+=1
            else:
                break
        ans += k-(j+1)
        j += 1

        
print(ans)
# Original solution
import bisect

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()

ans = 0

for i in range(N-1):
    for j in range(i+1, N):
        a = L[i]
        b = L[j]
        l = bisect.bisect_right(L, abs(a-b))
        r = bisect.bisect_left(L, a+b)
        ans += r-l
        if a in L[l:r]:
            ans -= 1
        if b in L[l:r]:
            ans -= 1
        
print((ans//3))

# Optimized solution
import bisect

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()

ans = 0

for i in range(N-1):
    for j in range(i+1, N):
        a = L[i]
        b = L[j]
        l = bisect.bisect_right(L, abs(a-b))
        r = bisect.bisect_left(L, a+b)
        ans += r-l
        if L[l] <= a <= L[r-1]:
            ans -= 1
        if L[l] <= b <= L[r-1]:
            ans -= 1
        
print((ans//3))
# Original solution
import itertools

n = int(eval(input()))
L = list(map(int, input().split()))
M = []

for v in itertools.combinations(L, 3):
    M.append(list(v))

cnt = 0

for v in M:
    if v[0] < v[1]+v[2] and v[1] < v[0]+v[2] and v[2] < v[0]+v[1]:
        cnt += 1
        
print(cnt)


# Optimized solution
from bisect import bisect_left
n = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(n):
    for j in range(i+1, n):
        ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)
# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
L  = sorted(LI())
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        ret += bisect_left(L[j + 1:], L[i] + L[j]) - bisect_right(L[j + 1:], abs(L[i] - L[j]))
        a = L[j + 1:]


print(ret)

# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
L  = sorted(LI())
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        ret += bisect_left(L, L[i] + L[j]) - j - 1

print(ret)
# Original solution
from itertools import combinations
N = int(eval(input()))
L = [i for i in map(int, input().split())]
ans = 0

# print(list(combinations(L,3)))

for i, j ,k in list(combinations(L, 3)):
    if i < j + k and j < i + k and k < i + j:
        ans += 1
print(ans)


# Optimized solution
import sys
N = int(eval(input()))
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
#print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        for k in range(j+1,len(L)):
            if L[i] + L[j] > L[k]:
                ans += 1
                #print(L[i], L[j], L[k])
            else:
                #print("break")
                break
print(ans)
# Original solution
N = int(eval(input()))
L_list = list(map(int, input().split()))

L_list = sorted(L_list)

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L_list[i] + L_list[j] > L_list[k]:
                count += 1
            else:
                break

print(count)

# Optimized solution
import bisect

N = int(eval(input()))
L_list = list(map(int, input().split()))

L_list = sorted(L_list)

total = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        total += bisect.bisect_left(L_list, L_list[i] + L_list[j]) - j -1

print(total)
# Original solution
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort(reverse=True)
c = 0
for ll in range(n):
    for lm in range(ll+1, n):
        for lr in range(lm+1, n):
            if l[ll] < l[lm] + l[lr]:
                c += 1

print(c)


# Optimized solution
import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort()


c = 0
for i_1 in range(n-2):
    for i_2 in range(i_1+1, n-1):
        m = l[i_1] + l[i_2]
        i_3max = bisect.bisect_left(l, m) - 1
        c += i_3max - i_2

print(c)
# Original solution
import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
    l = b + 1
    for a in range(b):
        maxL = L[a] + L[b]
        r = bisect.bisect_left(L, maxL)
        ans += max(0, r-l)
print(ans)

# Optimized solution
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
    l = b + 1
    r = l
    for a in range(b):
        maxL = L[a] + L[b]
        while r<N and L[r]<maxL: r += 1
        ans += max(0, r-l)
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
cmax = L[-1] + L[-2]
csum = list(0 for _ in range(cmax+1))
for i in range(N): csum[L[i]] += 1
for i in range(1,cmax+1): csum[i] += csum[i-1]
ans = 0
for ib in range(N):
    b = L[ib]
    for ia in range(ib):
        a = L[ia]
        minL, maxL = abs(a-b), a+b
        ans += csum[maxL-1] - csum[minL]
        if minL < a < maxL: ans -= 1
        if minL < b < maxL: ans -= 1
print((ans//3))

# Optimized solution
import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
    for a in range(b):
        ans += bisect.bisect_left(L, L[a] + L[b])-(b+1)
print(ans)
# Original solution
import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
    for a in range(b):
        ans += bisect.bisect_left(L, L[a] + L[b])-(b+1)
print(ans)

# Optimized solution
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
    r = b + 1
    for a in range(b):
        while r<N and L[r]<L[a]+L[b]: r += 1
        ans += r-(b+1)
print(ans)
# Original solution
from bisect import bisect_left

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):
        ans += max(0, bisect_left(L, L[i]+L[j]) - j - 1)
print(ans)


# Optimized solution
from bisect import bisect_left

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

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - j - 1
print(ans)