CodeEff/ECCO huggingface dataset:
# 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,l[i]+l[j])-j-1

print(ans)

# Optimized solution
from bisect import bisect_left

def main():
    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)

if __name__ == '__main__':
    main()
# Original solution

from bisect import bisect_right
N = int(eval(input()))
L = sorted(list(map(int,input().split())))
count = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ma = bisect_right(L[j+1:], L[i] + L[j] -1)
        if ma >= 0:
            count += ma
print(count)


# Optimized solution

import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        count += bisect.bisect(L,L[i]+L[j]-1)-j-1
print(count)
# Original solution
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):
        a = L[i]
        b = L[j]
        for k in range(j+1,N):
            c = L[k]
            if (c < a + b) and (b < a + c) and (a < b + c):
                ans += 1
            else:
                break
print(ans)


# Optimized solution
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):
        a = L[i]
        b = L[j]
        ans += bisect_left(L[j+1:], a+b)
print(ans)
# Original solution
import itertools

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

count = 0
paris = list(itertools.combinations(L[1:], 2))
for i, a in enumerate(L[:-2]):
    count += sum([(a < b + c) * (b < c + a) * (c < a + b) for b, c in paris])
    del paris[:(N-i-2)]
print(count)



# Optimized solution
N = int(eval(input()))
L = sorted([int(x) for x in input().split(' ')], reverse=True)

count = 0
while len(L) > 2:
    a = L.pop(0)
    ic = len(L) - 1
    for ib, b in enumerate(L):
        diff = a - b
        while L[ic] <= diff and ib < ic:
            ic -= 1
        count += ic - ib
        if ib >= ic:
            break

print(count)
# Original solution
import bisect

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

res = 0
for i in reversed(list(range(1, N))):
    for j in reversed(list(range(i))):
        index = bisect.bisect_left(L, L[i] + L[j])
        n = N - index
        res += (N - 1 - i) - n

print(res)


# Optimized solution
import bisect

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

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

print(res)
# Original solution
from bisect import bisect_left
from functools import lru_cache

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


@lru_cache()
def bisect_left_cache(x):
    return bisect_left(lll, x)


for i in range(n - 2):
    li = lll[i]
    for j in range(i + 1, n - 1):
        k = bisect_left_cache(li + lll[j])
        ans += k - j - 1
print(ans)


# Optimized solution
from bisect import bisect_left

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


def get_bisect_left():
    cache = {}

    def _f(x):
        if x in cache:
            return cache[x]
        cache[x] = bisect_left(lll, x)
        return cache[x]

    return _f


bisect_left_cache = get_bisect_left()

for i in range(n - 2):
    li = lll[i]
    for j in range(i + 1, n - 1):
        k = bisect_left_cache(li + lll[j])
        ans += k - j - 1
print(ans)
# Original solution
N=int(eval(input()))
L=list(map(int,input().split()))

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 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()))
L.sort()

dp=[0]*(N+1)
ans=0
for i in range(3,N+1):
  r=i-2
  l=0
  c=0
  while r>l:
    if L[r]+L[l]>L[i-1]:
      c+=r-l
      r-=1
    else:
      l+=1
  dp[i]=dp[i-1]+c

print((dp[-1]))
# Original solution
import itertools

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

triangle = itertools.combinations(l, 3)

cnt = 0

for i in triangle:
  if max(i)*2 < sum(i):
    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):
    sum = l[i] + l[j]
    index = bisect.bisect_left(l, sum)
    cnt += index - j - 1

print(cnt)
# Original solution
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):
        k = j
        while k + 1 < n and l[k + 1] < l[i] + l[j]:
            k += 1
        cnt += k - j
print(cnt)

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

# Optimized solution
n = int(eval(input()))
l = sorted(list(map(int, input().split())))
cnt = 0
for i in range(n):
    k = i + 1
    for j in range(i + 1, n):
        while k + 1 < n and l[k + 1] < l[i] + l[j]:
            k += 1
        cnt += k - j
print(cnt)
# Original solution
from bisect import bisect_left, bisect_right

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

L.sort()
result = 0
for i in range(N - 2):
  a = L[i]
  for j in range(i + 1, N - 1):
    b = L[j]
    result += bisect_left(L, a + b) - j - 1
print(result)


# Optimized solution
from bisect import bisect_left

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

L.sort()
result = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        result += bisect_left(L, L[i] + L[j]) - j - 1
print(result)
# Original solution
from bisect import bisect_left

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

L.sort()
result = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        result += bisect_left(L, L[i] + L[j]) - j - 1
print(result)


# Optimized solution
from bisect import bisect_left

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

L.sort()
result = 0
for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        result += bisect_left(L, a + L[j]) - j - 1
print(result)
# Original solution
import itertools
N = int(eval(input()))
L = list(map(int,input().split()))
tmp = list(itertools.combinations(L,3))
ans = 0
for i in range(len(tmp)):
    if abs(tmp[i][1] - tmp[i][2]) < tmp[i][0]:
        if tmp[i][0] < (tmp[i][1] + tmp[i][2]):
            ans += 1
print(ans)

# Optimized solution
import itertools
import bisect
N = int(eval(input()))
L = sorted(list(map(int,input().split())))
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        ind_cmin = j+1
        ind_cmax = bisect.bisect_left(L,a+b)-1
        ans += ind_cmax - ind_cmin + 1
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
ans = 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] and L[j]<L[k]+L[i] and L[k]<L[i]+L[j]:
                ans += 1
print(ans)


# Optimized solution
def is_ok1(a,b,c):
    return L[b] < L[c] + L[a]
def is_ok2(a,b,c):
    return L[c] < L[a] + L[b]
def meguru_bisect(ng, ok, is_ok, a, b):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(a, b, mid):
            ok = mid
        else:
            ng = mid
    return ok
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N):
    for b in range(a+1, N):
        ans += max(0, meguru_bisect(N, b, is_ok2, a, b)-meguru_bisect(b, N, is_ok1, a, b)+1)
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
import itertools
A = list(itertools.combinations(L,3))
ans = 0
for a in A:
    ok = True
    if a[0] >= a[1]+a[2]:
        ok = False
    if a[1] >= a[0]+a[2]:
        ok = False
    if a[2] >= a[0]+a[1]:
        ok = False
    if ok:
        ans += 1
print(ans)

# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
O = sorted(L, reverse=True)
def X(n,j):
    C = sorted(L)
    L1 = 0
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            nn = len(C[0:N-1-j])-len(C[0:a+1])
            if nn > 0:
                return nn
            else:
                return 0
        if L2 - L1 <= 1:
            if C[L1] > n:
                nn = len(C[0:N-1-j])-len(C[0:L1])
            else:
                nn = len(C[0:N-1-j])-len(C[0:L2])
            if nn > 0:
                return nn
            else:
                return 0
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += X((O[i]-O[j]),j)
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
C = sorted(L)
def X(n,j):
    L1 = j+1
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            while C[a] == C[a-1]:
                a = a-1
            return len(C[j+1:a])
        elif L2 - L1 <= 1:
            while C[L1] == C[L1-1]:
                if j+1 <= L1-1:
                    L1 = L1-1
                else:
                    break
            if C[L1] > n:
                return len(C[j+1:L1])
            elif C[L2] < n:
                return len(C[j+1:L2+1])
            elif C[L1] < n <= C[L2]:
                return len(C[j+1:L2])
            elif C[L1] == n:
                while C[L1] == C[L1-1]:
                    L1 = L1-1
                return len(C[j+1:L1])
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
    if C[L1] < n:
        return 1
    else:
        return 0
ans = 0
# print(C)
for i in range(N-2):
    for j in range(i+1,N-1):
        # print(X((C[i]+C[j]),j))
        ans += X((C[i]+C[j]),j)
print(ans)

# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
C = sorted(L)
def X(n,j):
    L1 = j+1
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            while C[a] == C[a-1]:
                a = a-1
            return len(C[j+1:a])
        elif L2 - L1 <= 1:
            if C[L2] < n:
                return len(C[j+1:L2+1])
            elif C[L1] < n <= C[L2]:
                return len(C[j+1:L2])
            while C[L1] == C[L1-1]:
                if j+1 <= L1-1:
                    L1 = L1-1
                else:
                    break
            if C[L1] > n:
                return len(C[j+1:L1])
            elif C[L1] == n:
                return len(C[j+1:L1])
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
    if C[L1] < n:
        return 1
    else:
        return 0
ans = 0
# print(C)
for i in range(N-2):
    for j in range(i+1,N-1):
        # print(X((C[i]+C[j]),j))
        ans += X((C[i]+C[j]),j)
print(ans)
# Original solution
import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
cnt=0
for i in range(N-1,1,-1):
    for j in range(i-1,0,-1):
        b = bisect.bisect_right(L[:j],L[i]-L[j])
        cnt+=j-b
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):
        b = bisect.bisect_left(L,L[i]+L[j])
        cnt += b-j-1
print(cnt)
# Original solution
N = int(eval(input()))
l = [int(x) for x in input().split()]

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

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


# Optimized solution
n = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
ans = 0
#print(l)
for i in range(n):
    for j in range(i+1,n):
        val = l[i]+l[j]
        ng = n
        ok = j
        while abs(ok - ng) > 1:
            mid = (ok+ng)//2
            if val > l[mid]:
                ok = mid
            else:
                ng = mid


        #print(i,j,ok,ng)

        ans += ok - j


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

ans = 0

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

print(ans)
# Original solution
import itertools

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

ans = 0

for a,b,c in itertools.combinations(L, 3):
  if a<b+c and b<a+c and c<a+b:
    ans += 1
print(ans)

# Optimized solution
import bisect

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

L.sort()

ans = 0

for a in range(N-2):
  for b in range(a+1,N-1):
    c = bisect.bisect_left(L, L[a]+L[b])
    ans += c - (b+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]
        k = bisect.bisect_left(L[j + 1:], a + b)
        ans += k
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 = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        k = bisect.bisect_left(L, a + b)
        ans += k - j - 1
print(ans)
# 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):
        num=l[i]+l[j]
        for k in range(j+1,n):
            if num<=l[k]:
                break
            else:
                ans+=1
print(ans)


# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
num=[0]*(max(l)+2)
for i in range(n):
    num[l[i]]=i
for i in range(1,len(num)):
    if num[i]==0:
        num[i]=num[i-1]
ans=0
num3=l[n-1]
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=max(0,num[min(num3,l[i]+l[j]-1)]-j)
print(ans)
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
ans=0
import bisect
for i in range(n):
    for j in range(n):
        if i<j:
            a=l[i]
            b=l[j]
            x=bisect.bisect_left(l,a+b)
            y=bisect.bisect_right(l,b-a)
            if b-a>=a:
                ans+=max(0,x-y-1)
            else:
                ans+=max(0,x-y-2)
print((ans//3))


# 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):
        a=l[i]
        b=l[j]
        ans+=max(0,bisect_left(l,a+b)-j-1)
print(ans)
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      a,b,c=l[i],l[j],l[k]
      if abs(a-b)<c<a+b:
        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):
  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 combinations

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

c = list(combinations(a,3))
ans=0
for i in range(len(c)):
    #print(c[i][0],c[i][1],c[i][2])
    
    if c[i][0] < c[i][1]+c[i][2] and c[i][1] < c[i][0]+c[i][2] and c[i][2] < c[i][1]+c[i][0]:
        ans+=1
print(ans)        




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

ans=0

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            #print(a[i],a[j],a[k])
            if a[i]<a[j]+a[k] and a[j]<a[k]+a[i] and a[k]<a[i]+a[j]:
                ans+=1

print(ans)
# Original solution
n = int(eval(input()))
li = list(map(int,input().split()))
li2 = sorted(li,reverse=True)
cnt = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if li2[i] > li2[j] + li2[j+1]:
            break
        else:
            for k in range(j+1,n):
                if li2[i] < li2[j]+li2[k]:
                    cnt += 1
                else:
                    break
print(cnt)

# Optimized solution
import bisect

n = int(eval(input()))
li = list(map(int,input().split()))
li2 = sorted(li)
cnt = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        cnt += bisect.bisect_left(li2,li2[i]+li2[j]) - (j+1) 
print(cnt)
# Original solution
import bisect
import copy

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

cout = 0
m,k = 0,0

for i in range(n-2):
	o = list1.pop(0)
	list1_c = copy.deepcopy(list1) #ここでjのためのdeepcopyを更新
	for j in range(n-i-1):
		p = list1_c.pop(0)

		a = abs(o-p) +1
		b = o+p -1 #<= ではなく<条件に揃える

		d = bisect.bisect_right(list1_c,b)
		
		cout += d

print(cout)

# Optimized solution
import bisect
import copy

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

cout = 0
m,k = 0,0

for i in range(n-2):
	o = list1.pop(0)
	for j in range(n-i-1):
		p = list1[j]

		a = abs(o-p) +1
		b = o+p -1 #<= ではなく<条件に揃える

		d = bisect.bisect_right(list1[j+1:],b)
		
		cout += d

print(cout)
# Original solution
import bisect
import copy

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

cout = 0
m,k = 0,0

for i in range(n-2):
	o = list1.pop(0)
	for j in range(n-i-1):
		p = list1[j]

		a = abs(o-p) +1
		b = o+p -1 #<= ではなく<条件に揃える

		d = bisect.bisect_right(list1[j+1:],b)
		
		cout += d

print(cout)


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

cout = 0 #最終的な三角形の個数

for i in range(n-2): #リストから三角形が作れなくなるまでループ
	o = list1[i] #1辺を確定、そのままリストから消去
	for j in range(i+1,n-1): #残りの二辺のループ(iで使っている次の値から)
		p = list1[j] #２辺目を確定

		b = o+p -1 #昇順にソートしてあるので、c<a+b条件のみ計算

		d = bisect.bisect_right(list1[j+1:],b) #３辺目を確定
		
		cout += d

print(cout)
# Original solution
#
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

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

            b_minus_a = ll[j] - ll[i]
            pos_left = bisect.bisect_right(rest, b_minus_a)
            count = pos_right - pos_left

            ans += count
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
#
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

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

            ans += count
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
L = list(map(int,input().split()))
L = sorted(L,reverse=True)
total = 0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if L[j] > L[i]/2:
            for k in range(j+1,n):
                if L[j] + L[k] > L[i]:
                    total += 1
                else:
                    break
        else:
            break
print(total)


# Optimized solution
import bisect

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

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

print(ans)
# Original solution
import bisect

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

cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        length = l[i] + l[j]
        cnt += bisect.bisect_left(l[j+1:], length)
print(cnt)

# Optimized solution
import bisect

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

cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        cnt += max(0, bisect.bisect_left(l, l[i] + l[j]) - j - 1)
print(cnt)
# Original solution
from bisect import bisect_left
from itertools import combinations

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

ans = 0
for e1, e2, e3 in combinations(L, 3):
    if e1 < e2 + e3 and e2 < e1 + e3 and e3 < e1 + e2:
        ans += 1
print(ans)


# Optimized solution
from bisect import bisect_left, bisect_right

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

L.sort()
ans = 0

for a in range(N):
    for b in range(a + 1, N):
        c = bisect_left(L, L[a] + L[b])
        ans += c - b - 1
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))

L.sort()

count = 0
for i in range(0, N - 2):
    for p in range(i + 1, N - 1):
        left = p + 1
        right = N - 1
        tmp = (left + right) // 2
        if left == right:
            if L[i] + L[p] > L[left]:
                count += (left - p)
                break
        while 'true':
            if L[i] + L[p] > L[tmp]:
                left = tmp
                tmp = (left + right) // 2
            else:
                right = tmp
                tmp = (left + right) // 2
            if abs(right - left) <= 1:
                if L[i] + L[p] > L[right]:
                    count += (right - p)
                    break
                elif L[i] + L[p] > L[left]:
                    count += (left - p)
                    break
                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(0, N - 2):
    for p in range(i + 1, N - 1):
        count += bisect.bisect_left(L, L[i] + L[p]) - p - 1
print(count)