CodeEff/ECCO huggingface dataset:
# Original solution
import bisect
n = int(eval(input()))
l = sorted(list(map(int,input().split())))
ans = 0          
for ai in range(n):
  for bi in range(ai+1,n):
    ci = bisect.bisect_left(l,l[ai]+l[bi])
    if ci>bi:
      ans += ci-bi-1
print(ans)

# Optimized solution
n = int(eval(input()))
l = sorted(list(map(int,input().split())))
ans = 0
for ai in range(n):
  for bi in range(ai+1,n):
    ok,ng = bi,n
    while ng-ok>1:
      mid = (ng+ok)//2
      if l[mid]<l[ai]+l[bi]:
        ok = mid
      else:
        ng = mid
    ans += ok-bi
print(ans)
# Original solution
import bisect
from copy import deepcopy
N = int(eval(input()))
L = sorted(map(int, input().split()))

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

print(ans)


# Optimized solution
import bisect
n = int(eval(input()))
L = sorted(map(int, input().split()))
m = L[-1]
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        k = L[i] + L[j]
        ans += bisect.bisect_left(L, k) - j-1
print(ans)
# Original solution
import itertools, bisect

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):
        cindex = bisect.bisect_left(L, int(L[i]) + int(L[j]))
        for _ in reversed(list(range(j+1, cindex))):
            ans += 1

print(ans)

# Optimized solution
import itertools, bisect

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):
        cindex = bisect.bisect_left(L, int(L[i]) + int(L[j]))
        ans += cindex-1 - j

print(ans)
# Original solution
from itertools import combinations
n = int(eval(input()))
l = list(map(int, input().split()))
combination_line = list(combinations(l, 3))
count = 0
for i in combination_line:
    line1 = i[0]
    line2 = i[1]
    line3 = i[2]
    if line1 < line2 + line3 and line2 < line1 + line3 and line3 < line1 + line2:
        count += 1

print(count)


# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
sort_l = sorted(l)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):        
        for k in range(j+1, n):
            two_line = sort_l[i] + sort_l[j]
            one_line = sort_l[k]
            if two_line > one_line:
                count += 1

print(count)
# Original solution
import itertools
N = int(eval(input()))
d_list = list(map(int, input().split()))
c_d_list = list(itertools.combinations(d_list, 3))
count = 0
for i in c_d_list:
    a = i[0]
    b = i[1]
    c = i[2]
    if a < b + c:
        if b < a + c:
            if c < a + b:
                count += 1
print(count)

# Optimized solution
import itertools
N = int(eval(input()))
d_list = list(map(int, input().split()))
c_d_list = list(itertools.combinations(d_list, 3))
count = 0
for i in c_d_list:
    a = i[0]
    b = i[1]
    c = i[2]
    if a < b + c and b < a + c and c < a + b:
        count += 1
print(count)
# Original solution
n = int(eval(input()))
d = list([int(x) for x in input().split()])

res = 0


def is_triangle(i, j, k):
    return 1 if i < j + k and j < i + k and k < i + j else 0


i = 0
j = 1
k = 2

while i < n:
    while j < n:
        while k < n:
            res += is_triangle(d[i],d[j],d[k])
            k += 1
        j += 1
        k = j + 1
    i += 1
    j = i + 1
    k = j + 1


print(res)

# Optimized solution
n = int(eval(input()))
d = list([int(x) for x in input().split()])
d.sort()

res = 0

for i in range(n-2):
    k = i + 2
    for j in range(i+1, n-1):
        while k < n and d[i] + d[j] > d[k]:
            k += 1
        if k > j:
            res += k - j - 1

print(res)
# Original solution
n = int(eval(input()))
d = list([int(x) for x in input().split()])
d.sort()

res = 0

for i in range(n-2):
    k = i + 2
    for j in range(i+1, n-1):
        while k < n and d[i] + d[j] > d[k]:
            k += 1
        if k > j:
            res += k - j - 1

print(res)

# Optimized solution
def find_triangle_count(d):
    n = len(d)
    d.sort()
    res = 0
    for i in range(n - 2):
        k = i + 2
        for j in range(i + 1, n - 1):
            while k < n and d[i] + d[j] > d[k]:
                k += 1
            if k > j:
                res += k - j - 1
    return res


def solve():
    eval(input())
    input_list = list([int(x) for x in input().split()])
    print((find_triangle_count(input_list)))


if __name__ == '__main__':
    solve()
# Original solution
from itertools import combinations
n = int(eval(input()))
l = [int(x) for x in input().split()]
l1 = list(combinations(l, 3))
c = 0
for i in l1:
	if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[0] + i[1]:
		c += 1
print(c)

# Optimized solution
def findnumberofTriangles(arr): 
  
    # Sort array and initialize count as 0 
    n = len(arr) 
    arr.sort() 
    count = 0
  
    # Fix the first element. We need to run till n-3 as 
    # the other two elements are selected from arr[i+1...n-1] 
    for i in range(0,n-2): 
  
        # Initialize index of the rightmost third element 
        k = i + 2
  
        # Fix the second element 
        for j in range(i+1,n): 
  
            # Find the rightmost element which is smaller 
            # than the sum of two fixed elements 
            # The important thing to note here is, we use 
            # the previous value of k. If value of arr[i] + 
            # arr[j-1] was greater than arr[k], then arr[i] + 
            # arr[j] must be greater than k, because the array 
            # is sorted. 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
            # Total number of possible triangles that can be 
            # formed with the two fixed elements is k - j - 1. 
            # The two fixed elements are arr[i] and arr[j]. All 
            # elements between arr[j+1] to arr[k-1] can form a 
            # triangle with arr[i] and arr[j]. One is subtracted 
            # from k because k is incremented one extra in above 
            # while loop. k will always be greater than j. If j 
            # becomes equal to k, then above loop will increment k, 
            # because arr[k] + arr[i] is always greater than arr[k] 
            if(k>j): 
                count += k - j - 1
  
    return count
n = int(eval(input()))
l = [int(x) for x in input().split()]
print((findnumberofTriangles(l)))
# Original solution
import bisect
def main():
    N = int(eval(input()))
    L = list(map(int,input().split()))
    L.sort()
    Lind = []
    count = 0
    for i in reversed(list(range(2,N))):
        for j in reversed(list(range(1,i))):
            if L[i] < 2*L[j]:
                Lind.append([i,j])
    for l in Lind:
        cind = bisect.bisect_left(L,L[l[0]]-L[l[1]])
        for k in range(cind,l[1]):
            if L[l[0]]<L[l[1]]+L[k]:
                count += 1
    print(count)
main()

# Optimized solution
import bisect
def main():
    N = int(eval(input()))
    L = list(map(int,input().split()))
    L.sort()
    
    count = 0
    for i in range(N-2):
        for j in range(i+1,N-1):
            c = bisect.bisect_left(L,L[i]+L[j])
            
            count += max(0,c-1 - j)
    
    print(count)
main()
# Original solution
N = int(eval(input()))
L = input().split()
L = [int(L[i]) for i in range(len(L))]

tri = 0
bar = [[L[i], L[j], L[k]] for i in range(N) for j in range(i+1,N) for k in range(j+1,N)]
for i in range(len(bar)):
  if bar[i][0] + bar[i][1] > bar[i][2]:
    if bar[i][0] + bar[i][2] > bar[i][1]:
      if bar[i][1] + bar[i][2] > bar[i][0]:
        tri += 1
print(tri)

# Optimized solution
N = int(eval(input()))
L = input().split()
L = [int(L[i]) for i in range(len(L))]
L.sort(reverse=True)
tri = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if L[k] + L[j] > L[i]:
        tri += 1
print(tri)
# Original solution
import bisect
import copy
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  for j in range(i+1,n):
    if i==j:
      continue
    b=copy.deepcopy(a)
    b.remove(a[i])
    b.remove(a[j])
    ans+=bisect.bisect_left(b,a[i]+a[j])-j+1
print(ans)

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

count=0
L.sort()
A=list(it.combinations(L,3))

for a in A:
    if a[2]<a[0]+a[1]:
        count+=1

print(count)

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

count=0
l=sorted(L,reverse=True)

for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if l[i]<l[j]+l[k]:
                count+=1



print(count)
# Original solution
n  = int(eval(input()))
arr = [int(i) for i in input().split()]
arr.sort()

works= lambda a,b,c : (a<(b+c)) and (b<(a+c)) and (c<(b+a))

total = 0

for i in range(n):
    aI = arr[i]
    for j in range(i+1,n):
        aJ = arr[j]
        for k in range(j+1,n):
            if works(arr[k],aI,aJ):
                total+=1
            else:
                break

print(total)


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

total = 0

for i in range(n-2):
    aI = arr[i]
    k = i + 2
    
    for j in range(i+1,n):
        mySum = aI+arr[j]

        while (k<n) and arr[k]<mySum:
            k+=1
            
        if k>j:
            total+= k-j-1

print(total)
# Original solution
import sys
import bisect
readline = sys.stdin.readline
n = int(readline())
A = list(map(int,readline().split()))
A.sort()
ans =0
for i in range(1,n):
    for j in range(i+1,n):
        ans += i- bisect.bisect(A,A[j]-A[i],hi=i)
print(ans)

# Optimized solution
import sys
import bisect
readline = sys.stdin.readline
n = int(readline())
A = list(map(int,readline().split()))
memo1 = {}
memo2 = {}
A.sort()
memo1[A[0]+A[1]] =1
memo2[A[0]] =1
if A[1] in memo2:
    memo2[A[1]] +=1
else:
    memo2[A[1]] =1
ans = 0
for c in A[2:]:
    for l,amount in list(memo1.items()):
        if c<l:
            ans +=amount
    for a,amount in list(memo2.items()):
        ac = a+c
        if ac in memo1:
            memo1[ac] += memo2[a]
        else:
            memo1[ac] = memo2[a]
    if c in memo2:
        memo2[c] +=1
    else:
        memo2[c] =1

print(ans)
# Original solution
import itertools
N = int(eval(input()))
L = list(map(int, input().split()))
lst = list(itertools.combinations(L, 3))
cnt = 0
for i in lst:
    if i[0]+i[1] > i[2] and i[1]+i[2] > i[0] and i[0]+i[2] > i[1]:
        cnt += 1
print(cnt)

# Optimized solution
N = int(eval(input()))
lst = list(map(int, input().split()))
lst.sort()
lst.append(10**10)
total = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        cnt = 0
        k = j+1
        while lst[j]+lst[i] > lst[k]:
            cnt += 1
            k += 1
        total += cnt
print(total)
# Original solution
import bisect
 
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
 
count = 0
# aとbを固定
for a in range(N-2):
    for b in range(a+1,N-1):
        aADDb = L[a] + L[b]
        maxL = bisect.bisect_left(L,aADDb)
        # cの範囲は、[b+1,maxL)
        count += max(0,maxL-(b+1))
 
print(count)

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

from bisect import bisect_left

ans = 0
# a < b < c
for a in range(N):
    for b in range(a+1, N):
        right = bisect_left(L, L[a] + L[b])
        # [b+1, right)
        ans += max(0, right - (b + 1))

print(ans)
# Original solution
n=int(eval(input()))
lengths=sorted([int(i) for i in input().split()])
import itertools as it
import math as ma

cnt=0
triangle=[list(i) for i in it.combinations(lengths,3)]

for i in range(len(triangle)):
    a=triangle[i].pop(0)
    b=triangle[i].pop(0)
    c=triangle[i].pop(0)
    if  ma.floor(b-a)<c<(b+a):
        cnt+=1

print(cnt)

# Optimized solution
import math
import itertools

n=int(eval(input()))
L=[int(i) for i in input().split()]
L.sort()

ans=0
for i in range(2,n):
  c=list(itertools.combinations(L[:i],2))
  for j in range(len(c)):
     if  math.floor(c[j][0]-c[j][1])<L[i]<c[j][0]+c[j][1]:
        ans+=1
print(ans)
# Original solution
from bisect import bisect_right
n=int(eval(input()))
L=[int(i) for i in input().split()]
L.sort()


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

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

def binary(a,b,mid):
  if  L[mid]+L[j]>L[i]:
    return True
  else:
    return False

ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    l=j
    r=n
    while r-l>1:
      mid=(r+l)//2
      if binary(i,j,mid):
        l=mid
      else:
        r=mid
    ans+=l-j
print(ans)
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))

l.sort()
ans = 0
for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        c_candidate = [k for k in l[j+1:] if k < a+b]
        ans += len(c_candidate)

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):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        ans += bisect.bisect_left(l, a+b)-j-1

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


# Optimized solution
from bisect import bisect_left
 
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
 
c = sum(bisect_left(l, l[i]+l[j])-j-1 for i in range(n-2) for j in range(i+1, n-1))
print(c)
# Original solution
def main():
    from bisect import bisect_right

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

    e.sort()

    ans = 0
    for j in range(2, N):
        for i in range(1, j):
            d = e[j] - e[i]
            ans += i - bisect_right(e, d, lo=0, hi=i)

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


# Optimized solution
def main():
    from bisect import bisect_right

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

    e.sort()

    ans = 0
    for j in range(2, N):
        for i in range(1, j):
            d = e[j] - e[i]
            ans += max(0, i - bisect_right(e, d))

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
# Original solution
from sys import stdin

N = int(stdin.readline())
L = [int(x) for x in stdin.readline().rstrip().split()]

L.sort()

tmp = 0

for i in range(N):

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

        for k in range(N-j-1):
            k = k + j + 1

            if L[k] < L[i] + L[j]:
                tmp = tmp + 1
            else:
                break

print(tmp)


# Optimized solution
# 本番では解けず。
from sys import stdin
import bisect

N = int(stdin.readline())
L = [int(x) for x in stdin.readline().rstrip().split()]

# (1)Lを昇順にソートする
L.sort()

s = 0

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

        # (2)Lから2つの辺を固定で選ぶ（L[i]をa L[j]をbとする）
        # この場合、a < b + c, b < a + c はソート済みのため自明。
        # c < a + b が成り立つ棒の個数を調べる
        tmp = L[i] + L[j]

        # (3)Lの中から(2)の和(a+b)、を左に挿入できる場所二分探索で探す
        # つまりL[index - 1] < L[i] + L[j] < L[index] になるindexを探す。

        index = bisect.bisect_left(L, tmp)

        # (4) 固定で選んだ大きい方の辺から(3)で見つけた棒の間にある棒の個数を足す
        # b より右にあり、これより左にあるもの　→　開区間　(L[j], L[index])に含まれる棒は c < a + b を満たすので。
        s += (index - (j+1))

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


# 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-2):
    for j in range(i+1,N-1):
        ans += bisect_left(L,L[i]+L[j])-(j+1)
print(ans)
# Original solution
n = int(eval(input()))
l = [int(i) for i in input().split()]
l.sort()
a = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(n - 1, j, -1):
            if l[i] + l[j] > l[k]:
                a += k - j
                break
print(a)


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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = l[i] + l[j]

        mi = 0
        ma = n - 1
        while mi != ma:
            m = (mi + ma) // 2 + 1
            if l[m] < a:
                mi = m
            else:
                ma = m - 1
        ans += max(0, mi - j)
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):
            index=bisect.bisect_left(L,L[i]+L[j])
            ans+=index-(j+1)
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-1):
    for j in range(i+1,n):
        idx=bisect.bisect_left(L,L[i]+L[j])
        ans+=idx-(j+1)
print(ans)
# Original solution
# coding: utf-8
def binary_search(x, L2):
    l, r = 0, len(L2)-1
    mid = (r + l) // 2
    while r - l > 1:
        mid = (r + l) // 2
        if L2[mid] == x:
            break
        elif L2[mid] > x:
            l = mid
        elif L2[mid] < x:
            r = mid
    if L2[r] > c:
        return r
    else:
        return l
    # return r

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
L = L[::-1]
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        c = a - b
        r = binary_search(c, L[j:]) + j
        if r > j and L[r] > c:
            ans += r - j
print(ans)

# Optimized solution
# coding: utf-8
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):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        ans += bisect_left(L, a+b) - 1 - j
print(ans)
# Original solution
import bisect
# 三角形の条件: c < a+b 

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

ans = 0
# a と b を固定
for a in range(N):
  for b in range((a+1), N):
    # c の動ける範囲の右端を求める
    c = L[a]+L[b]
    k = bisect.bisect_left(L, c)
    # c の動ける範囲は、[j+1, k)
    ans += k - b - 1
print(ans)    

# Optimized solution
import bisect
# 三角形の条件: c < a+b 

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

ans = 0
for i in range(N-1, 1, -1):
  a = 0
  b = i-1
  while a<b:
    if L[a]+L[b] > L[i]:
      ans += b-a
      b -= 1
    else:
      a += 1
          
print(ans)
# Original solution
from sys import stdin
import bisect

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

L.sort()

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

print(ans)    


# Optimized solution
from sys import stdin
import bisect

N = int(eval(input()))
L = list(map(int,stdin.readline().strip().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)
        ans += (idx-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-2):
  for j in range(i+1,n-1):
    res=l[i]+l[j]
    mid=bisect.bisect_left(l,res)
    ans+=mid-j-1
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):
  for j in range(i+1,n-1):
    res=l[i]+l[j]
    ans+=bisect.bisect_left(l,res)-1-j
print(ans)
# Original solution
import itertools

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

def is_rectangle(a,b,c):
    if a + b <= c:
      return False
    if b + c <= a:
      return False
    if c + a <= b:
        return False
    else:
        return True

x = [is_rectangle(a,b,c) for a, b, c in itertools.combinations(L, r=3)]


print((sum(x)))

# Optimized solution
#提出 #8086687

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
n=int(eval(input()))
l=list(map(int,input().split()))

l.sort()
cnt=0
for ind_a,a in enumerate(l[:-2]):
    for ind_b,b in enumerate(l[ind_a+1:-1]):
        for ind_c,c in enumerate(l[ind_a+ind_b+2:]):
            #print(a,b,c)
            if a+b<=c:
                cnt+=ind_c
                break
        if a+b>c:
            cnt+=ind_c+1

print(cnt)


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

l.sort()
l.append(10**9)
cnt=0
i=0
#print(l)

while i<n-2:
    j=i+1
    while j<n-1:
        LL=j+1
        RR=n-1
        #print("#",l[i],l[j],l[LL],l[RR])
        while LL<=RR:
            k=(LL+RR)//2
            if k==n:
                break
            #print(l)
            #print(i,j,LL,RR,k)
            #print(l[i]+l[j],l[k],l[k+1])
            if l[i]+l[j]>l[k] and l[i]+l[j]<=l[k+1]:
                cnt+=k-j
                break
            elif LL==RR:
                break
            elif l[i]+l[j]<=l[k]:
                RR=k
            elif l[i]+l[j]>l[k]:
                LL=k+1
            elif l[i]+l[j]<l[k] and k==j+1:
                break
        j+=1
    i+=1

print(cnt)
# Original solution
N = int(eval(input()))
L = list(map(int,input().split(' ')))

L.sort()
#print(L)


cnt = 0
for i in range(N-2):
    highJ = 0
    for j in range(i+1,N-1):
        tmphighJ = max(j,highJ)
        for k in range(max(j+1,highJ+1),N):
            if L[k] < L[i]+L[j]:
                tmphighJ = k
            else:
                break
        highJ = max(j,tmphighJ)
        cnt+= tmphighJ - j
        #print(i,j,highJ,cnt)

print(cnt)
            

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

L.sort()
#print(L)

cnt = 0
order =0
for i in range(N-2):
    highJ = 0
    for j in range(i+1,N-1):
        tmphighJ = max(j,highJ)
        for k in range(max(j+1,highJ+1),N):
            order+=1
            if L[k] < L[i]+L[j]:
                tmphighJ = k
            else:
                break
        highJ = max(j,tmphighJ)
        cnt+= highJ - j
        #print(i,j,highJ,cnt)

print(cnt)
#print(order)
# Original solution
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = [ int(x) for x in sys.stdin.readline().strip().split() ]
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)


# Optimized solution
#!/usr/bin/env python3

import sys
from bisect import bisect_left

n = int(sys.stdin.readline().strip())
l = list(map(int,sys.stdin.readline().strip().split()))
    
l.sort()
c = 0
n1 = n - 1
for i in range(n-2):
    li = l[i]
    for j in range(i+1,n1):
        k = bisect_left(l,l[j]+li,lo=j)
        c += k-j-1
#
print(c)