CodeEff/ECCO huggingface dataset:
# Original solution
import bisect

N = int(eval(input()))
Ls = list(map(int, input().split()))
Ls.sort()
# index: 0,...,N-1

ans = 0
print((sum(bisect.bisect_left(Ls[j+1:], J + I) for i,I in enumerate(Ls[:-2]) for j,J in enumerate(Ls[i+1:-1], start=i+1))))
    # i: 0,...,N-3
    # j: i+1,...,N-2
    # k: j+1,...,N-1


# Optimized solution
import bisect

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort() # index: 0,...,N-1

ans = 0
for i in range(N-2): # i: 0,...,N-3
    for j in range(i+1, N-1): # j: i+1,...,N-2
        # k の満たすべき条件:
        # 1. L[k] > L[j] - L[i]
        #     L[k] > L[j] なので自動的に満たす
        # 2. L[k] < L[i] + L[j]
        x = bisect.bisect_left(L, L[i]+L[j])
        # (<L[i]+L[j]), (<L[i]+L[j]), ..., (<L[i]+L[j]) | (L[i]+L[j]<=), (L[i]+L[j]<=), ...
        # | (x) より左側はOK
        # j+1 より右側はOK
        # L[j]<L[i]+L[j] と L[i]+L[j]<=L[x] より L[j]<L[x] つまり j<x
        ans += x - (j + 1)

print(ans)
# Original solution
def tri(l):
    if l[0]<l[1]+l[2] and l[1]<l[2]+l[0] and l[2]<l[0]+l[1]:
        return True
    else: return False

import itertools
n=int(eval(input()))
l=list(map(int,input().split()))
li=list(itertools.combinations(l,3))
print((sum([tri(i) for i in li])))

# Optimized solution
import itertools
n=int(eval(input()))
l=sorted(list(map(int,input().split())),reverse=True)
ans,tmp=0,0
ls=[sum(i) for i in list(itertools.combinations(l,2))]
for i in range(n-2):
    tmp+=n-1-i
    ans+=sum([j>l[i] for j in ls])-tmp
print(ans)
# Original solution
import sys
from bisect import bisect_left

input = sys.stdin.readline


def main():
    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):
            k = bisect_left(L, a + L[j])
            ans += (k - 1 - j)

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
import bisect

input = sys.stdin.readline


def main():
    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]) - 1
            ans += c - b

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import sys
import bisect

input = sys.stdin.readline


def main():
    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]) - 1
            ans += c - b

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
from bisect import bisect_left

input = sys.stdin.readline


def main():
    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):
            k = bisect_left(L, a + L[j])
            ans += (k - 1 - j)

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
from bisect import bisect
from bisect import bisect_left
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):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - max(j+1, bisect(l,left)))
print(ans)

# Optimized solution
from bisect import bisect_left
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i+1, n):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - (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):
  for j in range(i+1, n):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - (j+1))
print(ans)

# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
lt = [n] * (l[n-1] + l[n-2] + 1)
ans = 0
for i in range(l[0]+1):
    lt[i] = 0
length = l[0]
for i in range(1, n):
  if length < l[i]:
    for j in range(length+1, l[i]+1):
      lt[j] = i
    length = l[i]
for i in range(n):
  for j in range(i+1, n):
    right = l[i]+l[j]
    ans += max(0,  lt[right] - (j+1))
print(ans)
# Original solution
import itertools

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

def is_triangle(l):
    a, b, c = l
    if a >= b + c or b >= c + a or c >= a + b :
        return 0
    else:
        return 1

ans = 0

for m in list(itertools.combinations(l,3)):
    ans += is_triangle(m)

print(ans)

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

def is_triangle(a,b,c):
    if a < b + c and b < a + c:
        return True
    else:
        return False

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):
            if is_triangle(l[i], l[j], l[k]):
                ans += 1
            else:
                break

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

def is_triangle(a,b,c):
    if a < b + c and b < a + c:
        return True
    else:
        return False

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):
            if is_triangle(l[i], l[j], l[k]):
                ans += 1
            else:
                break

print(ans)

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

l.sort(reverse=True)

ans = 0

#1番長い辺(a)は固定する
for i in range(n - 2):
    #2番目に長い辺(b)＝次に長い辺とする
    j = i + 1
    #3番目の長さの辺(c)＝リストの中で最短の辺からスタート
    k = n - 1

    while j < k:
        #b<a+c,c<a+b は自明。a<b+cを判定する。
        #満たす場合、このbにおいて、cまでの全ての要素は条件を満たす(cが小さいほうから攻めているから)
        if l[i] < l[j] + l[k]:
            ans += k - j
            j += 1
        #満たさない場合、cを次に長い辺として再度判定。
        else:
            k -= 1

print(ans)
# Original solution
import sys
readline = sys.stdin.readline

N = int(readline())
L = list(map(int,readline().split()))
L = sorted(L)

# 2本固定すると、もう一本として選べるのは、2本の和より長いものだけ
# これを二分探索で数える

#print(L)
import bisect
ans = 0
for i in range(N - 1):
  for j in range(i + 1,N):
    limit = L[i] + L[j]
    ng = len(L)
    ok = j
    while abs(ok - ng) > 1:
      mid = abs(ok + ng) // 2
      if L[mid] < limit:
        ok = mid
      else:
        ng = mid
#    print("i",i,"j",j,"L[i]",L[i],"L[j]",L[j],"limit",limit,ok - j)
    ans += ok - j
        
print(ans)

# Optimized solution
import sys
readline = sys.stdin.readline

N = int(readline())
L = list(map(int,readline().split()))
L = sorted(L)

# 2本固定すると、もう一本として選べるのは、2本の和より長いものだけ
# これを二分探索で数える

#print(L)
import bisect
ans = 0
for i in range(N - 1):
  for j in range(i + 1,N):
    limit = L[i] + L[j]
    ok = bisect.bisect_left(L, limit)
#    print("i",i,"j",j,"L[i]",L[i],"L[j]",L[j],"limit",limit,"ok",ok,"ok - j",ok - 1 - j)
    ans += ok - 1 - j
        
print(ans)
# Original solution
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(eval(input())) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
pairs = []
for i in range(n):
    for j in range(i + 1, n):
        pairs.append((i, j))

ans = 0
for i, j in pairs:
    p = L[:i] + L[i + 1:j] + L[j + 1:]
    a, b = L[i], L[j]
    l = bisect_left(p, b - a + 1)
    r = bisect_left(p, a)
    if l < r:
        ans += (r - l)
print(ans)

# Optimized solution
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(eval(input())) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
pairs = []
for i in range(n):
    for j in range(i + 1, n):
        pairs.append((i, j))

ans = 0
for i, j in pairs:
    a, b = L[i], L[j]
    ans += bisect_left(L, a + b) - 1 - j
print(ans)
# Original solution
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(eval(input())) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
pairs = []
for i in range(n):
    for j in range(i + 1, n):
        pairs.append((i, j))

ans = 0
for i, j in pairs:
    a, b = L[i], L[j]
    ans += bisect_left(L, a + b) - 1 - j
print(ans)

# Optimized solution
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(eval(input())) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a, b = L[i], L[j]
        ans += bisect_left(L, a + b) - 1 - j
print(ans)
# Original solution
n = int(eval(input()))
xs = list(map(int, input().split()))
xs = sorted(list(xs))
ts = []
for i in range(n):
    for j in range(i+1, n):
        ts.append(xs[i] + xs[j])
ts.sort()
i = 0
j = 0
r = 0
xs.append(10**18)
while True:
    if j == len(xs) or i == len(ts):
        break
    if ts[i] <= xs[j]:
        i += 1
        r += n-j
    else:
        j += 1
print((n*(n-1)*(n-2)//6-r))


# Optimized solution
n = int(eval(input()))
X = list(map(int, input().split()))
X.sort()
k=r=0
for i in range(n):
    k = i
    for j in range(i+1, n):
        while k<n and X[i]+X[j]>X[k]:
            k +=1
        r += k-j-1
print(r)
# Original solution
n,*l=list(map(int,open(0).read().split()))
l.sort()
a=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[k]>=l[i]+l[j]:
                break
            if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
                a+=1
print(a)

# Optimized solution
import bisect
n,*l=list(map(int,open(0).read().split()))
l.sort()
a=0
for i in range(n):
    for j in range(i+1,n):
        k=l[i]+l[j]
        a+=max(0,bisect.bisect_left(l,k)-j-1)
print(a)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()

from bisect import bisect_left

cnt = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        t = L[i] + L[j]
        idx = bisect_left(L, t, lo=j + 1, hi=len(L))
        cnt += max(0, idx - j - 1)
print(cnt)


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

from bisect import bisect_left

cnt = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        t = L[i] + L[j]
        idx = bisect_left(L, t, j + 1, len(L))
        cnt += max(0, idx - j - 1)
print(cnt)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()

from bisect import bisect_left

cnt = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        t = L[i] + L[j]
        idx = bisect_left(L, t, j + 1, len(L))
        cnt += max(0, idx - j - 1)
print(cnt)


# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
 
from bisect import bisect_left 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j+1)
    cnt += max(0,idx-j-1)
print(cnt)
# Original solution
import sys
readline = sys.stdin.readline
N = int(readline())
L = list(map(int, readline().split()))

ans = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        for k in range(N):
            if i == k or j == k:
                continue
            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//6))

# Optimized solution
import sys
import bisect
readline = sys.stdin.readline
N = int(readline())
L = list(map(int, readline().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i, N):
        if i == j: continue
        ab = L[i] + L[j]
        to = bisect.bisect_left(L, ab, j, N)
        ans += to - 1 - j
print(ans)
# Original solution
from itertools import combinations

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

l3s = list(combinations(l,3))
for l3 in l3s:
    if abs(l3[1] - l3[2]) < l3[0] < (l3[1] + l3[2]):
        ans += 1
print(ans)

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

lsorted = sorted(l, reverse=True)

for longest in range(len(l)-2):

    for second in range(longest+1, len(l)):


        for k in range(second+1, len(l)):
            if lsorted[longest] - lsorted[second] - lsorted[k] >= 0:                
                break
            else:
                ans += 1

print(ans)
# Original solution
from bisect import bisect_left

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

for i in range(n-2):
    shortest = l[i]
    for j in range(i+1, n-1):
        second = l[j]
        k = bisect_left(l[j+1:], shortest + second)
        ans += k

print(ans)

# Optimized solution
from bisect import bisect_left

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

for i in range(n-2):
    shortest = l[i]
    for j in range(i+1, n-1):
        second = l[j]
        # このスライスしたやつと地味にTLEになる...
        # k = bisect_left(l[j], shortest + second)
        # ans += k

        k = bisect_left(l, shortest + second)
        ans += k - j - 1

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

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    if tmp in list(dic.keys()):
      index2 = dic[tmp]
    else:
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    if l[j] in list(dic.keys()):
      index1 = dic[l[j]]
    else:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1
      
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += max(d,0)
    
print(ans)

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

count = 0
for i in range(n):
  for j in range(i+1,n):
    index = bs.bisect_left(l,l[i]+l[j])
    count += index - j - 1
    
print(count)
# Original solution

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

def j(a,b,c):
  if a<b+c and c<b+a and b<a+c:
    return True
  else:
    return False

cnt = 0
l = list(itertools.combinations(list(range(N)),2))
for i1,i2 in l:
  a,b = L[i1],L[i2]
  if a == b:
    ib = bisect.bisect_right(L, b)
    ic = bisect.bisect_right(L, a+b)
  else:
    ib = bisect.bisect_left(L, b)
    ic = bisect.bisect_left(L, a+b)
  if ic - ib >=1:
    cnt += ic - ib -1
print(cnt)

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

cnt = 0

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

# Optimized solution
n = int(eval(input()))
l = list(map(int,input().split()))
l = sorted(l)
ans = 0
for c in range(n):
    a=0
    b=c-1
    while a<b:
        if l[a]+l[b]>l[c]:
            ans+=b-a
            b-=1
        else:
            a+=1
print(ans)
# Original solution
import itertools
n=int(eval(input()))
l=list(map(int,input().split()))
ans=0
for i in itertools.combinations(l,3):
	a,b,c=list(map(int,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()))
l.sort()
count=0
import bisect
for i in range(N):
    for j in range(i+1,N-1):
        m=bisect.bisect_left(l,l[i]+l[j])
        count+=m-(j+1)
print(count)
# Original solution
n=int(eval(input()))
l=[0]*n
l[:]=list(map(int,input().split()))
ans=0
m=10**3
l=sorted(l)[::-1]
for i in range(n-2):
  m=min(m,l[i])
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if m<l[j]+l[k]:
        ans+=1
      else:
        break
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):
    for j in range(i+1,N):
        k=bisect.bisect_left(L,L[i]+L[j])
        ans+=k-j-1
print(ans)
# Original solution
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))

n = ni()
l = nl()

l = sorted(l)[::-1]

ans = 0


for a in range(n):
    fl = 0
    A = l[a]
    for b in range(a+1,n):
        B = l[b]
        if A > B*2:
            break
        for c in range(b+1,n):

            C = l[c]

            if A >= B + C:
                break

            ans += 1

print(ans)

# Optimized solution
import bisect

ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))

n = ni()
l = nl()

l = sorted(l)

ans = 0

for a in range(n):
    fl = 0
    A = l[a]
    for b in range(a+1,n):
        B = l[b]

        idx = bisect.bisect_left(l, A+B)
        ans += max(0,idx-b-1)

print(ans)
# Original solution
import bisect

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *L = list(map(int, read().split()))

    L.sort()

    ans = 0
    for i, a in enumerate(L):
        for j, b in enumerate(L[i + 1 :], i + 1):
            k = bisect_left(L, a + b, lo=j + 1)
            ans += k - j - 1

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *L = list(map(int, read().split()))

    L.sort()

    max_L = max(L)

    C = [0] * (max_L + 1)
    for l in L:
        C[l] += 1
    C = list(accumulate(C))

    ans = 0
    for i, a in enumerate(L):
        for j, b in enumerate(L[i + 1 :], i + 1):
            if a + b > max_L:
                ans += N - j - 1
            else:
                ans += C[a + b - 1] - j - 1

    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
import sys
from itertools import accumulate

read = sys.stdin.buffer.read


def main():
    N, *L = list(map(int, read().split()))

    L.sort()
    max_L = L[-1]

    C = [0] * (max_L + 1)
    for l in L:
        C[l] += 1
    C = list(accumulate(C))

    ans = 0
    for i, a in enumerate(L):
        for j, b in enumerate(L[i + 1 :], i + 1):
            if a + b > max_L:
                ans += N - j - 1
            else:
                ans += C[a + b - 1] - j - 1

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from itertools import accumulate

read = sys.stdin.buffer.read


def main():
    N, *L = list(map(int, read().split()))

    L.sort()
    max_L = L[-1]

    C = [0] * (max_L + 1)
    for l in L:
        C[l] += 1
    C = list(accumulate(C))

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            if L[i] + L[j] > max_L:
                ans += N - j - 1
            else:
                ans += C[L[i] + L[j] - 1] - j - 1

    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
from itertools import combinations

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

    L = sorted(L)
    ans = 0
    comb = [p for p in combinations(L, 3)]
    for a, b, c in comb:
        if c < a + b:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
from bisect import bisect_left

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

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

    print(ans)

    
if __name__ == "__main__":
    main()
# Original solution
import bisect

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        if L[minInd]> L[i]+L[j]:
            continue
        if MAX<L[i]+L[j]:
            count+=N-1-minInd+1
        else:
            ind = bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
            count+=ind
        # print(count)
print(count)

# Optimized solution
import bisect
 
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)
# Original solution
from bisect import bisect_left,bisect_right
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):
        bc=l[i]+l[j]
        idx=bisect_left(l,bc)
        ans+=idx-j-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
a=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        t=l[i]+l[j]
        cnt=bisect_left(l,t)
        ans+=cnt-j-1
print(ans)
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
ans=0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1,n-1):
    ab=l[i]+l[j]
    idx=bisect_left(l,ab)
    ans+=max(idx-j-1,0)
print(ans)


# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
from bisect import bisect_left
l.sort()
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    t=l[i]+l[j]
    idx=bisect_left(l,t)
    ans+=max(idx-j-1,0)
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_min = b - a
        c_max = a + b
        if c_max > c_min + 1:
            l = L[j+1:]
            i_min = bisect.bisect_right(l, c_min)
            i_max = bisect.bisect_left(l, c_max)
            ans += i_max-i_min
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):
        k = bisect.bisect_left(L, L[i]+L[j])
        ans += k-1 - j
print(ans)
# Original solution
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):
    b=a[i]+a[j]
    k=j+1
    while a[k]<b:
      k+=1
      if k>=n:
        break
    ans+=k-j-1
print(ans)

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