CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
cnt = 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[j] < l[i] < l[k]+l[j]:
                cnt += 1
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-2):
    for j in range(i+1, n-1):
        bi = bisect.bisect_left(l, l[i]+l[j])
        cnt += bi-j-1
print(cnt)
# Original solution
from itertools import combinations 

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

def is_triangle(a, b, c):
	return (a+b > c and a+c > b and b+c > a)

count = 0

for a, b, c in combinations(arr, 3):
	if is_triangle(a, b, c):
		count += 1
print(count)

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

arr.sort()
count = 0
for i in range(n-1, 0, -1):
	l, r = 0, i - 1
	while l < r:
		if arr[l] + arr[r] > arr[i]:
			count += r - l
			r -= 1
		else:
			l += 1
print(count)
# Original solution
import bisect
n=int(eval(input()))
L=[]*n
L=list(map(int,input().split()))
L.sort()
cnt=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ab=L[i]+L[j]
        num=bisect.bisect_left(L[j+1:],ab)
        cnt+=num
print(cnt)

# Optimized solution
import bisect
n=int(eval(input()))
L=[]*n
L=list(map(int,input().split()))
L.sort()
cnt=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ab=L[i]+L[j]
        num=bisect.bisect_left(L,ab,j+1,n)-j-1
        cnt+=num
print(cnt)
# Original solution
import sys
import itertools
import bisect
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
l = na()

l.sort()

ct = 0
for i in range(n):
    for j in range(i+1, n):
        tmp = l[i] + l[j]
        ct += bisect.bisect_left(l[j+1:], tmp)
print(ct)







# Optimized solution
import sys
import itertools
import bisect
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
l = na()

l.sort()

ct = 0
for i in range(n):
    for j in range(i+1, n):
        tmp = l[i] + l[j]
        ct += bisect.bisect_left(l, tmp) - (j + 1)
print(ct)
# Original solution
import bisect
N = int(eval(input()))
L = sorted(list(map(int,input().split())))
lenl = len(L)
count = 0
for i in range(0,lenl-2):
    for j in range(i+1,lenl-1):
        count += bisect.bisect_left(L[j+1:],L[i]+L[j])
print(count)

# Optimized solution
import bisect
N = int(eval(input()))
L = sorted(list(map(int,input().split())))
lenl = len(L)
count = 0
for i in range(0,lenl-2):
    for j in range(i+1,lenl-1):
        count += bisect.bisect_left(L,L[i]+L[j])-j-1
print(count)
# Original solution
import itertools
n = int(eval(input()))
cnt = 0
l = list(map(int, input().split()))
for a, b, c in itertools.combinations(l, 3):
    if abs(b - c) < a < b + c:
        cnt += 1
print(cnt) 

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

# Optimized solution
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
x = []
for i in range(N-2):
    check = 0
    for j in range(i+1,N-1):
        for k in range(j+1+check,N):
            if L[k] < L[i]+L[j]:
                check += 1
            else:
                break
        ans += check
        check -= 1
print(ans)
# Original solution
n = int(eval(input()))
l = list(map(int,input().split()))
ans = 0
l.sort()
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i]+l[j]>l[k]:
                ans += 1
            else:
                break
print(ans)

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

def bisec(i,k): #ギリギリokなj<=j_を探す
    ci = i
    ck = k
    i+=1
    k-=1
    j = int((i+k)/2)
    while k-i>1:
        if l[ci]+l[j]>l[ck]:
            k = j
            j = int((i+k)/2)
        else:
            i = j+1
            j = int((i+k)/2)
    if l[ci]+l[i]>l[ck]:
        return True,i
    elif l[ci]+l[i+1]>l[ck]:
        return True,i+1
    else:
        return False,-1

for i in range(n):
    for k in range(i+2,n):
        f,j = bisec(i,k)
        if f:
            ans += k-j
print(ans)
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))

l.sort(reverse=True)
m = sorted(l)
#print(l)
# print(m)

import bisect

ans = 0
for i in range(n-2):
  a = l[i]
  for j in range(i+1,n-1):
    b = l[j]
    x = a-b
    ind = bisect.bisect_right(m,x)
    #print(a, b, j, ind)
    if n-1-j-ind >= 0:
      ans += n-1-j-ind

print(ans)


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

L.sort()
import bisect
ans = 0
for i in range(n-2):
    b = L[i]
    for j in range(i+1, n-1):
        c = L[j]
        p = bisect.bisect_left(L, b+c)
        #print(b, c, j, p, p-j-1)
        ans += max(p-j-1, 0)
print(ans)
# Original solution
import itertools

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

a = tuple(itertools.combinations(lis,3))
b = 0

for i in a:
    if i[0] < i[1] + i[2] and i[1] < i[2] + i[0] and i[2] < i[0] + i[1]:
        b += 1
print(b)


# Optimized solution
import bisect

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

a = sorted(lis, reverse=True)
c = sorted(lis)
d = 0

for i in range(n):
    for j in range(i + 1, n):
        e = c[:-j-1]
        b = bisect.bisect_right(e, int(a[i]-a[j]))
        d += max(0, len(e) - b)
print(d)
# Original solution
n = int(eval(input()))
L = list(map(int, input().split()))

# 各数値が何個あるか
C = [0]*(2100)
for l in L:
    C[l] += 1

# 累積和を作成する
S = [0]
for i in range(2100):
    S.append(S[i]+C[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]
        tmp = S[right]-S[left]

        if left <= L[i] <= right:
            tmp -= 1
        if left <= L[j] <= right:
            tmp -= 1
        ans += max(0, tmp)

print((ans//6))


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

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

import itertools
com = list(itertools.combinations(L, 3))

count = 0
for i in com:
    #print(i)
    if (i[0] < i[1] + i[2]) and (i[1] < i[0] + i[2]) and (i[2] < i[1] + i[0]):
        count += 1

print(count)

# Optimized solution

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

L.sort()
#print(L)

count = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            #print(i, j, k)
            #print(L[i], L[j], L[k])
            #print(L[i] + L[j] > L[k])
            if L[k] >= L[i] + L[j]:
                break
            count += 1

print(count)
# Original solution
n = int(eval(input()))
l_ls = list(map(int, input().split()))
l_ls.sort()
def check(a,b,c):
    return abs(a-b) < c < a+b
ans = 0
for i in range(n):
    short = l_ls[i]
    num = 0
    r = i+1
    for l in range(i+1,n):
        while r+1 < n and check(short, l_ls[l], l_ls[r+1]):
            r += 1
        num += r - l
        if r == l:
            r += 1
    ans += num
print(ans)
            


# Optimized solution
n = int(eval(input()))
a_ls = list(map(int, input().split()))
def isOK(a,b,c):
    return abs(a-b) < c < a+b
a_ls.sort()
ans = 0
for i in range(n):
    short = a_ls[i]
    r = i+1
    num = 0
    for l in range(i+1,n-1):
        while r+1 < n and isOK(short, a_ls[l], a_ls[r+1]):
            r += 1
        num += r - l
        if l == r:
            r += 1
    ans += num
print(ans)
# Original solution
import itertools

def main():
  n = int(input())
  parts = list(map(int, input().split()))
  result = 0
  conditions = [
    lambda a,b,c: a<b+c,
    lambda a,b,c: b<c+a,
    lambda a,b,c: c<a+b,
  ]
  for comb in itertools.combinations(parts, 3):
    if all([func(*comb) for func in conditions]):
      result += 1
  print(result)

main()

# Optimized solution
def main():
  n = int(input())
  sticks = list(sorted(map(int, input().split())))
  result = 0

  for x in range(n):
      z = x + 2
      for y in range(x+1, n):
          while (z < n and sticks[x] + sticks[y] > sticks[z]):
              z += 1
          result += z - y -1
  print(result)

main()
# Original solution
N=int(eval(input()))
y=list(map(int, input().split()))
from itertools import combinations
C=list(combinations(list(range(N)), 3))

def cond(a, b, c):
  c1=a+b>c
  c2=b+c>a
  c3=c+a>b
  if c1 and c2 and c3:
    return True
  else:
    return False

ans=0
for c in C:
  if cond(y[c[0]], y[c[1]], y[c[2]]):
    ans+=1

print(ans)
  

# Optimized solution
N=int(eval(input()))
y=list(map(int, input().split()))
y.sort()
ans=0
for i in range(N-2):
  for j in range(i+1, N-1):
    tmp=y[i]+y[j]
    for k in range(j+1, N):
      if y[k]<tmp:
        ans+=1
      else:
        break
print(ans)
# Original solution
from bisect import bisect_left
N=int(eval(input()))
y=list(map(int, input().split()))
y.sort()
ans=0
for i in range(N-2):
  for j in range(i+1, N-1):
    tmp=y[i]+y[j]
    ans+=bisect_left(y[(j+1):],tmp)
print(ans)

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

N = int(eval(input()))
L = [int(a) for a in input().split()]

comb_sides = list(itertools.combinations(L, 3))

num_triangles = 0
for sides in comb_sides:
    if sides[0] + sides[1] > sides[2] and sides[1] + sides[2] > sides[0] and sides[2] + sides[0] > sides[1]:
        num_triangles += 1

print(num_triangles)


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

L.sort()

num_triangles = 0
for i in range(0, N - 2): # 0, 1, ..., N - 3
    for j in range(i + 1, N - 1): # i+1, i+2, ..., N-2
        for k in range(j + 1, N):
            if L[i] + L[j] <= L[k]:
                break
            else:
                num_triangles += 1

print(num_triangles)
# Original solution
from itertools import combinations,combinations_with_replacement

N = int(eval(input()))

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

comb_list = list(combinations(L,3))

ans = 0

for i in range(len(comb_list)):

	a, b, c = comb_list[i]
	if (a < b + c) and (b < a + c) and (c < a + b):
		ans += 1

print(ans)

# Optimized solution
def findnumberofTriangles(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 

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

print((findnumberofTriangles(L)))
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))

def meguru_nibutan(ar,m,key):
    a = m
    b = len(ar)
    while(abs(a-b) > 1):
        c = (a+b)//2
        if (ar[c] > key):
            a = c
        else:
            b = c
    return a

def main():
    cnt = 0
    l.sort(reverse=True)
    for a in range(0,n-2):
        for b in range(a+1,n-1):
            cnt += meguru_nibutan(l,b,l[a]-l[b]) - b
    print(cnt)

if (__name__ == "__main__"):
    main()

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

def meguru_nibutan(ar,m,key):
    a = m
    b = len(ar)
    while(abs(a-b) > 1):
        c = (a+b)//2
        if (ar[c] > key):
            a = c
        else:
            b = c
    return a

def main():
    cnt = 0
    l.sort()
    for a in range(0,n-2):
        for b in range(a+1,n-1):
            #cnt += meguru_nibutan(l,b,l[a]-l[b]) - b
            cnt += bisect.bisect_left(l,l[a]+l[b]) - 1 - b
    print(cnt)

if (__name__ == "__main__"):
    main()
# Original solution
N=int(eval(input()))
L=list(map(int,input().split()))

import bisect
L.sort()
ans=0
i=0
while i<N-2:
    j=i+1
    while j<N-1:
        x=bisect.bisect_left(L[j+1:],L[i]+L[j])
        ans+=x
        j+=1
    i+=1
print(ans)




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

L.sort()
ans=0
i=0
while i<N-2:
    j=i+1
    k=j+1
    while j<N-1:
        while k<N:
            if L[i]+L[j]<=L[k]:
                ans+=k-j-1
                break
            k+=1
        if k==N:
            ans+=k-1-j
        j+=1
    i+=1
print(ans)
# Original solution
from itertools import combinations

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

ans = 0
for c in comb:
    if c[0] + c[1] - c[2] > 0:
        ans += 1

print(ans)


# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
# print(l)
ans = 0
for i in range(len(l)):
    for j in range(i+1, len(l)):
        k = j + 1
        if k == len(l):
            continue
        if l[i] + l[j] <= l[k]:
            continue
        while k + 1 < len(l) and l[i] + l[j] > l[k+1]:
            k += 1
        ans += k - j

print(ans)
# Original solution
def main():
    n = int(eval(input()))
    l_list = list(map(int, input().split()))
    l_list.sort()
    max_l = max(l_list)

    ans = 0
    for i, a in enumerate(l_list):
        for j, b in enumerate(l_list[i+1:]):
            if b - a > max_l:
                break
            for k, c in enumerate(l_list[i+1+j+1:]):
                # if is_ok(a, b, c):
                if c < a + b:
                    ans += 1
                else:
                    break
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import bisect


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

    ans = 0
    for i, a in enumerate(l_list):
        for j, b in enumerate(l_list[i+1:]):
            x = a + b
            temp = bisect.bisect_left(l_list, x)
            ans += temp - (i + 1 + j + 1)
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
N=int(eval(input()))
L=list(map(int,input().split()))
L.sort()
from bisect import bisect_left
ans = 0
for i1 in range(N-2):
  for i2 in range(i1+1,N-1):
    l1,l2 = L[i1],L[i2]
    th = bisect_left(L[i2+1:],l1+l2)
    #print(l1,l2,L[i2+1:],(l2-l1+1)*(-1),th)
    ans += th
print(ans)

# Optimized solution
N=int(eval(input()))
L=list(map(int,input().split()))
L.sort()
from bisect import bisect_left
ans = 0
for i1 in range(N-2):
  for i2 in range(i1+1,N-1):
    l1,l2 = L[i1],L[i2]
    #th = bisect_left(L[i2+1:],l1+l2)
    #print(l1,l2,L[i2+1:],(l2-l1+1)*(-1),th)
    th = bisect_left(L,l1+l2)
    ans += max(th-i2-1,0)
print(ans)
# Original solution
n=eval(input())
li=list(map(int,input().split()))

li.sort()
mod_li=[[i,num] for i,num in enumerate(li)]

result=0
for i in range(len(li)-2):
  for j in range(i+1,len(li)-1):
    temp_li=[num for num in mod_li[j+1:]]
    while(len(temp_li)>1):
      if temp_li[len(temp_li)//2][1]>=li[i]+li[j]:
        temp_li=temp_li[:len(temp_li)//2]
      else:
        temp_li=temp_li[len(temp_li)//2:]
    if temp_li[0][1]>=li[i]+li[j]:
      result+=temp_li[0][0]-j-1
    else:
      result+=temp_li[0][0]-j
print(result)

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

li.sort()
#mod_li=[[i,num] for i,num in enumerate(li)]

result=0
for i in range(len(li)-2):
  tmp=i+2
  for j in range(i+1,len(li)-1):
    for k in range(tmp,len(li)):
      if li[i]+li[j]<=li[k]:
        tmp=k-1
        if tmp-j>0:
          result+=tmp-j
        break
      elif k==len(li)-1:
        tmp=k
        result+=tmp-j
        break
print(result)
# Original solution
from bisect import bisect_left

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

    ans = 0
    for ia in range(N):
        for ib in range(ia+1, N-1):
            a = L[ia]
            b = L[ib]
            ic_end = bisect_left(L, a+b, lo=ib+1)
            ans += ic_end - (ib+1)

    print(ans)
main()

# Optimized solution
def main():
    N = int(eval(input()))
    L = sorted(list(map(int, input().split())))
    ans = 0
    for ia in range(N-2):
        a = L[ia]
        ic = ia + 2
        for ib in range(ia+1, N-1):
            b = L[ib]
            while ic < N and L[ic] < a+b:
                ic += 1
            ans += ic - (ib + 1)
    print(ans)
main()
# Original solution
import copy
N = int(eval(input()))
L = list(map(int,input().split()))

cnt = 0

for a in L:
    L2 = copy.deepcopy(L)
    L2.remove(a)
    for b in L2:
        L3 = copy.deepcopy(L2)
        L3.remove(b)
        for c in L3:
            if a<b+c and b<c+a and c<a+b:
                cnt+=1
print((cnt//6))

# Optimized solution
import bisect
 
n=int(eval(input()))
a=list(map(int,input().split()))
a=sorted(a)
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        tmp=a[i]+a[j]
        index=bisect.bisect_left(a,tmp)
        ans+=index-j-1
print(ans)
# Original solution
n = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
#s = input()
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    tmp = l[i] + l[j]
    for k in range(j+1,n):
      #print(i,j,k)
      if tmp > l[k]:
        ans += 1
      else:
        break

print(ans)

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


input = sys.stdin.readline

def main():
    N = int(eval(input()))
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i, a in enumerate(L):
        if i > N-2:
            break
        for j, b in enumerate(L):
            if j > N-1:
                break
            if j <= i:
                continue
            # print(a, b)
            c_right = bleft(L, a+b)
            # print(c_right)
            if c_right == 0:
                continue
            now_seq = L[j+1:c_right]
            c_left = bright(now_seq, b-a)
            if c_left == N:
                continue
            ans += len(now_seq) - c_left
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
import bisect


input = sys.stdin.readline

def main():
    N = int(eval(input()))
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i, a in enumerate(L):
        if i > N-2:
            break
        for j, b in enumerate(L):
            if j > N-1:
                break
            if j <= i:
                continue
            c_right = bleft(L[j+1:], a+b)
            ans += c_right
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
# D TLE
import itertools
import bisect

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

L.sort()
value = 0

for i, j in itertools.combinations(list(range(len(L)-1)), 2):
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=index

print(value)

# 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)
    ans += max(0, idx-j-1)
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))

import itertools
l = list(itertools.combinations(L, 3))

a = 0
n = 0

for x in range(len(l)):
  m = max(l[n])
  if m < sum(l[n]) - m:
    a += 1
    n += 1
  else:
    n += 1
    
print(a)

# Optimized solution
N = int(eval(input()))
l = [int(x) for x in input().split()]
l.sort(reverse=True)
ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    a = l[j+1:]
    for x in range(len(a)):
      if l[i] < l[j] + a[x] and abs(l[j] - a[x]) < l[i]:
        ans += 1
print(ans)
# Original solution
import itertools
n=int(eval(input()))
l=list(map(int,input().split(' ')))


ans=0
for com in list(itertools.combinations(l,3)):
    com=sorted(com)
    if com[2]<com[0]+com[1]:
        ans+=1

print(ans)

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

ans=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]<l[j]+l[k]:
                if l[j]<l[i]+l[k]:
                    if l[k]<l[i]+l[j]:
                        ans+=1
            else:
                continue
                
print(ans)
# Original solution
import itertools
n = int(eval(input()))
L = list(map(int, input().split()))

#%%
ans = 0
for c in itertools.combinations(L, 3):
    if (c[0] < c[1] + c[2]) and (c[1] < c[0] + c[2]) and (c[2] < c[0] + c[1]):
        ans += 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): # aを固定
    for j in range(i+1, n-1): # bを固定
        ab = L[i] + L[j]
        idx = bisect.bisect_left(L, ab, lo=j)
        ans += max(idx - (j+1), 0)

print(ans)
# Original solution
import itertools

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

len_combs = list(itertools.combinations(lengths, 3))
res = sum([a < b + c and b < c + a and c < a + b for a, b, c in len_combs])

print(res)


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

res = 0
sorted_lengths = sorted(lengths)[::-1]
for i in range(n):
	l1 = sorted_lengths[i]
	for j in range(i+1, n):
		l2 = sorted_lengths[j]
		res += sum([l1 - l2 < _ < l1 + l2 for _ in sorted_lengths[j + 1:]])
		
print(res)
# Original solution
from bisect import bisect_left

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

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		rem = lengths[j + 1:]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)

# Optimized solution
from bisect import bisect_left

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

res = 0
for i in range(n):
	l1 = lengths[i]
	for j in range(i + 1, n - 1):
		l2 = lengths[j]
		res += bisect_left(lengths, l1 + l2, j + 1) - j - 1

print(res)
# Original solution
# n = int(input())
# a, b = map(int, input().split())
# an = list(map(int, input().split()))

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

ln.sort(reverse=True)

bcs = []
for i in range(1, n-1):
  row = []
  for j in range(i+1, n):
    row.append(ln[i] + ln[j])
  bcs.append(row)

cnt = 0
ix = [0 for _ in range(n-2)]
# a > b,c
for i in range(n-2):
  a = ln[i]
  for j in range(i, n-2):
    try:
      while ix[j] < (n - 2 - j) and bcs[j][ ix[j] ] > a:
        ix[j] += 1
    except:
      print((j, ix[j]))
      exit()
  cnt += sum(ix[i:])
print(cnt)

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

ln.sort(reverse=True)

bcs = []
for i in range(1, n-1):
  row = []
  for j in range(i+1, n):
    row.append(ln[i] + ln[j])
  bcs.append(row)

cnt = 0
ix = [0 for _ in range(n-2)]
# a > b,c
for i in range(n-2):
  a = ln[i]
  for j in range(i, n-2):
    try:
      while ix[j] < (n - 2 - j) and bcs[j][ ix[j] ] > a:
        ix[j] += 1
    except:
      print((j, ix[j]))
      exit()
  cnt += sum(ix[i:])
print(cnt)