CodeEff/ECCO huggingface dataset:
# Original solution
length = 2010

n = int(eval(input()))
L = list(map(int, input().split()))
ans = 0
L.sort()
sum_1 = [ 0 for _ in range(length)]
for i in range(n):
    sum_1[L[i]]+=1
#棒の長さで累積和
for i in range(length-1):
    sum_1[i+1] +=sum_1[i]
for i in range(n-1):
    for j in range(i+1, n):
        a = abs(L[i]-L[j])
        b = L[i]+L[j]
        ans = ans + sum_1[b-1] - sum_1[a]

        if a<L[i] and L[i]<b:
            ans -=1
        
        if a<L[j] and L[j]<b:
            ans -=1
print((ans//3))

# Optimized solution
length = 2010

n = int(eval(input()))
L = list(map(int, input().split()))
ans = 0
L.sort()
sum_1 = [0]*length
for i in range(n):
    sum_1[L[i]]+=1
#棒の長さで累積和
for i in range(length-1):
    sum_1[i+1] +=sum_1[i]
for i in range(n-1):
    for j in range(i+1, n):
        a = abs(L[i]-L[j])
        b = L[i]+L[j]
        ans = ans + sum_1[b-1] - sum_1[a]

        if a<L[i] and L[i]<b:
            ans -=1
        
        if a<L[j] and L[j]<b:
            ans -=1
print((ans//3))
# Original solution
import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
 
L.sort()
 
ans = 0
 
for k in range(N-2):
    for j in range(k+1, N-1):
        ans += bisect.bisect_left(L[j+1:], L[k]+L[j])
 
 
print(ans)

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

from bisect import bisect_left
for k in range(N-2):
    for j in range(k+1, N-1):
        ans += bisect_left(L[j+1:], L[k]+L[j])
 
 
print(ans)
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))

s = 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] and l[j] < l[k] + l[i] and l[k] < l[i] + l[j]:
                s += 1

print(s)


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

s = 0

l.sort()

for i in range(n-2):
    j = n-2
    k = n-1
    while i < j:
        if l[k] >= l[i] + l[j] and j < k:
            #print(0, i, j, k)
            k -= 1
        else:
            #print(1, i, j, k)
            s += k - j
            j -= 1


print(s)
# Original solution
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


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

    max_l = max(L)

    ans = 0

    for a in range(N):

        for b in range(a+1, N):
            if L[a] >= L[b] + max_l:
                continue

            for c in range(b+1, N):
                if L[a] < L[b] + L[c] and L[b] < L[c] + L[a] and L[c] < L[a] + L[b]:
                    ans += 1
                else:
                    break

    print(ans)


if __name__ == '__main__':
    main()

# Optimized solution
import sys
import bisect
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce, reduce
sys.setrecursionlimit(20000000)

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

        for b in range(a+1, N-1):
            ab = L[a] + L[b]
            i = bisect.bisect_left(L, ab) - 1

            ans += i - b

    print(ans)


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

n = int(eval(input()))
l = sorted([int(li) for li in input().split()])

sum = 0
for i in range(n)[::-1]:
    for j in range(i)[::-1]:
        k = bisect.bisect_right(l[:j],l[i]-l[j])
        sum += j-k

print(sum)


# Optimized solution
import bisect

n = int(eval(input()))
l = sorted([int(li) for li in input().split()])

sum = 0
for i in range(n-1,-1,-1):
    for j in range(i-1,-1,-1):
        k = bisect.bisect_right(l,l[i]-l[j])
        sum += j-k if j>k else 0

print(sum)
# Original solution
N=int(eval(input()))
L=[int(x) for x in input().split()]
L.sort()
count=0

for i,a in enumerate(L):
    for j,b in enumerate(L[i+1:]):
        for k,c in enumerate(L[i+j+2:]):
            if c>=a+b:
                break
            count+=1
print(count)

# Optimized solution
def main():
    N=int(eval(input()))
    L=[int(x) for x in input().split()]
    L.sort()
    count=0

    dic={}

    for i in range(N):
        for j in range(i+1,N):
            if i:
                try:
                    start=dic[j]
                    count+=dic[j]-j-1
                except:
                    count+=N-j-1
                    continue
            else:
                start=j+1
            for k in range(start,N):
                if L[k]>=L[i]+L[j]:
                    dic[j]=k
                    break
                count+=1
                
                
                
    print(count)

main()
# 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]:
                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):
        num = L[i] + L[j]
        third = bisect.bisect_left(L,num)
        if third > j:
            cnt += third - j - 1
print(cnt)
# Original solution
import itertools
import sys
from collections import defaultdict

input = sys.stdin.readline


class AtCoder:
    def main(self):
        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 < c + a and c < a + b:
                ans += 1

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


# Optimized solution
import bisect
import itertools
import sys

input = sys.stdin.readline


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

        ans = 0
        L.sort()

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

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()
# Original solution
n = int(eval(input()))
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target > abs(a-b) and target < a+b

def bin_search(a,b):
  left = 1
  right = n
  while right-left>1:
    mid = left+(right-left)//2
    if isOK(L[mid],a,b):
      left = mid
    else:
      right = mid
  return left
ans = 0
for i in range(n):
  for j in range(i+1,n):
    a,b = L[i],L[j]
    ans += max(0, bin_search(a,b) - j)
      
print(ans)



# Optimized solution
n = int(eval(input()))
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target < a+b

def bin_search(a,b):
  left = 1
  right = n
  while abs(right-left)>1:
    mid = (left+right)//2
    if isOK(L[mid],a,b):
      left = mid
    else:
      right = mid
  return left
ans = 0
for i in range(n-2):
  for j in range(i+1,n):
    a,b = L[i],L[j]
    ans += max(0, bin_search(a,b) - j)
      
print(ans)
# Original solution
import bisect
N= int(eval(input()))
L = list(map(int, input().split()))

L.sort(reverse=True)

#print(L)
for i in range(N):
    L[i] *= -1
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if -L[i] >= -L[j] * 2:
            break
        data = L[i] - L[j]
        #print(data, L[j + 1 : N])
        #print(bisect.bisect_left(L[j + 1 : N], data))
        count += bisect.bisect_left(L[j + 1 : N], data)

print(count)

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

L.sort(reverse=True)

#print(L)
for i in range(N):
    L[i] *= -1
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if -L[i] >= -L[j] * 2:
            break
        data = L[i] - L[j]
        #print(data, L[j + 1 : N])
        #print(bisect.bisect_left(L[j + 1 : N], data))
        count += bisect.bisect_left(L, data) - (j+1)

print(count)
# Original solution
import bisect

n = int(eval(input()))
L = sorted(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]
        l = bisect.bisect(L[j+1:n], a+b-1)
        ans += l
print(ans)


# Optimized solution
import bisect

n = int(eval(input()))
L = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    a = L[i]
    for j in range(i+1, n):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        if k > j:
            ans += k - j - 1
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):
    for j in range(i + 1, N):
        idx = bisect.bisect_left(L, L[i] + L[j], lo=j + 1)
        cnt += max(0, idx - (j + 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):
    for j in range(i + 1, N):
        idx = bisect.bisect_left(L, L[i] + L[j])
        cnt += max(0, idx - (j + 1))


print(cnt)
# Original solution
import bisect

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

cnt = 0

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

print(cnt)

# Optimized solution
import bisect

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

ans = 0

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

print(ans)
# Original solution
import sys
from bisect import bisect_left as bl
from bisect import bisect_right as br
input = sys.stdin.buffer.readline
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
dl = []
for i in range(N - 1):
  for j in range(i + 1, N):
    dl.append((L[i] + L[j], i, j, abs(L[i] - L[j])))
dl.sort()
#print(L)
#print(dl)
res = 0
for d in dl:
  ind = bl(L, d[0])
  ind2 = br(L, d[3])
  res += ind - ind2
  if ind2 <= d[1] <= ind:
    res -= 1
  if ind2 <= d[2] <= ind:
    res -= 1
  #print(res, d, ind, ind2)
print((res // 3))

# Optimized solution
import sys
from bisect import bisect_left as bl
from bisect import bisect_right as br
input = sys.stdin.buffer.readline
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
dl = []
res = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    d0 = L[i] + L[j]
    d1 = i
    d2 = j
    d3 = abs(L[i] - L[j])
    ind = bl(L, d0)
    ind2 = br(L, d3)
    res += ind - ind2
    if ind2 <= d1 <= ind:
      res -= 1
    if ind2 <= d2 <= ind:
      res -= 1
  #print(res, d, ind, ind2)
print((res // 3))
# Original solution
import bisect

def main():    
    n = int(eval(input()))
    L = list(int(x) for x in input().split())
    ans = 0
    c = 0

    L.sort()

    for i in range(n-2):
        for j in range(i+1, n):
            c = L[i]+L[j]
            l = j
            r = bisect.bisect_left(L, c, lo=l) -1
            ans += (r-l)
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
import bisect

def main():    
    n = int(eval(input()))
    L = list(int(x) for x in input().split())
    ans = 0
    c = 0
    L.sort()

    for i in range(n-2):
        for j in range(i+1, n-1):
            c = L[i]+L[j]
            l = j
            r = bisect.bisect_left(L, c, lo=l) -1
            ans += (r-l)
    print(ans)

if __name__ == '__main__':
    main()
# Original 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):
    for j in range(i+1, N):
        max_len = L[i] + L[j]
        count += bisect_left(L, max_len) - j - 1
print(count)


# Optimized solution
from bisect import bisect_left
import sys
input = sys.stdin.readline

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):
        l = L[i] + L[j]
        k = bisect_left(L, l)
        ans += max(0, k - j - 1)
print(ans)
# Original solution
import itertools
n = int(eval(input()))
l = list(map(int, input().split()))
counter = 0
for v in itertools.combinations(l, 3):
     if 2 * max(v) < sum(v):
         counter += 1
print(counter)

# Optimized solution
import bisect
n = int(eval(input()))
l = sorted(list(map(int, input().split())))
counter = 0
for i in range(n):
    for j in range(i + 1, n):
        counter += (bisect.bisect_left(l, l[i] + l[j]) - j - 1)
print(counter)
# Original solution
n = int(eval(input()))
l = sorted(list(map(int,input().split())))
ans = 0
import bisect
for i in range(n):
    for j in range(i+1,n):
        a1 = abs(l[i]-l[j])
        a2 = l[i]+l[j]
        x1 = bisect.bisect_right(l,a1)
        x2 = bisect.bisect_left(l,a2)
        buf = 0
        if x1<=i<=x2:buf+=1
        if x1<=j<=x2:buf+=1
        ans += max(0,x2-x1-buf)
print((ans//3))


# Optimized solution
n = int(eval(input()))
l = sorted(list(map(int,input().split())))
ans = 0
import bisect
for i in range(n):
    for j in range(i+1,n):
        a = l[i]+l[j]
        x = bisect.bisect_left(l,a)
        if x>j:
            ans += max(0,x-j-1)
print(ans)
# Original solution
# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline
 
 
def main():
    n = int(eval(input()))
    l = list(map(int, input().split()))
    l = sorted(l)
 
    result = 0
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            result += bisect.bisect_left(l[j+1:], l[i] + l[j])
 
    print(result)
 
 
if __name__ == '__main__':
    main()

# Optimized solution
# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline
 
 
def main():
    n = int(eval(input()))
    l = list(map(int, input().split()))
    l = sorted(l)
 
    result = 0
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            result += bisect.bisect_left(l, l[i] + l[j]) - (j + 1)
 
    print(result)
 
 
if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
import bisect
for i in range(N-2):
    for j in range(i,N-1):
        if i==j:
            continue
        a = L[i]
        b = L[j]
        k = bisect.bisect_left(L[j+1:],a+b)
        l = bisect.bisect_left(L[j+1:],abs(a-b))
        if k<N-j:
            c = L[k+j]
            d = L[l+j+1]
            
            if 0<d<=c:
                
                ans += k-l
print(ans)


# Optimized solution
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
import bisect
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)
        l = bisect.bisect_left(L,b-a)
        ans += k-max(j+1,l)
print(ans)
# Original solution
from bisect import bisect_left

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

count = 0
length_list.sort()

for a_idx in range(n - 2):
    for b_idx in range(a_idx + 1, n - 1):
        a = length_list[a_idx]
        b = length_list[b_idx]
        if b > a:
            a, b = b, a
        
        left_count = bisect_left(length_list, a+b)
        count += max(0, left_count - b_idx - 1)


print(count)

# Optimized solution
from bisect import bisect_left

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

count = 0
length_list.sort()

for a_idx in range(n - 2):
    for b_idx in range(a_idx + 1, n - 1):
        a = length_list[a_idx]
        b = length_list[b_idx]

        left_count = bisect_left(length_list, a+b)
        count += max(0, left_count - b_idx - 1)


print(count)
# Original solution
### a<=b<=cととることとし、a,bを固定すると
### cは　c<a+b
from bisect import bisect_left
N = int(eval(input()))
lst = list(map(int, input().split()))
sor = sorted(lst)
res = 0
for i in range(N):
    for j in range(i+1, N):##ここでa<=bを満たしている
        ab = sor[i] + sor[j]
        highbound = bisect_left(sor, ab)
        res += highbound - j - 1
print(res)
### ライブラリを使おう！！！

# Optimized solution
### a<=b<=cととることとし、a,bを固定すると
### cは　c<a+b
from bisect import bisect_left
def main():
    N = int(eval(input()))
    lst = list(map(int, input().split()))
    sor = sorted(lst)
    res = 0
    for i in range(N):
        for j in range(i+1, N):##ここでa<=bを満たしている
            ab = sor[i] + sor[j]
            highbound = bisect_left(sor, ab)
            res += highbound - j - 1
    print(res)
main()
### ライブラリを使おう！！！
# Original solution
import bisect

N = int(eval(input()))
L = input().split()
for i in range(0, N):
  L[i] = int(L[i])
L.sort()
ans = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    a = L[j] - L[i]
    b = L[j] + L[i]
    c = bisect.bisect_right(L, a)
    d = bisect.bisect_left(L, b)
    if 2*L[i] > L[j]:
      ans += d-c-2
    else:
      ans += d-c-1
print((ans // 3))

# Optimized solution
import bisect

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

def check(x, a):
    if a < x:
        return True
    else:
        return False

def bin_search(x, ok, ng, l):
    while ng - ok > 1:
        mid = (ng + ok) // 2
        if check(x, l[mid]):
            ok = mid
        else:
            ng = mid
    return ok + 1

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

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

def bin_search(x, ok, ng, l):
    while ng - ok > 1:
        mid = (ng + ok) // 2
        if l[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok + 1

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

from itertools import combinations

cb = list(combinations(L, 3))

def my_def(x):
    if x[0] + x[1] > x[2]:
        if x[1] + x[2] > x[0]:
            if x[0] + x[2] > x[1]:
                return(True)
    return(False)

print((sum(list(map(my_def, cb)))))

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

from itertools import combinations

cb = combinations(L, 3)

def my_def(x):
    #cb.sort
    if x[1] + x[2] > x[0]:
        if x[0] + x[2] > x[1]:
            if x[0] + x[1] > x[2]:
                return(True)
    return(False)

print((sum(list(map(my_def, cb)))))
# Original solution
from bisect import bisect, bisect_left
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):
        a, b = L[i], L[j] 
        k = i + 1
        l = bisect_left(L[i+1:], a-b) + i+1
        r = bisect_left(L, a+b)
        cnt += max(r - l, 0)
            
print(cnt)            

# Optimized solution
from bisect import bisect, bisect_left
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):
        a, b = L[i], L[j] 
        r = bisect_left(L[i+1:], a+b) + i+1
        cnt += max(r - i - 1, 0)
            
print(cnt)
# Original solution
#!/usr/bin/env python3
import sys
# import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = sorted(L)
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        # for b in range(a+1, len(L)-1):
            # ct+= bisect.bisect_left(L[b+1:],a_+L[b])
            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],ct))
        ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
    print(ct)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
# import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = sorted(L)
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        for b in range(a+1, len(L)-1):
            b_in = bisect.bisect_left(L,a_+L[b]) - b -1
            if b_in > 0:
                ct+=b_in

            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],ct))
        # ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
    print(ct)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

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

counter = 0

for i in range(N):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        for k in range(j+1, N):
            c = L[k]
            if c >= a + b:
                break
            elif b < c + a and a < b + c:
                counter += 1

print(counter)

# Optimized solution
import bisect

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

counter = 0

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

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


def count(i, j):
    l1, l2 = L[i], L[j]
    low = l2 - l1
    high = l2 + l1
    arr = L[j + 1:]
    start = bisect_right(arr, low)
    end = bisect_left(arr, high)
    return end - start


if __name__ == '__main__':
    eval(input())
    L = [int(x) for x in input().split()]
    L.sort()
    total = 0
    for i in range(len(L)):
        for j in range(i + 1, len(L)):
            total += count(i, j)
    print(total)

# Optimized solution
from bisect import bisect_left, bisect_right


def count(i, j):
    l1, l2 = L[i], L[j]
    low = l2 - l1
    high = l2 + l1
    start = bisect_right(L, low, j + 1)
    end = bisect_left(L, high, j + 1)
    return end - start


if __name__ == '__main__':
    eval(input())
    L = [int(x) for x in input().split()]
    L.sort()
    total = 0
    for i in range(len(L)):
        for j in range(i + 1, len(L)):
            total += count(i, j)
    print(total)
# Original solution
from bisect import bisect_left,bisect_right
from copy import deepcopy
n = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
LL = deepcopy(L)
LL.sort(reverse=1)
# print(L,LL)
ans = 0
for i_max,abc_max in enumerate(LL[:-2]):
	ans_bef = ans
	# print("i ",i_max,abc_max)
	for j_mid,abc_mid in enumerate(LL[i_max+1:],i_max+1):
		# print("j ",j_mid,abc_mid)
		# for k_min,abc_min in enumerate(L[j_mid+1:]):
		right = bisect_left(L,abc_max+1-abc_mid)
		# print(right,abc_max+1-abc_mid)
		cur = len(LL[j_mid:-(right+1)])
		if not cur:
			break
		ans += cur
		# print("ans->",ans)
print(ans)

# Optimized solution
from bisect import bisect_left

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

#L[i]+L[j] > ?
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        zz = L[i]+L[j]
        idx = bisect_left(L,zz)
        ans += idx-j-1
print(ans)