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

cnt = 0
for a in range(N-2):
  for b in range(a+1,N-1):
    for c in range(b+1,N):
      if L[c] < L[a] + L[b]:
        cnt += 1
print(cnt)

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

def binary_search(a,b):
  top = N
  bottom = b
  c = (top + bottom)//2
  while top - bottom > 1:
    #print(a,b,":",top,bottom,c)
    if L[c] < L[a] + L[b]:
      bottom = c
    else:
      top = c
    c = (top + bottom)//2
  return top - 1

cnt = 0
for a in range(N-2):
  for b in range(a+1,N-1):
    cnt += binary_search(a,b) - b

print(cnt)
# Original solution
from collections import deque

def hoge(A,B):
    sum = 0
    for i in range(B):
        sum += A
        A -= 1
    return sum

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

L.sort(reverse=True)

List = deque()
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(hoge(N-2,i),len(List)):
        if List[j] > L[i]:
            Sum += 1

print(Sum)

# Optimized solution
import bisect

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

Sum = 0
L.sort(reverse=False)

for i in reversed(list(range(2,N))):
    for j in reversed(list(range(1,i))):
        hoge = 0
        hoge = j - bisect.bisect(L, L[i] - L[j])
        if hoge < 0:
            hoge = 0
        Sum += hoge

print(Sum)
# Original solution
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):
        for k in range(j + 1, n):
            if l[k] < l[i] + l[j]:
                count += 1
            else:
                break
print(count)

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

# Optimized solution
import bisect
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):
        a = l[i]+l[j]
        index = bisect.bisect_left(l, a)
        count += index - j -1
print(count)
# Original solution
import itertools
N=int(eval(input()))
L=list(map(int, input().split()))
S=0
C=list(itertools.combinations(L,3))
for i in range(len(C)):
    if C[i][0]+C[i][1]>C[i][2] and C[i][1]+C[i][2]>C[i][0] and C[i][2]+C[i][0]>C[i][1]:
        S+=1
print(S)

# Optimized solution
import itertools
N=int(eval(input()))
L=list(map(int, input().split()))
S=0
C=list(itertools.combinations(L,3))
for i in range(len(C)):
    if max(C[i])*2<sum(C[i]):
        S+=1
print(S)
# Original solution
import itertools
N = int(eval(input()))
L = list(map(int, input().split()))
L = list(itertools.combinations(L, 3))

cnt = 0
for l in L:
    l = list(l)
    m = max(l)
    l.remove(m)
    if m < sum(l):
        cnt += 1
        
print(cnt)

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

cnt = 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 b > c and a < b+c:
                cnt += 1
print(cnt)
# Original solution
import math
from bisect import bisect_right
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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            if st > L[j+1]:
                m2 = 0
            else:
                m2 = bisect_right(L[j+1:],st)
            c += max(0,m1-m2)
print (c)

# Optimized solution
import math
from bisect import bisect_right
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):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            c += max(0,m1)
print (c)
# Original solution

import bisect

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



cnt = 0
for i in range(0, len(L)-2):
    l1 = L[i]
    rest = L[i+1:]
    for i2 in range(0, len(rest)-1):
        l2 = rest[i2]
        if l2 < l1 / 2:
            break
        if l2 < l1 / 2:
            break
        rest2 = rest[i2+1:]
        cnt += bisect.bisect_left(rest2, l2+l1) - bisect.bisect_left(rest2, l2-l1)

print(cnt)

# Optimized solution
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    for j in range(i):
        m = L[i]-L[j]
        k = bisect_right(L, m)
        n = max(0, j-k)
        ans+=n
print(ans)
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
d={}
for li in l:
  if li in d:
    d[li]+=1
  else:
    d[li]=1
l=list(set(l))
l.sort()
ans=0
for i in range(len(l)):
  for j in range(i+1):
    ls=[li for li in l[:j+1] if li>l[i]-l[j]]
    for lsi in ls:
      if l[i]==l[j] and l[j]==lsi:
        ans+=d[l[i]]*(d[l[i]]-1)*(d[l[i]]-2)//6
        #print(str(ans)+' '+str(l[i])+' '+str(l[j])+' '+str(lsi))
      elif l[i]==l[j]:
        ans+=d[l[i]]*(d[l[i]]-1)*d[lsi]//2
      elif l[j]==lsi:
        ans+=d[l[i]]*d[l[j]]*(d[l[j]]-1)//2
      else:
        ans+=d[l[i]]*d[l[j]]*d[lsi]
print(ans)


# Optimized solution
n=int(eval(input()))
l=sorted(list(map(int,input().split())))
import bisect
ans=0
for i in range(n):
  for j in range(i):
    index=bisect.bisect_right(l,l[i]-l[j])#このindexよりも右側のものでかつjより左のものが当てはまるもの
    ans += max(j - index,0)
print(ans)
# 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[i]+L[j]:
                break
            else:
                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):
        cnt += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

print(cnt)
# Original solution
import 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):
        lower_bound = bisect.bisect_left(L, L[i]+L[j])
        for k in range(lower_bound):
            if k == i or k == j:
                continue
            if L[i]+L[j] > L[k] and L[i]+L[k] > L[j] and L[j]+L[k] > L[i]:
                ans += 1
        # print(L[i], L[j])
        # print(bisect.bisect_left(L, L[i]+L[j])-2)
        # ans += max(bisect.bisect_left(L, L[i]+L[j])-2, 0)
print((ans//3))


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

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

print(ans)
# Original solution
import bisect

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

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

print(ans)

# Optimized solution
from bisect import bisect_left

N = int(eval(input()))
L = [int(x) for x in 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
from itertools import combinations

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

count = 0
# for a, b, c in combinations(ls, 3):
#     if a < b + c and b < c + a and c < a + b:
#         count += 1
for j in range(n - 1, 1, -1):
    last = ls[j]
    for a, b in combinations(ls[:j], 2):
        if a + b > last:
            count += 1

print(count)

# Optimized solution
# from itertools import combinations
from bisect import bisect_left

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

count = 0

# for a, b, c in combinations(ls, 3):
#     if a < b + c and b < c + a and c < a + b:
#         count += 1

# for j in range(n - 1, 1, -1):
#     last = ls[j]
#     for a, b in combinations(ls[:j], 2):
#         if a + b > last:
#             count += 1

for i in range(n - 1, 1, -1):
    for j in range(i - 1, 0, -1):
        idx = bisect_left(ls[:j], ls[i] - ls[j] + 1)
        if idx < j:
            count += j - idx

print(count)
# Original solution
N=int(eval(input()))
L=list(map(int,input().split()))
ans=0
c=[0]*1001
for i in L:c[i]+=1
for i in range(1000):c[i+1]=c[i]+c[i+1]
for i in range(N):
    for j in range(N):
        if i!=j:
            l,r=abs(L[i]-L[j]),min(L[i]+L[j]-1,1000)
            s=c[r]-c[l]
            if l<L[i] and L[i]<=r:s-=1
            if l<L[j] and L[j]<=r:s-=1
            ans+=max(s,0)
print((ans//6))

# Optimized solution
N=int(eval(input()))
L=list(map(int,input().split()))
ans=0
c=[0]*1001
for i in L:c[i]+=1
for i in range(1000):c[i+1]=c[i]+c[i+1]
for i in range(N):
    for j in range(i+1,N):
        l,r=abs(L[i]-L[j]),min(L[i]+L[j]-1,1000)
        s=c[r]-c[l]
        if l<L[i] and L[i]<=r:s-=1
        if l<L[j] and L[j]<=r:s-=1
        ans+=max(s,0)
print((ans//3))
# Original solution
N=int(eval(input()))
L=list(map(int,input().split()))
ans=0
c=[0]*1001
for i in L:c[i]+=1
for i in range(1000):c[i+1]=c[i]+c[i+1]
for i in range(N-1):
    for j in range(i+1,N):
        l,r=abs(L[i]-L[j]),min(L[i]+L[j]-1,1000)
        s=c[r]-c[l]
        if l<L[i] and L[i]<=r:s-=1
        if l<L[j] and L[j]<=r:s-=1
        ans+=max(s,0)
print((ans//3))

# Optimized solution
N=int(eval(input()))
L=list(map(int,input().split()))
ans=0
c=[0]*1001
for i in L:c[i]+=1
for i in range(1000):c[i+1]=c[i]+c[i+1]
for i in range(N-1):
    for j in range(i+1,N):
        l,r=abs(L[i]-L[j]),min(L[i]+L[j]-1,1000)
        ans+=c[r]-c[l]
        if l<L[i] and L[i]<=r:ans-=1
        if l<L[j] and L[j]<=r:ans-=1
print((ans//3))
# Original solution
from itertools import combinations

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

combi = list(combinations(l, 3))

for i in range(len(combi)):
  max_num = max(combi[i])
  if max_num < (sum(combi[i]) - max_num):
    ans += 1
    
print(ans)

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

for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      max_num = max(l[i], l[j], l[k])
      if max_num < ((l[i]+l[j]+l[k]) - max_num):
        ans += 1
      else:
        break
print(ans)
# Original solution
import bisect
import copy

ans = 0
n = int(eval(input()))
l = [int(x) for x in input().split()]
l.sort()
for i in range(n-2):
  ln = copy.copy(l)
  del ln[:i+1]
  for j in range(i+1, n-1):
    a = l[i]
    b = l[j]
    del ln[0]
    k = bisect.bisect_right(ln, b - a)
    m = bisect.bisect_left(ln, a + b)
    ans += (m - k)
print(ans)

# Optimized solution
import bisect
import copy

ans = 0
n = int(eval(input()))
l = [int(x) for x in input().split()]
l.sort()
for i in range(n-2):
  for j in range(i+1, n-1):
    a = l[i]
    b = l[j]
    m = bisect.bisect_left(l, a + b)
    ans += (m - 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):
    for j in range(i + 1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]
        ans += bisect.bisect_left(L[j+1:], r) - bisect.bisect_right(L[j+1:], l)
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):
    for j in range(i + 1, N):
        r = L[j] + L[i]
        ans += bisect.bisect_left(L[j+1:], r)
print(ans)
# Original solution
import heapq

N = int(eval(input()))
L_list = list(map(int,input().split()))
L_list.sort()
ans = 0
list = []
M = 0

for i in range(N-1):
    for j in range(N-i-1):
        list.append((L_list[i]+L_list[j+i+1],i,j+i+1))
        M += 1

for k in range(N):
    for z in range(M):
        if L_list[k] < list[z][0]:
            if (k > list[z][2]):
                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):
    for j in range(i + 1, N - 1):
        insert_index = bisect.bisect_left(l, l[i] + l[j],j) #l[i] + l[j]を挿入できる点を探す。同じ者がlにすでにある時は、一番左になるようにする
        ans += (insert_index - j - 1)

print(ans)
# Original solution
import itertools
n=int(eval(input()))
l=list(map(int,input().split()))


def triangle(num):
    a,b,c=num
    if a<(b+c) and b<(a+c) and c<(a+b):
        return True
    else:
        return False
ans=0
for num in itertools.combinations(l,3):
    ans+=triangle(num)
print(ans)


# Optimized solution
from bisect import bisect_left
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+=max(0,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(reverse = 1)
ans = 0
flg = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        indL = j
        indR = len(l)-1
        while 1:
            if indL == indR:
                flg = 1
                break
            if l[i] < l[indL] + l[indR]:
                ans += (indR - indL)
                break
            else:
                indR -= 1
        if flg == 1:
            flg = 0
            break
                
print(ans)

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

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    indL = i+1
    indR = len(l)-1
    while 1:
        if indL == indR:
            break
        if l[i] < l[indL] + l[indR]:
            ans += (indR - indL)
            indL += 1
        else:
            indR -= 1
                
print(ans)
# Original solution
n = int(eval(input()))
L = list(map(int, input().split()))
cnt = n * (n - 1) * (n - 2) / 6
jud = []

for i in range(n):
    for j in range(n):
        if i > j:
            jud.append(L[i] + L[j])

for p in range(len(jud)):
    for m in range(n):
        if L[m] >= jud[p]:
            cnt -= 1

if cnt < 0:
    print((0))
else:
    print((int(cnt)))

# Optimized solution
from _bisect import bisect_left
from _bisect import bisect_right

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

cnt = 0

for a in range(n):
    for b in range(n):
        if a < b:
            c = bisect_left(L, L[a] + L[b], b)
            cnt += c - b - 1
print(cnt)
# Original solution
from itertools import combinations
n=int(eval(input()))
l=[int(i)for i in input().split()]
l2=list(combinations(l, 3))
sum=0
for i in range(len(l2)):
    a=l2[i][0]
    b=l2[i][1]
    c=l2[i][2]
    if(a<b+c and b<c+a and c<a+b):
        sum+=1
print(sum)

# Optimized solution
n=int(eval(input()))
l=sorted([int(i)for i in input().split()])
sum=0
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]:
                sum+=1
            else:
                break
print(sum)
# Original solution
from bisect import*
n,*l=list(map(int,open(0).read().split()))
l.sort()
A=0
for i in range(n):
    a=l[i]
    for j in range(i+1,n):
        b=l[j]
        k1=max(j+1,bisect(l,b-a))
        k2=bisect_left(l,a+b)
        A+=max(0,k2-k1)
print(A)

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

# Optimized solution
from bisect import*
_,l=open(0)
l=sorted(map(int,l.split()))
e=enumerate
print((sum(j-bisect(l,a-b,0,j)for i,a in e(l)for j,b in e(l[:i]))))
# Original solution
from bisect import*
_,l=open(0)
l=sorted(map(int,l.split()))
e=enumerate
print((sum(j-bisect(l,a-b,0,j)for i,a in e(l)for j,b in e(l[:i]))))

# Optimized solution
from bisect import*
_,l=open(0)
l=sorted(map(int,l.split()))
*e,=enumerate(l)
print((sum(j-bisect(l,a-b,0,j)for i,a in e for j,b in e[:i])))
# Original solution
n = int(eval(input()))
ls = list(map(int, input().split()))

from itertools import combinations


p = list(combinations(ls, 3))

result = 0
for a, b, c in p:
    if a < (b+c) and b < (c+a) and c < (a+b):
        result += 1

print(result)

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

from itertools import combinations


p = combinations(ls, 3)

result = 0
for a, b, c in p:
    if a < (b+c) and b < (c+a) and c < (a+b):
        result += 1

print(result)
# Original solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from bisect import bisect_left,bisect_right


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

ret = 0
for a in range(N-1,1,-1):
  for b in range(a-1,0,-1):
    if Ln[a] >= Ln[b] + Ln[b-1]:
      continue
    else:
      c = b-1
      while Ln[a]<Ln[b]+Ln[c] and c>=0:
        ret += 1
        c -= 1
print(ret)

# Optimized solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-


## Input
N = int(eval(input()))
Ln = list(map(int, input().split()))
Ln = sorted(Ln)

## Solve
ret = 0
for a in range(2,N):
  c = 0
  for b in range(a-1,0,-1):
    if c >= b:
      continue
    else:
      while (c<b and Ln[a]>=Ln[b]+Ln[c]):
        c += 1
      ret += max(b-c,0)
print(ret)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import bisect

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

    print(ans)

if __name__ == '__main__':
    main()



# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import bisect

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

    print(ans)

if __name__ == '__main__':
    main()
# Original solution
import bisect
n = int(eval(input()))
l_li = [int(x) for x in input().split()]
l_li.sort()

count = 0
  
for i in range(n):
  for j in range(i+1,n):
    wa = l_li[i] + l_li[j]
    target = l_li[j+1:]
    count += bisect.bisect_left(target, wa)
    
print(count)

# Optimized solution
import bisect
n = int(eval(input()))
l_li = [int(x) for x in input().split()]
l_li.sort()

count = 0
  
for i in range(n):
  for j in range(i+1,n):
    wa = l_li[i] + l_li[j]
    count += bisect.bisect_left(l_li, wa) - j - 1
    
print(count)
# Original solution
import sys
import bisect

n = int(eval(input()))
*l, = list(map(int, input().split()))
l = sorted(l)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        c = bisect.bisect_left(l[j+1:], l[i]+l[j])
        count += c
print(count)

# Optimized solution
import sys
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):
        c = bisect.bisect_left(l, l[i] + l[j], j+1)
        ans += c - j - 1

print(ans)
# Original solution
import bisect
n = int(eval(input()))
*l, = sorted(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        bc = l[i]+l[j]
        index = bisect.bisect_left(l, bc)
        ans += len(l[j+1:index])

print(ans)


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

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

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

# Optimized solution
import bisect

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

'''
リストをソートし、a, b <= cとなるようにa, bを取り出せば、
a < b + c, b < c + a という条件は満たすので、
a, bを取り出したとき、c < a + b を満たすcを二分探索で探す
'''

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
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]
        c = bisect.bisect_left(L,a+b)
        ans += c-j-1
print(ans)


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

L.sort()
diff_L=[]

for i in range(1,N-1):
    diff=[]
    for j in range(i+1,N):
        diff.append(L[j]-L[i])
    diff_L.append(diff)
    
total=0
for i in range(N-2):
    for j in range(i,N-2):
        for elem in diff_L[j]:
            if elem < L[i]:
                total += 1
            else:
                break
print(total)

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

L.sort()
larger=[N]
prev=1
for i in range(N):
    larger= larger +[N-i]*(L[i]-prev)
    prev=L[i]

total=0    
for i in range(N-2):
    low=L[:i+1]
    high=L[i+1:]
    for j in range(len(high)-1):
        diff = high[j+1]-high[0]
        if diff >= len(larger):
            count = 0
        else:
            count = max(larger[diff] - (N-i-1),0)
        total += count
        
print(total)
# Original 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)


# 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
N = int(eval(input()))
L = list(map(int, input().split())) 

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 = 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)