CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
L = list(map(int, input().split())) 

ans = 0

for a in range(0, N-2):
    for b in range(a+1, N-1):
        for c in range(b+1, N):
            n1, n2, n3 = L[a], L[b], L[c]
            if n1<n2+n3 and n2<n3+n1 and n3<n1+n2:
                ans += 1

print(ans)
exit()
from itertools import permutations, combinations,combinations_with_replacement,product

C = list(combinations(L,3))

ans = 0

for i in C:
    a, b, c = i
    if a<b+c and b<c+a and c<a+b:
        ans += 1

print(ans)

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

ans = 0

import bisect

for a in range(N):
    for b in range(a):
        A=L[a]
        B=L[b]
        c=bisect.bisect_left(L, A+B)
        ans+=c-a-1

print(ans)
# Original solution
#それゆけにぶたんまん
n = int(eval(input()))
l = sorted(list(map(int,input().split())))

ans = 0
for i in range(n):
    for j in range(i+1,n):
        #jより大きい整数kでl[k]<l[i]+l[j]を満たす最大のk
        le = j
        ri = n
        while ri-le>1:
            m = (ri+le)//2
            if l[m]<l[i]+l[j]:
                le = m
            else:
                ri = m
        ans += le-j

print(ans)


# Optimized solution
#それゆけにぶたんまん
#python3.8.2のTLEの壁に阻まれました
n = int(eval(input()))
l = sorted(list(map(int,input().split())))

ans = 0
for i in range(n):
    for j in range(i+1,n):
        #jより大きい整数kでl[k]<l[i]+l[j]を満たす最大のk
        le = j
        ri = n
        while ri-le>1:
            m = (ri+le)//2
            if l[m]<l[i]+l[j]:
                le = m
            else:
                ri = m
        ans += le-j

print(ans)
# Original solution
import sys
import bisect


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i + 1, n-1):
            p = bisect.bisect_left(a, a[i] + a[j])
            cnt += (p - j - 1)
    print(cnt)


if __name__ == '__main__':
    slove()


# Optimized solution
import sys
import bisect


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    t = 0
    for i in range(n):
        for j in range(i + 1, n - 1):
            p = bisect.bisect_left(l, l[i] + l[j])
            t += p - (j + 1)
    print(t)


if __name__ == '__main__':
    solve()
# Original solution
import bisect

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

for a in range(len(L)-2):
    for b in range(a+1, len(L)-1):
        ans += bisect.bisect_left(L[b+1:], L[a]+L[b])
print(ans)

# Optimized 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):
        ans += bisect.bisect_left(L, L[a]+L[b]) - (b+1)
print(ans)
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
cnt = 0
for i in range(n):
  for j in range(i):
    a = l[i]+l[j]
    for k in l:
      if a > k:
        continue
      cnt += 1
print((n*(n-1)*(n-2)//6-cnt))

# Optimized solution
n = int(eval(input()))
l = sorted(map(int, input().split()))
cnt = 0
m = n-1
g = []
for i in range(n):
  for j in range(i):
    g.append(l[i]+l[j])
g = sorted(g,reverse = True)
for i in g:
  while l[m] >= i:
    m-=1
  cnt += n-m-1
print((n*(n-1)*(n-2)//6-cnt))
# Original solution
# a < b + c
# b < a + C
# c < a + b

# 4 3 2 1
# a b c 

# abs(a - b) < c < a + b
# a < b < c
# b - a < b < c
# c < a + b 

from math import ceil, floor
from bisect import bisect_left, bisect_right

def solution(N, data): # O(N^2 * logN)
    data = sorted(data)
    c = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            c += bisect_left(data[j+1:], data[i] + data[j])

    return c

if __name__ == '__main__':
    N = int(eval(input()))
    L_i = list(map(int, input().split()))
    a = solution(N, L_i)
    print(a)



# Optimized solution
# a < b + c
# b < a + C
# c < a + b

# 4 3 2 1
# a b c 

# abs(a - b) < c < a + b
# a < b < c
# b - a < b < c
# c < a + b 

from math import ceil, floor
from bisect import bisect_left, bisect_right

def solution(N, data): # O(N^2 * logN)
    data.sort()
    c = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            c += bisect_left(data, data[i] + data[j], j) - j - 1

    return c

if __name__ == '__main__':
    N = int(eval(input()))
    L_i = list(map(int, input().split()))
    a = solution(N, L_i)
    print(a)
# Original solution
# a < b + c
# b < a + C
# c < a + b

# 4 3 2 1
# a b c 

# abs(a - b) < c < a + b
# a < b < c
# b - a < b < c
# c < a + b 

from math import ceil, floor
from bisect import bisect_left, bisect_right

def solution(N, data): # O(N^2 * logN)
    data.sort()
    c = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            # c += bisect_left(data, data[i] + data[j], j) - j - 1
            c += bisect_left(data[j+1:], data[i] + data[j])


    return c

if __name__ == '__main__':
    N = int(eval(input()))
    L_i = list(map(int, input().split()))
    a = solution(N, L_i)
    print(a)



# Optimized solution
# a < b + c
# b < a + C
# c < a + b

# 4 3 2 1
# a b c 

# abs(a - b) < c < a + b
# a < b < c
# b - a < b < c
# c < a + b 

from math import ceil, floor
from bisect import bisect_left, bisect_right

def solution(N, data): # O(N^2 * logN)
    data.sort()
    c = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            c += bisect_left(data, data[i] + data[j], j) - j - 1
    return c

if __name__ == '__main__':
    N = int(eval(input()))
    L_i = list(map(int, input().split()))
    a = solution(N, L_i)
    print(a)
# Original solution
import itertools

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

count = [0]

x = list(itertools.combinations(a, 3))

def check_triangle(li):
    li.sort(reverse=True)
    if li[0] < li[1] + li[2]:
        count[0] += 1


for i in x:
    check_triangle(list(i))

print((count[0]))





# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

a.sort()
count = 0


def binary_search(numbers, target_number):
    # 最小値を仮決め
    low = 0
    # 範囲内の最大値
    high = len(numbers)


    # 目的地を探し出すまでループ
    while low <= high:
        if low == high:
            return low
        # 中央値を求める（index）
        middle = (low + high) // 2
        # 中央値のnumbersの値とtarget_numberが等しい場合
        if numbers[middle] == target_number:
            return middle
        # 中央値のnumbersの値がtarget_numberより小さい場合
        elif numbers[middle] < target_number:
            low = middle + 1
        # 中央値のnumbersの値がtarget_numberより大きい場合
        else:
            high = middle - 1
    return max(low, high)


for i in range(n-2):
    for j in range(i+1, n-1):
        if a[i] + a[j] > max(a):
            count += n - (j+1)
            continue
        elif a[i] + a[j] == max(a):
            count += n - (j+1) - 1
            continue
        index = binary_search(a, (a[i]+a[j]))
        if a[i] + a[j] == a[index] or a[i] + a[j] < a[index]:
            count += (index-(j+1))
        else:
            count += (index - j)


print(count)
# Original solution
#D
n = int(eval(input()))
l = list(map(int,input().split()))
cnt = 0
l.sort(reverse=True)



for i in range(len(l)-2):
    for j in range(i+1,len(l)-1):
        x = l[i]-l[j]
        right = n-1
        left = j
 
        while left <= right:
            mid = (right + left) //2
            if l[mid] == x:
                mid -= 1
                break
                
        
            elif l[mid] > x:
                left = mid+1
            elif l[mid] < x:
                right = mid-1
        if (mid - j) > 0:
            cnt += mid - j
 
        
print(cnt)

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

for i in range(n):
    for j in range(i+1,n):
        k = bisect.bisect_left(l,l[i]+l[j])
        if k > j:
            cnt += k - j - 1
        else:
            pass
            
print(cnt)
# Original solution
import sys
import itertools
input = sys.stdin.readline

N = int(eval(input()))

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

patterns = list(itertools.combinations(edge, 3))

# print(patterns)

sum = 0
for p in patterns:
    # print(p)
    if p[0] < (p[1] + p[2]) and p[1] < (p[0] + p[2]) and p[2] < (p[0] + p[1]):
        sum += 1

print(sum)


# Optimized solution
import sys
input = sys.stdin.readline

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

lines.sort()
# print(lines)

sum = 0
for i in range(N):
    for j in range(i + 2, N):
        # print("i,j:{0},{1}".format(i, j))
        # print("lines[i],lines[j]:{0},{1}".format(lines[i], lines[j]))
        k = j - 1
        while i < k:
            # print("i,j,k:{0},{1},{2}".format(i, j, k))
            # print("lines[i],lines[j],lines[k]:{0},{1},{2}".format(lines[i], lines[j], lines[k]))

            if ((lines[i] + lines[j]) > lines[k]) and (lines[i] + lines[k]) > lines[j]:
                # print("count up")
                sum += 1
            k -= 1
print(sum)
# Original solution
import bisect

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

ans = 0

for i in range(n):
	d = []
	for j in range(i+1,n):
		index = bisect.bisect_left(l,l[i]+l[j])
		for k in range(i+1,j):
			if l[j] < l[k] + l[i]:
				if [k,j] not in d:
					d.append([k,j])
					ans += 1
		for k in range(j+1,index):
			if l[k] < l[j] + l[i]:
				if [j,k] not in d:
					d.append([j,k])
					ans += 1
print(ans)


# Optimized solution
import bisect

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

l.sort()
#print(l)
ans = 0
for i in range(n-1):
	a = l[i]
	for j in range(i+2,n):
		b = l[j]
		c = bisect.bisect_left(l,b-a+1)
		if j - c > 0:
			if i >= c:
				ans += j-i-1
			else:
				ans += j-c
		#print(i,j,c,ans)

print(ans)
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations 
from bisect import bisect_left
def main():
    N = int(readline())
    L = [int(i) for i in readline().split()]
    L.sort()
    sig = 0
    for i in range(N):
        for j in range(i+1, N):
            l = bisect_left(L[j+1:], L[i]+L[j])
            sig += l
    print(sig)
if __name__ == '__main__':
    main()


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations 
from bisect import bisect_left
def main():
    N = int(readline())
    L = [int(i) for i in readline().split()]
    L.sort()
    sig = 0
    for i in range(N):
        for j in range(i+1, N):
            l = bisect_left(L, L[i]+L[j], j+1)
            sig += l-j-1
    print(sig)
if __name__ == '__main__':
    main()
# Original solution
from bisect import *

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = max(j+1, bisect_right(l, b-a))
        upper = bisect_left(l, a+b)
        cnt += max(0, upper-lower)

print(cnt)

# Optimized solution
from bisect import *

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = max(j+1, bisect_right(l, b-a))
        upper = bisect_left(l, a+b)
        cnt += upper-lower

print(cnt)
# Original solution
N = int(eval(input()))
l = list(map(int, input().split(" ")))
l.sort()
t = 0
for i in range(N-2):
    a = l[i]
    for j in range(i+1, N-1):
        b = l[j]
        low, upp = abs(b-a), a+b
        flag = 0
        for k in range(j+1, N):
            if low < l[k] < upp:
                t += 1
                flag = 1
            else:
                if flag == 1:
                    break
                else:
                    continue
print(t)

# Optimized solution
from bisect import bisect_right
def main():
	N = int(eval(input()))
	L = list(map(int, input().split(" ")))
	L.sort()
	k = 0
	for i in reversed(list(range(2, N))):
		a = L[i]
		for j in reversed(list(range(1, i))):
			b = L[j]
			index = bisect_right(L, a-b, hi=j)
			k += j - index
	print(k)
if __name__ == "__main__":
    main()
# Original solution
from bisect import bisect_left

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

cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j+1)
    cnt += max(0,idx-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)
# Original solution
from bisect import bisect_left
 
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j)
    cnt += max(0,idx-j-1)
print(cnt)

# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t, j+1)
    ans += max(0, idx-j-1)
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
 
from bisect import bisect_left 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
 
from bisect import bisect_left 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,j+1)
    cnt += max(0,idx-j-1)
print(cnt)
# Original solution
def binarySearch(A, head, tail, key):
	left = head
	right = tail - 1 # 探索範囲:[left, right]
	i = 0
	while left <= right:
		mid = (left + right) // 2
		if key == A[mid]:
			return mid
		elif key < A[mid]:
			right = mid - 1
			i = mid
		else:
			left = mid + 1
			i = mid + 1
	return i

if __name__ == "__main__":
	N = int(eval(input()))
	L = list(map(int, input().split()))
	L.sort()
	# print(L)
	sum = 0
	for a in range(N - 2):
		for b in range(a + 1, N - 1):
			key = L[a] + L[b]
			c = binarySearch(L, b + 1, N, key)
			# print(a, b, c, c - b - 1)
			sum += c - b - 1
	print(sum)

# Optimized solution
from bisect import bisect_left

if __name__ == "__main__":
	N = int(eval(input()))
	L = list(map(int, input().split()))
	L.sort()
	# print(L)
	sum = 0
	for a in range(N - 2):
		for b in range(a + 1, N - 1):
			key = L[a] + L[b]
			i = bisect_left(L, key)
			# print(a, b, i, i - b)
			sum += i - b - 1
	print(sum)
# Original solution
import itertools

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

def tri_d(a,b,c):
  if (a+b>c) and (b+c>a) and (c+a>b):
    return True
  else:
    return False


ans=0
C=list(itertools.combinations(L, 3))
for a,b,c in C:
  if tri_d(a,b,c):
    ans+=1
print(ans)

# Optimized solution
import bisect

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

count=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1, N-1):
    b=L[j]
    r=bisect.bisect_left(L, a+b)
    count+=r-1-j
    
print(count)
# Original solution
import bisect
N=int(eval(input()))
L=list(map(int, input().split()))
#a<b+c
#b<c+a
#c<a+b
#a<=b<=c
#c<a+b
L=sorted(L)
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        x=bisect.bisect_left(L,L[i]+L[j])
        ans+=x-(j+1)
print(ans)

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

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        a=L[i]
        b=L[j]
        upper = bisect.bisect_left(L,a+b)
        lower=max(j+1, bisect.bisect_right(L, a-b), bisect.bisect_right(L, b-a))
        #print(upper, lower)
        ans+=max(0, upper-lower)


print(ans)
# Original solution
from itertools import combinations

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

count = 0
for bars in list(combinations(L, 3)):
    if bars[2] < bars[0] + bars[1]:
        if bars[1] - bars[0] < bars[2]:
            count += 1

print(count)

# Optimized solution
N = int(eval(input()))
L = sorted(list(map(int, input().split())), reverse=True)

def aaa(arr): 
    n = len(arr) 
    arr.sort() 
    count = 0
    for i in range(0,n-2): 
        k = i + 2
        for j in range(i+1,n): 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1
  
    return count 

print((aaa(L)))
# Original solution
from bisect import*
N,*L=list(map(int,open(0).read().split()));L.sort()
a=0
l=[]
r=[]
for i in range(1001):
    l.append(bisect_left(L,i))
    r.append(bisect(L,i))
for p in L:
    for q in L:
        x=p+q
        y=abs(p-q)
        a+=(l[x]if x<1001else N)-(r[y]if 0<y<1001else(y>1000)*N)
for p in L:
    x=2*p
    a-=3*(l[x]if x<1001else N)
print(((a+2*N)//6))

# Optimized solution
from bisect import*
N,*L=list(map(int,open(0).read().split()));L.sort()
a=0
for i in range(N):
    for j in range(i+1,N):
      	a+=bisect_left(L,L[i]+L[j],j+1)-j-1
print(a)
# Original solution
from bisect import*
N,*L=list(map(int,open(0).read().split()));L.sort()
a=0
for i in range(N):
    for j in range(i+1,N):
      	a+=bisect_left(L,L[i]+L[j],j+1)-j-1
print(a)

# Optimized solution
from bisect import*;N,*L=list(map(int,open(0).read().split()));L.sort();print((sum(bisect_left(L,L[i]+L[j],j+1)-j-1for i in range(N)for j in range(i+1,N))))
# Original solution
import math


def rank(arr):
    lastIndex = len(arr) - 1
    while lastIndex > 0:

        for i in range(lastIndex):
            if arr[i + 1] < arr[i]:
                tmp = arr[i + 1]
                arr[i + 1] = arr[i]
                arr[i] = tmp

        lastIndex = lastIndex - 1

    return arr

def half_search(arr, N, startIndex, endIndex):
    if startIndex == endIndex:
        if arr[startIndex] > N:
            return startIndex
        else:
            return -1

    if endIndex - startIndex == 1:

        if arr[startIndex] > N:
            return startIndex
        else:

            if arr[endIndex] <= N:
                return -1

            return endIndex

    m = (startIndex + endIndex) % 2

    if m == 1:
        # 偶数 2,5 => 3,4
        s1 = int((startIndex + endIndex - 1) / 2)
        s2 = s1 + 1
        value1 = arr[s1]

        if N < value1:
            return half_search(arr, N, startIndex, s2)
        else:
            return half_search(arr, N, s1, endIndex)
    else:
        # 奇数 3,6 => 5
        #
        midIndex = int((startIndex + endIndex + 1) / 2)
        midValue = arr[midIndex]

        if midValue > N:
            return half_search(arr, N, startIndex, midIndex)
        else:
            return half_search(arr, N, midIndex, endIndex)

def calculate(arr):
    if len(arr) < 3:
        return 0

    index = len(arr) - 1
    result = 0
    while index - 2 >= 0:

        s1 = arr[index] # 最大的值

        secondIndex = index - 1

        while secondIndex - 1 >= 0:

            s2 = arr[secondIndex]

            left = arr[:secondIndex]

            dirrerence = math.fabs(s2 - s1)
            t = half_search(left, dirrerence, 0, len(left) - 1)
            res = 0
            if t >= 0:
                res = len(left) - t
            result = result + res

            secondIndex = secondIndex - 1
        index = index - 1

    return result

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

arr = rank(S)
result = calculate(arr)
print(result)

# Optimized solution
import bisect

N = int(eval(input()))

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

def calculate(n,arr):
    arr = sorted(arr)
    sum = 0
    for i in range(n-1):
        for j in range(i+1,n):
            mmm = arr[j] + arr[i] - 1
            nnn = bisect.bisect_right(arr,mmm)
            sum = sum + nnn - (j + 1)

    print(sum)


calculate(N,ARR)
# Original solution
from bisect import bisect_left

n = int(eval(input()))
l_ls = sorted(map(int, input().split()))

ans = 0
for i, a in enumerate(l_ls):
    for j, b in enumerate(l_ls):
        if i >= j:
            continue

        ls = l_ls[:i] + l_ls[i+1:j] + l_ls[j+1:]

        left = bisect_left(ls, max(a-b, b-a)+1)
        right = bisect_left(ls, a+b)
        ans += right-left


print((ans//3))

# Optimized solution
from bisect import bisect_left

n = int(eval(input()))
l_ls = sorted(map(int, input().split()))

ans = 0

for i in range(n):
    for j in range(i+1, n):
        a, b = l_ls[i], l_ls[j]
        right = bisect_left(l_ls, a+b)
        ans += right-(j+1)

print(ans)
# Original solution
n=int(eval(input()))
l=sorted([int(i) for i in input().split()],reverse=True)

#print(l)
co=0
for i in range(n-2):
    c=l[i]
    x=0
    for j in range(i+1,n-1):
        b=l[j]
        for k in range(j+1,n):
            a=l[k]
            if c<(a+b):
                co+=1
            else:
                if k==j+1:
                    x=1
                break
        if x==1:
            break

print(co)

# Optimized solution
import bisect

def solve():
    N = int(eval(input()))
    Ls = list(map(int, input().split()))
    Ls.sort()

    # O(N^2 * logN)の全探索で解く
    ans = 0
    for a_i in range(N):
        for b_i in range(a_i+1, N):
            c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
            if c_i > b_i:
                ans += c_i - b_i - 1
            else:
                pass

    print(ans)

if __name__ == "__main__":
    solve()
# Original solution
N = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
ans = 0
max = l[N-1]
tc = N
st = [j+1 for j in range(N-1)]
for i in range(N-2):
    if l[i]+l[i+1] > max:
        k = N-i-1
        ans += ((k-1)*k*(k+1))//6
        break
    for j in range(i+1,N-1):
        if j == tc:
            ans += tp
            break
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > max:
            tc = j 
            tp = (N-j-1) * (N-j) //2 
            ans += tp
            break
        start = st[j]
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        st[j] = end
        ans += end-j-1
print(ans)

# Optimized solution
N = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
ans = 0
max = l[N-1]
tc = N
st = [j+1 for j in range(N-1)]
for i in range(N-2):
    if l[i]+l[i+1] > max:
        k = N-i-1
        ans += ((k-1)*k*(k+1))//6
        break
    for j in range(i+1,N-1):
        if j == tc:
            ans += tp
            break
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > max:
            tc = j 
            tp = (N-j-1) * (N-j) //2 #これをiの中でできないか
            ans += tp
            break
        start = st[j]
        if s <= l[start]:
            ans += start-j-1
            continue
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        st[j] = end
        ans += end-j-1
print(ans)