CodeEff/ECCO huggingface dataset:
# Original solution
import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j] - 0.1
        res += bisect.bisect_right(L, tgt)-(j+1)
print(res)


# Optimized solution
import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j]
        res += bisect.bisect_left(L, tgt)-(j+1)
print(res)
# Original solution
n = int(eval(input()))
l = [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):
            if l[j] + l[k] <= l[i]:
                continue
            elif l[i] + l[j] <= l[k]:
                continue
            elif l[k] + l[i] <= l[j]:
                continue
            
            ans += 1

print(ans)

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

l.sort()

ans = 0
for a in range(n):
    for b in range(a + 1, n):
        c = bisect.bisect_left(l, l[a] + l[b])
        if b < c:
            ans += c - (b + 1)

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

start = time.time()
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        res += c_index - j - 1
print(res)


# Optimized solution
from bisect import bisect_left

N = int(eval(input()))
Lmat = [int(n) for n in input().split()]
Lmat.sort()

sum = 0
for i in range(N):
    for j in range(i+1,N):
        sum+= bisect_left(Lmat, Lmat[i]+Lmat[j]) - j - 1
print(sum)
# Original solution
import sys
input=sys.stdin.readline
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
import bisect
ans=0
for i in range(n):
    for j in range(i+1,n):
        x=bisect.bisect_left(l[j+1:n],l[i]+l[j])
        ans+=x
print(ans)


# Optimized solution
import sys
input=sys.stdin.readline
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
import bisect
ans=0
for i in range(n):
    for j in range(i+1,n):
        x=bisect.bisect_left(l,l[i]+l[j],lo=j+1)
        ans+=x-j-1
print(ans)
# Original solution
a = int(eval(input()))
b = [int(i) for i in input().split()]
print(((int)(sum(1 for x in range(a-2) for y in range(x+1,a-1) for z in range(y+1,a) if (b[x]<b[y]+b[z] and b[y]<b[x]+b[z] and b[z]<b[x]+b[y])))))



# Optimized solution
a = int(eval(input()))
arr = [int(i) for i in input().split()]
arr.sort() 
count = 0
for i in range(0,a-2): 
    k = i + 2
    for j in range(i+1,a):
        while (k < a and arr[i] + arr[j] > arr[k]): 
            k += 1
        if(k>j): 
            count += k - j - 1
  
print(count)
# Original solution
from bisect import bisect_left

N = int(eval(input()))
L = sorted([int(i) for i in input().split()])

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

print(ans)

# Optimized solution
from bisect import bisect_left

N = int(eval(input()))
L = sorted([int(i) for i in input().split()])

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
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=j
    while k<n and l[k]<a+b:
      k+=1
    ans+=k-j-1
print(ans)




# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n-2):
  a=l[i]
  k=i
  for j in range(i+1,n-1):
    b=l[j]
    
    while k<n and l[k]<a+b:
      k+=1
    ans+=k-j-1
print(ans)
# Original solution
def upperbound(nums, value):
    low = 0
    high = len(nums)
    while low < high:
        mid = (low + high) >> 1
        if value > nums[mid]:
            low = mid + 1
        else:
            high = mid
    return low


n = int(eval(input()))
ar = list(map(int, input().split()))
ar.sort()
total = 0
for i in range(n):
    for j in range(i + 1, n):
        sum2edge = ar[i] + ar[j]
        index = upperbound(ar, sum2edge)
        if index > j:
            total += (index - j - 1)
print(total)

# Optimized solution
def findnumberofTriangles(arr): 
  
    # Sort array and initialize count as 0 
    n = len(arr) 
    arr.sort() 
    count = 0
  
    # Fix the first element. We need to run till n-3 as 
    # the other two elements are selected from arr[i+1...n-1] 
    for i in range(0,n-2): 
  
        # Initialize index of the rightmost third element 
        k = i + 2
  
        # Fix the second element 
        for j in range(i+1,n): 
  
            # Find the rightmost element which is smaller 
            # than the sum of two fixed elements 
            # The important thing to note here is, we use 
            # the previous value of k. If value of arr[i] + 
            # arr[j-1] was greater than arr[k], then arr[i] + 
            # arr[j] must be greater than k, because the array 
            # is sorted. 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
            # Total number of possible triangles that can be 
            # formed with the two fixed elements is k - j - 1. 
            # The two fixed elements are arr[i] and arr[j]. All 
            # elements between arr[j+1] to arr[k-1] can form a 
            # triangle with arr[i] and arr[j]. One is subtracted 
            # from k because k is incremented one extra in above 
            # while loop. k will always be greater than j. If j 
            # becomes equal to k, then above loop will increment k, 
            # because arr[k] + arr[i] is always greater than arr[k] 
            if(k>j): 
                count += k - j - 1
  
    return count 

n = int(eval(input()))
ar = list(map(int, input().split()))
print((findnumberofTriangles(ar)))
# Original solution
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def C(n,r):
    if n < 0 or r < 0 or n < r: 
        return 0
    elif n == 0 or r == 0: 
        return 1
    return C(n-1,r-1)+C(n-1,r)

def main():
    n = ni()
    l = sorted(na())

    j = n - 2
    k = n - 1
    cnt = 0
    dame = []
    for i in range(n - 3, -1, -1):
        try:
            if i in dame or j in dame or k in dame:
                continue
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                cnt += C(n - i - len(dame) - 1, 2)
                j -= 1
                k -= 1
            else:
                tmp = j
                while True:
                    a = l[i]
                    b = l[j]
                    c = l[k]
                    if a < b + c and b < a + c and c < a + b:
                        break
                    j += 1
                    k += 1
                    tmp = j
                cnt += C(n - tmp - 1 - len(dame), 2)
                dame.append(i)
        except:
            break
    print(cnt)

main()

# Optimized solution
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

from bisect import bisect_left

def main():
    n = ni()
    l = sorted(na())
    
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            t = l[i] + l[j]
            ind = bisect_left(l, t)
            ans += max(0, ind - j - 1)
    print(ans)

main()
# Original solution

def is_triangle(a, b, c):
    if a >= b + c:
        return False

    if b >= a + c:
        return False

    if c >= a + b:
        return False

    return True


def main():
    N = int(eval(input()))
    L = list([int(x) for x in input().split()])

    L.sort(reverse=True)

    count = 0
    for index, a in enumerate(L):
        if index + 2 == N:
            break

        for b_i in range(index+1, N):
            b = L[b_i]
            c_i = 1

            while not is_triangle(a, b, L[-c_i]):
                if c_i + b_i == N:
                    break
                c_i += 1

            count += (N - b_i - c_i)

    print(count)


if __name__ == '__main__':
    main()


# Optimized solution

def is_triangle(a, b, c):
    if a >= b + c:
        return False

    if b >= a + c:
        return False

    if c >= a + b:
        return False

    return True


def main():
    N = int(eval(input()))
    L = list([int(x) for x in input().split()])

    L.sort(reverse=True)

    count = 0
    for a_i in range(N-2):
        b_i = a_i + 1
        c_i = 1
        while b_i + c_i < N:

            if not is_triangle(L[a_i], L[b_i], L[-c_i]):
                c_i += 1

            else:
                count += (N - b_i - c_i)
                b_i += 1

    print(count)


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

input = sys.stdin.readline


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


n = int(eval(input()))
ls = sorted(read_i())
ls2 = ls[::-1]
res = 0
for i, x in enumerate(ls2):
    for j, y in enumerate(ls2[i + 1:], i + 1):
        res += n - j - 1 - bisect.bisect(ls[:-(j + 1)], x - y)
print(res)

# Optimized solution
import bisect
import sys

input = sys.stdin.readline


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


n = int(eval(input()))
ls = sorted(read_i())
res = 0
for i in range(n - 2):
    x = ls[i]
    for j in range(i + 1, n - 1):
        y = ls[j]
        res += bisect.bisect_left(ls, x + y) - j - 1
print(res)
# Original solution
def is_triangle(a, b, c):
    return a < b + c and b < c + a and c < a + b


def main():
    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):
            if not is_triangle(L[j + 1], L[i], L[j]):
                # cannot construct with L[k] for all k > j
                continue
            if is_triangle(L[N - 1], L[i], L[j]):
                # can construct with L[k] for all k > j
                cnt += N - 1 - j
                continue
            # binary search
            ok = j + 1
            ng = N - 1
            while abs(ok - ng) > 1:
                mid = (ok + ng) // 2
                if is_triangle(L[mid], L[i], L[j]):
                    ok = mid
                else:
                    ng = mid
            cnt += ok - j
    print(cnt)


if __name__ == '__main__':
    main()

# Optimized solution
import bisect


def main():
    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):
            index = bisect.bisect_left(L, L[i] + L[j])
            cnt += max([0, index - j - 1])
    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
l = sorted(l)
res = 0
for i in range(n):
    for j in range(i+1, n, 1):
        a = l[i]
        b = l[j]
        ab = a + b
        f = 0
        for k in range(j+1, n, 1):
            if l[k] < ab:
                res += 1
                f = 1
            else:
                break
        if f == 0:
            continue
print(res)

# Optimized solution
from bisect import bisect_left
n = int(eval(input()))
l = list(map(int, input().split()))
l = sorted(l)
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        res += c_index - j - 1
print(res)
# Original solution
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(eval(input()))
def FLOAT(): return float(eval(input()))
MOD = 10**9+7
from math import factorial
def comb(n,r):
    return factorial(n) // (factorial(r) * factorial(n - r))

n = INT()
l = MAP()

l.sort()
res=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]:
                res+=n-k
                break
        else:
            break


print((comb(n,3)-res))

# Optimized solution
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(eval(input()))
def FLOAT(): return float(eval(input()))
MOD = 10**9+7


n = INT()
l = MAP()

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

print(ans)
# Original solution
#!/usr/bin/env python3
import bisect


N = int(input().split()[0])
l_list = list(map(int, input().split()))
l_list = sorted(l_list)
p_list = []

for a_i, a in enumerate(l_list):
    for b_i, b in enumerate(l_list):
        if a_i == b_i:
            continue

        c_kouho = a + b
        c_i = bisect.bisect_left(l_list, c_kouho)
        p_list += [
            sorted([a, b, c])
            for c_i, c in enumerate(l_list[: c_i + 1])
            if c_i != a_i and c_i != b_i and abs(b - c) < a < b + c
        ]

p_list = ["{}_{}_{}".format(p[0], p[1], p[2]) for p in p_list]
ans = len(set(p_list))

print(ans)


# Optimized solution
#!/usr/bin/env python3
import bisect


N = int(input().split()[0])
l_list = list(map(int, input().split()))
l_list = sorted(l_list)
total = 0

for a_i, a in enumerate(l_list):
    # 一番長い辺を固定
    for b_i, b in enumerate(l_list[:a_i]):
        # 2番目に長い辺を固定
        c_i = bisect.bisect_right(l_list, abs(a - b))
        total += max(b_i - c_i, 0)

ans = total
print(ans)
# Original solution
N = str(eval(input()))
N = int(N)
Lines = input().split(" ")
Lines = list(map(int, Lines))
answer = 0

for lineI in range(N):
    for lineJ in range(lineI+1,N):
        for lineK in range(lineJ+1,N):
             if (Lines[lineI] + Lines[lineJ] > Lines[lineK]) and (Lines[lineK] + Lines[lineJ] > Lines[lineI]) and (Lines[lineK] + Lines[lineI] > Lines[lineJ]):
                answer += 1
print(answer)


# Optimized solution
N = int(eval(input()))
Lines = list(map(int, input().split(" ")))
Lines.sort()
answer = 0
 
import bisect
 
for lineI in range(N):
    for lineJ in range(lineI+1,N):
    	answer += bisect.bisect_left(Lines,Lines[lineI]+Lines[lineJ])-lineJ-1
print(answer)
# Original solution
import bisect
n=int(eval(input())) 
L=list(map(int, input().split())) 
L.sort()

#m = bisect.bisect_left(l, a + b)
#count += (m - j - 1)
    
count = 0        
for i in range(n-1):
  a = L[i]
  for k in range(i+1,n-1):
    b = L[k]
    L_temp = L[k+1:]
    count += (bisect.bisect_left(L_temp, a + b)) 
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):
  a = L[i]
  for k in range(i+1,n-1):
    b = L[k]

    count += bisect.bisect_left(L, a + b) - k -1
print(count)
# Original solution
n = int(eval(input()))
L = list(map(int,input().split()))
ans = 0
import itertools
for l in list(itertools.combinations(L,3)):
    a, b, c = l
    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(reverse=True)
ans = 0
for i in range(n-2):
    tmp = 0
    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 a < b + c and b < a + c and c < a + b:
                ans += 1
print(ans)
# Original solution
import bisect

N = int(eval(input()))
L = sorted([int(n) for n in input().split()])
#print(L)

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

print(count)


# Optimized solution
import bisect

N = int(eval(input()))
L = sorted([int(n) for n in input().split()])
#print(L)

count = 0
for i in range(N-1):
    b = L[:i]
    c = L[i+1:]
    for j in b:
        count += bisect.bisect_left(c, L[i] + j)

print(count)
# Original solution
N = int(eval(input()))
S = list(sorted(map(int,input().split())))

cnt = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      # print("{} {} {} {} {} {}".format(i,j,k,S[i],S[j],S[k]))
      if S[i]+S[j] <= S[k]:
        #print("break")
        cnt += k-j-1
        break 
    else:
      cnt += k-j
         
        
print(cnt)

# Optimized solution
N = int(eval(input()))
S = list(sorted(map(int,input().split())))
cnt = 0
for j in range(1,N-1):
  k=j+1
  for i in range(j):
    while True:
      
      if k == N or S[i]+S[j] <= S[k]:
        k-=1
        break
      k+=1
    #print(i,j,k)
    #print(S[i],S[j], S[j+1:k+1],k-j)
    cnt += k-j
print(cnt)
# Original solution
from bisect import bisect
N = int(eval(input()))
L = sorted([int(_) for _ in input().split()])
ans = 0
for a in range(N - 2):
    for b in range(a + 1, N - 1):
        #print(bisect(L,L[a]+L[b]-1)-b-1)
        ans += bisect(L, L[a] + L[b] - 1) - b - 1
print(ans)

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

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

c = combinations(L, 3)
ans = 0
for v in c:
    a, b, c = v
    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 i in range(N-1, 1, -1):
    for j in range(i-1, 0, -1):
        a, b = L[i], L[j]
        c = a - b + 1
        if c > b: continue
        ans += (j - bisect.bisect_left(L, c))
print(ans)
# Original solution
def bin_search(list,value,low,high):
    middle = int((low + high) / 2)
    if low > high :
        return 'nothing'
    else:
        if list[middle] == value:
            return middle
        elif list[middle] > value:
            return bin_search(list,value,low,middle - 1)
        elif list[middle] < value:
            return bin_search(list,value,middle + 1,high)


n = int(eval(input()))
list = [int(x) for x in input().split()]
list.sort()
count = 0
for i in range(n - 1):
    for j in range(i,n-1):
        a = list[n - i - 1]
        b = list[n - j - 2]
        c = a - b + 1
        while b > c :
         if bin_search(list,c,0,len(list)-1) != 'nothing':
             count += 1
         c += 1
print(count)


# Optimized solution
from bisect import bisect_left

count = 0
n = int(eval(input()))
list = sorted([int(x) for x in input().split()])

for i in range(n):
    for j in range(i + 1, n) :
        sum = list[i] + list[j]
        a = bisect_left(list,sum)
        count += a - j - 1
print(count)
# Original 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):
        x=bisect.bisect_left(l,l[i]+l[j])-j-1
        ans+=max(0,x)
print(ans)

# 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):
        ans+=bisect.bisect_left(l,l[i]+l[j])-j-1
print(ans)
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
import itertools 
def findsubsets(s, n): 
    return list(itertools.combinations(s, n))
s = set(range(0, n))
com = findsubsets(s, 3)
c = 0
fin = []
for i in com:
    tem = list(i)
    tem.sort()
    fin.append(tem)
l.sort()
for i in fin:
    if l[i[0]] + l[i[1]] > l[i[2]]: c += 1
print(c)

# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
c = 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]: c += 1
            else: break
print(c)
# Original solution
import sys
input = sys.stdin.readline
def main():
  n = int(eval(input()))
  l = list(map(int, input().split()))
  l.sort()
  l.append(99999999)
  c = 0
  for i in range(n - 2):
      t = i + 2
      for j in range(i + 1, n - 1):
          for k in range(t, n + 1):
              if l[i] + l[j] <= l[k]:
                  t = k
                  break
          if t > j: c += t - j - 1
          if j + 1 == t: t += 1
  print(c)
if __name__ == "__main__":
  main()


# Optimized solution
def main():
  n = int(eval(input()))
  l = list(map(int, input().split()))
  l.sort()
  l.append(99999999)
  c = 0
  for i in range(n - 2):
      t = i + 2
      for j in range(i + 1, n - 1):
          for k in range(t, n + 1):
              if l[i] + l[j] <= l[k]:
                  t = k
                  break
          if t > j: c += t - j - 1
          if j + 1 == t: t += 1
  print(c)
if __name__ == "__main__":
  main()
# Original solution
import bisect

n = int(eval(input()))
length = list([int(x) for x in input().split()])
length.sort()
ans = 0
for i in range(n-2):  
    a = length[i]
    for j in range(i+1,n-1):
        b = length[j]
        if i >= j:
            continue
        else:
            c_candidates = length[j+1:]
            max_bar = bisect.bisect_left(c_candidates,a+b)
            ans += max_bar
            
print(ans)

# Optimized solution
import bisect

n = int(eval(input()))
#length = list(map(lambda x:int(x), input().split()))
length = list(map(int, input().split()))
length.sort()
ans = 0
for i in range(n-2):  
    a = length[i]
    for j in range(i+1,n-1):
        b = length[j]
        if i >= j:
            continue
        else:
            max_bar = bisect.bisect_left(length,a+b)
            ans += max_bar - j - 1
            
print(ans)
# Original solution
import itertools
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(itertools.combinations(A, 3))
ans = 0
for b in B:
  if b[0] < b[1] + b[2] and b[1] < b[0] + b[2] and b[2] < b[0] + b[1]:
    ans += 1
print(ans)
  


# Optimized solution
N = int(eval(input()))
A = 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):
      if A[i] < A[j] + A[k]:
        if A[j] < A[i] + A[k]:
          if A[k] < A[j] + A[i]:
            ans += 1
print(ans)
# Original solution
import sys


def main():
    n = int(sys.stdin.readline().strip())
    l = [int(s) for s in sys.stdin.readline().strip().split()]
    # n = 4
    # l = [1, 2, 3, 4]

    l.sort()

    # [lo, hi)
    # Returns -1 if no valid item
    def b_search(lo, hi, limit):
        if lo >= hi:
            return -1
        if lo + 1 == hi:
            return lo
        assert lo + 1 < hi
        mid = (lo + hi) // 2
        if l[mid] < limit:
            return b_search(mid, hi, limit)
        else:
            return b_search(lo, mid, limit)

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

    print(ans)


main()


# Optimized solution
import sys


def main():
    n = int(sys.stdin.readline().strip())
    l = [int(s) for s in sys.stdin.readline().strip().split()]
    # n = 4
    # l = [1, 2, 3, 4]

    l.sort()

    # [lo, hi)
    # Returns -1 if no valid item
    def b_search(lo, hi, limit):
        while lo + 1 < hi:
            mid = (lo + hi) // 2
            if l[mid] < limit:
                lo = mid
            else:
                hi = mid
        if lo >= hi:
            return -1
        if lo + 1 == hi:
            return lo

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

    print(ans)


main()
# Original 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):
        k = bisect_left(l[j:], l[i] + l[j]) + j
        ans += k - j - 1
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-2):
    for j in range(i+1,n-1):
        k = bisect_left(l,l[i]+l[j])
        ans += k - j - 1

print(ans)