CodeEff/ECCO huggingface dataset:
# 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 #これを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)

# Optimized 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):
        s = l[i]+l[j]
        start = j+1
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        ans += end-j-1
print(ans)
# Original solution
N = int(eval(input()))
L = [int(x) for x in input().split()]

import bisect
L = sorted(L)
ans = 0
for i in range(1, N - 1):
    for j in reversed(list(range(i + 1, N))):
        k = bisect.bisect_right(L[0:i], L[j] - L[i])
        ans += i - k
print(ans)

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

import bisect
L = sorted(L)
ans = 0
for i in range(N - 2):
    for j in reversed(list(range(i + 1, N - 1))):
        k = bisect.bisect_left(L, L[i] + L[j], j)
        ans += k - j - 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):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]

        idx = bisect_left(L, a+b)
        ans += max(idx - (j+1), 0)

print(ans)


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

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

print(ans)
# Original solution
from itertools import permutations, combinations,combinations_with_replacement,product

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

L.sort()

cnt = 0
l = list(combinations(L,3))

for i in l:
    if i[0] + i[1] > i[2]:
        cnt += 1
    else:
        pass

print(cnt)


# Optimized solution
from itertools import permutations, combinations,combinations_with_replacement,product

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

L.sort()

cnt = 0

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]:
                cnt += 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):
    a = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        for k in range(j + 1, n):
            c = L[k]
            if c >= a + b:
                break
            ans += 1
print(ans)


# Optimized solution
n = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 2):
    a = L[i]
    k = i
    for j in range(i + 1, n - 1):
        b = L[j]
        while k < n and L[k] < a + b:
            k += 1
        ans += k - (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(1,N-1):
  for j in range(i+1,N):
    a=l[i]
    b=l[j]
    ans+=i-bisect.bisect_right(l[:i],b-a)
print(ans)

# Optimized solution
import bisect
N=int(eval(input()))
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(1,N-1):
  for j in range(i+1,N):
    m=bisect.bisect_right(l,l[j]-l[i])
    if i>m:
      ans+=i-m
print(ans)
# Original solution
n = int(eval(input()))
ll = [int(w) for w in input().split()]
ll.sort(reverse=True)

ans = 0
for ei, i in enumerate(ll):
    for ej, j in enumerate(ll[ei + 1:]):
        ans += len([w for w in ll[ei + ej + 2:] if w > i - j])

print(ans)


# Optimized solution
import bisect

n = int(eval(input()))
ll = [int(w) for w in input().split()]
ll.sort()

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

print(ans)
# Original solution
from bisect import bisect_left, bisect_right

n = int(eval(input()))

l_list = [int(x) for x in input().split()]
l_list.sort()

ans = 0
for i in range(n - 2):
    continue_flag = False
    for j in range(i + 1, n - 1):
        l = bisect_right(l_list, l_list[j] - l_list[i])
        l = l if l > j else j + 1
        if l == n:
            continue_flag = True
            break

        r = bisect_left(l_list, l_list[j] + l_list[i])

        ans += r - l

    if continue_flag:
        continue
print(ans)

# Optimized solution
from bisect import bisect_left

n = int(eval(input()))

l_list = [int(x) for x in input().split()]
l_list.sort()
# print(l_list)

ans = 0
for i in range(n - 2):
    continue_flag = False
    for j in range(i + 1, n - 1):
        ans += bisect_left(l_list, l_list[j] + l_list[i]) - (j + 1)
print(ans)
# Original solution
import itertools as it

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

com=list(it.combinations(l,3))
# print(com)
# print(len(com))

cnt=0
for i in com:
    if i[0]+i[1]>i[2] and i[1]+i[2]>i[0] and i[0]+i[2]>i[1]:
        cnt+=1
    else:
        cnt+=0
print(cnt)

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

cnt=0
for i in range(N-1):
    for j in range(i+1,N):
        k=j+1
        while k<N:
            if l[i]+l[j]>l[k]:
                cnt+=1
                k+=1
            else:
                cnt+=0
                k+=1
print(cnt)
# Original solution
import itertools
N = int(eval(input()))
L = list(map(int, input().split()))
A = list(itertools.combinations(L, 3))
ans = 0
for i in A:
    if i[0] >= i[1]+i[2]:
        continue
    if i[1] >= i[0]+i[2]:
        continue
    if i[2] >= i[1]+i[0]:
        continue
    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-1, 1,-1):
    for j in range(i-1,0,-1):
        x = L[i]-L[j]
        maxindex = bisect.bisect_right(L, x)
        if j>maxindex:
            ans += j-maxindex

print(ans)
# Original solution
import bisect


def LI():
    return list(map(int, input().split()))


N = int(eval(input()))
L = LI()
L.sort()
ans = 0

for i in range(N-1, 1, -1):
    for j in range(i-1, 0, -1):
        xl = L[i]-L[j]
        ind = bisect.bisect_right(L, xl)
        if j > ind:
            ans += j-ind
print(ans)


# Optimized solution
import bisect


def LI():
    return list(map(int, input().split()))


N = int(eval(input()))
L = LI()
L.sort()
ans = 0
for i in range(N-1, 1, -1):
    for j in range(i-1, 0, -1):
        ind = bisect.bisect_right(L, L[i]-L[j])
        if ind < j:
            ans += j-ind
print(ans)
# Original solution
import bisect
N = int(eval(input()))
ans = 0
L = list(map(int,input().split()))
L = sorted(L)
for i in range(N-1):
    for j in range(i+1,N):
        a = bisect.bisect(L,L[i]+L[j])
        if L[i]+L[j] in L:
            a -= 1
        ans += a-j-1
     
print(ans)        
        

# Optimized solution
import bisect
N = int(eval(input()))
ans = 0
L = list(map(int,input().split()))
L = sorted(L)
for i in range(N-1):
    for j in range(i+1,N):
        a = bisect.bisect(L,L[i]+L[j]-1)
       
        ans += a-j-1

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


def check(a, b, c):
    return (a < b+c) and (b < c+a) and (c < a+b)


for i, j, k in combinations(L, 3):
    c += check(i, j, k)

print(c)


# Optimized solution
from bisect import bisect_left
N = int(eval(input()))
L = sorted([int(i) for i in input().split()])

res = 0

for i in range(N):
    for j in range(i+1, N):
        r = bisect_left(L, L[i]+L[j])
        res += max(r-(j+1), 0)

print(res)
# Original solution
# coding: utf-8
import itertools
num = int(eval(input()))
lines = list(int(i) for i in input().split())
lines.sort(reverse=True)
counter = 0

comb = itertools.combinations(lines, 3)

for c in comb:
  cl = list(c)
  if cl[0] < cl[1] + cl[2]:
    counter += 1
    
print(counter)

# Optimized solution
import bisect
n = int(eval(input()))
lines = list(int(i) for i in input().split())
lines.sort()
counter = 0

for i in range(n-2):
  for j in range(i+1, n-1):
    counter += bisect.bisect_left(lines, lines[i] + lines[j]) - (j + 1)
    
print(counter)
# Original solution
import bisect
N=int(eval(input()))
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(len(L)-1):
  for j in range(i+1,len(L)):
    left=bisect.bisect_left(L, L[i]+L[j])
    right=bisect.bisect_right(L, L[j]-L[i])
    if left > j:
      ans+=left-j-1
 # break
print(ans)

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

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

for i in range(l):
    s = sorted(C[i])
    if s[0] + s[1] <= s[2]:
        pass
    else:
        count = count + 1

print(count)

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

import bisect
for i in range(N - 2):
    for  j in range(N - i - 2):
        s = C[i] + C[j + i + 1]
        t = bisect.bisect_left(C,s)
        u = t - (j + i + 1) - 1
        if u <= 0:
            pass
        else:
            count = count + u

print(count)
# Original solution
from bisect import bisect_left
n = int(eval(input()))
llist = list(map(int, input().split()))

llist.sort()
res = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        num = llist[i] + llist[j] 
        idx = bisect_left(llist, num, lo=j+1, hi=n)
        res += idx - j - 1

print(res)

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

llist.sort()
res = 0
for i in range(n-2):
    prev = n-1
    for j in range(n-2,i,-1):
        for k in range(prev, j, -1):
            if llist[k] < llist[i] + llist[j]:
                res += k - j
                prev = k
                break            
print(res)
# Original solution
import bisect
n = int(eval(input()))
l = list(map(int, input().split()))
count = 0
l.sort(reverse = False)
for i in range(len(l)-1, 1, -1):
  for j in range(i-1, 0, -1):
    pt = bisect.bisect_right(l, l[i] - l[j])
    count += max(j - pt, 0)
print(count)



# Optimized solution
import bisect
n = int(eval(input()))
l = list(map(int, input().split()))
count = 0
l.sort()
for i in range(len(l)-1, 1, -1):
  for j in range(i-1, 0, -1):
    count += max(j - (bisect.bisect_right(l, l[i] - l[j])), 0)
print(count)
# Original solution
n= int(eval(input()))
l=list(map(int,input().split()))
cnt=0
ls = sorted(l)
for i in range(n-1):
    for j in range(i+1,n-1):
        for h in range(j+1,n):
            a,b,c=ls[i],ls[j],ls[h]
            if(a+b<c):
                break
            if(a<b+c)and(b<a+c)and(c<a+b):
                cnt+=1
print(cnt)

# Optimized solution
from bisect import bisect_left

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):
    count+=bisect_left(l,l[j]+l[i])-j-1
print(count)
# Original solution
from bisect import bisect_left
N = int(eval(input()))
L = list(map(int,input().split()))
L_1 = sorted(L)

ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
      A = bisect_left(L_1,L_1[i]+L_1[j])
      for k in range(j+1,A):
          if L_1[i]+L_1[j] > L_1[k]:
              ans += 1
      
print(ans)

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

ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
      ans +=bisect_left(L_1,L_1[i]+L_1[j])-j-1
print(ans)
# Original solution
import itertools
d = int(eval(input()))
d = list(map(int,input().split()))
n = 3
ans = 0
for i in itertools.combinations(d,n):
    if i[0] < i[1]+i[2] and i[1] < i[0]+i[2] and i[2] < i[1]+i[0]:
        ans += 1
print(ans)

# Optimized solution
import bisect
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):
        k = bisect.bisect_left(l,l[i]+l[j])
        if k > j:
            ans += k - j -1 
print(ans)
# Original solution
from itertools import combinations

n = int(eval(input()))
l = list(map(int, input().split()))
cnt = 0
for i in combinations(list(range(n)), 3):
    a,b,c = i
    if (l[a] < l[b] + l[c]) and (l[b] < l[c] + l[a]) and (l[c] < l[b] + l[a]):
        cnt += 1
print(cnt)

# Optimized solution
from bisect import bisect_left

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

#aを1番短い辺、bを2番めに短い辺とする
cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        c_i = bisect_left(l, l[i] + l[j])
        cnt += c_i - (j+1)

print(cnt)
# Original solution
from bisect import bisect_left
n, *l = list(map(int, open(0).read().split()))
l.sort()

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


# Optimized solution
from bisect import bisect_left
n, *l = list(map(int, open(0).read().split()))
l.sort()

print((sum(bisect_left(l, l[i] + l[j]) - 1 - j for i in range(n)
          for j in range(i + 1, n))))
# Original solution
import itertools
n = int(eval(input()))
l = list(map(int, input().split()))
ll = list(itertools.combinations(l, 3))
ans = 0
for a, b, c in ll:
  if a < b+c and b < c+a and c<a+b:
    ans += 1
print(ans)

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

for i in range(n):
  for j in range(i+1, n):
    s = l[i]+l[j]
    tmpl = l[j+1:n]
    ans += bisect_left(l[j+1:n], s)

print(ans)
# Original solution
import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L = sorted(L)
ans = 0

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


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

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

print(ans)
# Original solution
import bisect

def main():
    N = int(eval(input()))
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for ai in range(N-2):
        a = L[ai]
        for bi in range(ai+1,N-1):
            b = L[bi]
            cleft = max((a - b), (b - a))
            cright = a + b
            left_index = bisect.bisect_left(L[bi+1:],cleft)
            right_index = bisect.bisect_left(L[bi+1:],cright)
            if left_index == right_index:
                if L[bi+1+left_index] < cright:
                    ans += 1
            else:
                ans += (right_index - left_index)
    print(ans)
    
if __name__ == "__main__":
    main()


# Optimized solution
import bisect

def main():
    N = int(eval(input()))
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for ai in range(N-2):
        a = L[ai]
        for bi in range(ai+1,N-1):
            b = L[bi]
            cmax = a + b
            m_index = bisect.bisect_left(L,cmax)
            ans += max(m_index - bi - 1, 0)

    print(ans)
    
if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
k2 = 2
ans = 0
for i in range(N-2):
    for j in range(1,N-1-i):
        s = L[i] + L[N-j-1]
        if L[N-j] >= s:
            ans += j
        else:
            for k in range(N-j+1,N):
                if L[k] >= s:
                    ans += N-k
                    break
print(((N*(N-1)*(N-2))//6 - ans))

# Optimized solution
import bisect as bs
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):
        s = L[i] + L[j]
        ans += bs.bisect_left(L,s) - j - 1
        # bisect.bisect_left(list, x)
        # はリストにxを挿入できる点を返す
        # すなわち、
        # (val < x for val in list[0:i]) + (val >= x for val in list[i:len(list)])
print(ans)
# Original solution
N = int(eval(input()))
L = [int(i) for i in input().split()]

import random
import time
from bisect import bisect_left

L_len = len(L)
L.sort()

count = 0
for i in range(0, L_len - 2):
    for j in range(i + 1, L_len - 1):
        length = L[i] + L[j]
        idx = bisect_left(L, length, lo = j + 1, hi = L_len)
        count += idx - j - 1

print(count)


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

from bisect import bisect_left

L.sort()

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

print(count)
# Original solution
import itertools
n = int(eval(input()))
l = list(map(int, input().split()))
p = list(itertools.combinations(l,3))
def triangle(a, b, c):
    if a < b + c and b < c + a and c < a + b:
        return True
    else:
        return False
ans = 0
for i in p:
    if triangle(i[0], i[1], i[2]):
        ans += 1
print(ans)

# Optimized solution
def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番右側のidx+1となる。
    '''
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

n = int(eval(input()))
llis = list(map(int, input().split()))
lis = sorted(llis, reverse=True)
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += max(bisect_left_reverse(lis, lis[i]-lis[j]) - j - 1, 0)
print(ans)
# Original solution
from bisect import bisect_left
import copy
from itertools import combinations


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

li = list(combinations(l, 2))


ans = 0
for i in li:
    x = copy.deepcopy(l)
    x.remove(i[0])
    x.remove(i[1])
    left = abs(i[0] - i[1])
    small = min(i[0], i[1])
    x = [i for i in x if i < small]

    if len(x) != 0:
        left_div = bisect_left(x, left+1)
        ans += max(0, len(x) - left_div)

print(ans)

# Optimized solution
from bisect import bisect_left
import copy

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


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)
# Original solution
def binary_search(l, item):

    if len(l) == 0 or l[0] <= item:
        return -1

    if item < l[-1]:
        return len(l) - 1

    list2 = [1001] + l + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2

        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:

            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1

    return -1


import heapq


N = int(eval(input()))
L = []
for l in map(int, input().split(' ')):
    heapq.heappush(L, l*(-1))

L = [heapq.heappop(L)*(-1) for _ in range(N)]
# L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L[:-2:]):
    for j, b in enumerate(L[i+1:-1:]):
        k = binary_search(L[i+j+2::], a-b)
        if k == -1:
            break
        result += k + 1


print(result)


# Optimized solution
from bisect import bisect_left

N = int(eval(input()))
L = list([int(l)*(-1) for l in input().split()])
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)
# Original solution
#ABC143-D:二分探索
n=int(eval(input()))
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
ans=0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        b=l[i]
        c=l[j]

        #二分探索
        ok=j
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if l[mid]>b-c:
                #b>=cはわかってる
                ok=mid

            else:
                ng=mid

        ans+=ok-j
print(ans)

# Optimized solution
#ABC143-D
n=int(eval(input()))
l=list(map(int,input().split()))
l=sorted(l,reverse=True)
ans=0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        b=l[i]
        c=l[j]

        #二分探索
        ok=j
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if l[mid]>b-c:
                #b>=cはわかってる
                ok=mid

            else:
                ng=mid

        ans+=ok-j
print(ans)
# Original solution
from collections import Counter
n = int(eval(input()))
l = list(map(int,input().split()))
l = sorted(l)

CNT = Counter(l)
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        temp0 = l[j] - l[i]
        temp1 = l[j] + l[i]
        for k in range(l[j] + 1, temp1):
            #print(k,CNT[k])
            cnt += CNT[k]
            if k == l[j]:cnt += -1
            if k == l[i]:cnt += -1
print(cnt)
#print(CNT)

# Optimized solution
def low(list, j, tag):
    ok = j
    ng = n
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if list[mid] >= tag:ok = mid
        else:ng = mid
    return ok

n = int(eval(input()))
l = list(map(int,input().split()))
l = sorted(l, reverse = True)
#print(l)
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        temp0 = l[i] - l[j]
        temp1 = l[j] + l[i]
        cnt += low(l, j, temp0 + 1) - j
        #print((l[i],l[j]), j, low(l, j, temp0 + 1) - j, cnt)
print(cnt)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))

# import bisect

L.sort()
# print(L)

ans = 0
for l1ix in range(N-1, -1, -1):
    for l2ix in range(l1ix - 1, -1, -1):
        # binsearch
        l = -1
        r = l2ix + 1

        while (r - l) > 1:
            mid = l + (r - l) // 2

            if L[mid] < (L[l1ix] + L[l2ix]) and L[l2ix] < L[mid] + L[l1ix] and L[l1ix] < L[mid] + L[l2ix]:
                #ok
                r = mid
            else:
                #ng
                l = mid
        
        l3ix = r
        # if l2ix != l3ix:
        #     print("1,2,3=", L[l1ix], L[l2ix], L[l3ix])
        
        anst = l2ix - l3ix
        ans += anst if anst > 0 else 0

print(ans)
        


"""
O(N^3)だから間に合わない．明らかに間に合うアルゴリズムを探す
ans = 0
for aix in range(N):
    for bix in range(aix + 1, N):
        for cix in range(bix + 1, N):
            if L[aix] < L[bix] + L[cix] and L[bix] < L[aix] + L[cix] and L[cix] < L[aix] + L[bix]:
                # print("ok:", aix,",", bix,",", cix)
                ans += 1

print(ans)
"""


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

import bisect

L.sort()
# print(L)

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

print(ans)