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

from collections import defaultdict

d = defaultdict(int)

for i in range(n):
    d[s[i]]+= 1

r = 0
key = sorted(list(d.keys()))
ng = len(key)
for i in range(ng)[::-1]:
    ki = key[i]
    for j in range(i+1)[::-1]:
        kj = key[j]
        if kj <= ki / 2:
            continue
        for k in range(j+1)[::-1]:
            ti = 0
            kk = key[k]
            if kj + kk <= ki:
                break
            if ki != kj and kj != kk and ki != kk:
                ti = d[ki] * d[kj] * d[kk]
            elif ki == kj and kj == kk:
                if d[ki] < 3:
                    continue
                else:
                    ti = d[ki] * (d[ki]-1) * (d[ki]-2) // 6
            elif ki == kj:
                if d[ki] < 2:
                    continue
                else:
                    ti = d[ki] * (d[ki]-1) * d[kk] // 2
            elif kj == kk:
                if d[kk] < 2:
                    continue
                else:
                    ti = d[j] * (d[kj]-1) * d[ki] // 2
            elif ki == kk:
                if d[ki] < 2:
                    continue
                else:
                    ti = d[ki] * (d[ki]-1) * d[kj] // 2
            r+=ti
print(r)




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

import bisect

s = sorted(s)

res = 0
for i in range(n)[::-1]:
    for j in range(i)[::-1]:
        if s[j] <= s[i] / 2:
            break
        k = bisect.bisect_left(s, s[i]-s[j]+1)
        res += max(0, j-k)
print(res)
# 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):
        for k in range(j+1,n):
            if l[k]<l[j]+l[i]:
                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):
    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
import copy
import bisect

def main(N, L):
    L.sort(reverse=True)

    triangles = 0

    for i, P in enumerate(L):
        Q_list = copy.copy(L)
        del Q_list[:i + 1]
        for j, Q in enumerate(Q_list):
            if Q < P / 2:
                break
            minR = P - Q + 1
            R_list = copy.copy(Q_list)
            del R_list[:j + 1]
            R_list.reverse()
            triangles += len(R_list) - bisect.bisect_left(R_list, minR)

    print(triangles)

if __name__ == '__main__':
    N = int(eval(input()))
    L = list(map(int, input().split()))
    main(N, L)


# Optimized solution
import copy
import bisect

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

triangles = 0

for i in range(N - 2):
    P = L[i]
    for j in range(i + 1, N - 1):
        Q = L[j]
        if P + Q <= L[j + 1]:
            continue
        maxR = P + Q - 1
        triangles += bisect.bisect_right(L, maxR) - (j + 1)

print(triangles)
# Original solution
import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
res = 0
for i in range(N-2):
    idx = (N-1) - i
    max_, second_max = L[idx], L[idx-1]
    for tmp_idx in range(1, idx):
        second_max = L[tmp_idx]
        tidx = bisect.bisect_right(L, max_ - second_max)
        if len(L[tidx:tmp_idx]) > 0:
            res += len(L[tidx:tmp_idx])
print(res)



# Optimized solution
from bisect import bisect_left
N = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
res = 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)
        res += idx-j-1
print(res)
# 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):
        for k in range(j+1, n):
            if l[k] >= l[j] + l[i]:
                break
            if l[j] < l[k] + l[i] and l[i] < l[k] + l[j]:
                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+1
    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 permutations
n=int(eval(input()))
li=[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):
            a=li[i]
            b=li[j]
            c=li[k]
            if a<b+c and b<a+c and c<a+b:
                ans+=1
                  
print(ans)
        


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

ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        a=li[i]
        b=li[j]
        c=bisect.bisect_left(li,a+b)
        ans+=c-j-1
                  
print(ans)
# Original solution
import bisect

n = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        short_2hen = l[i] + l[j]
        l_long = l[j+1:n]
        bis = bisect.bisect_right(l_long, short_2hen-1)
        count += bis
print(count)


# Optimized solution
import bisect

n = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        short_2hen = l[i] + l[j]
        bis = bisect.bisect_left(l, short_2hen)
        count += bis - j - 1
print(count)
# Original solution
from bisect import bisect_left, bisect_right

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

L.sort()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = bisect_right(L[j+1:], abs(l1-l2))
            e = bisect_left(L[j+1:], l1+l2)

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)

# Optimized solution
from bisect import bisect_left, bisect_right

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

L.sort()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = max(j+1, bisect_right(L, abs(l1-l2)))
            e = max(j+1, bisect_left(L, l1+l2))

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)
# Original solution
from bisect import bisect_left

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
answer = 0
for i in range(N):
    for j in range(i+1, N):
        answer += bisect_left(L[j+1:], L[i]+L[j])
print(answer)


# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
answer = 0
for i in range(N-1, 1, -1): # iは辺の最大値
    s = 0 # aは1番短い辺
    l = i-1
    while l > s:
        if L[s] + L[l] > L[i]:
            answer += l - s
            l -= 1
        else:
            s += 1
print(answer)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
answer = 0
for i in range(N-1, 1, -1): # iは辺の最大値
    s = 0 # aは1番短い辺
    l = i-1
    while l > s:
        if L[s] + L[l] > L[i]:
            answer += l - s
            l -= 1
        else:
            s += 1
print(answer)


# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
answer = 0
for i in range(N-1, 1, -1): # iは辺の最大値
    s = 0 # sは1番短い辺
    l = i-1
    while l > s:
        if L[s] + L[l] > L[i]:
            answer += l - s
            l -= 1
        else:
            s += 1
print(answer)
# Original solution
import sys
from bisect import bisect_left

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
L = lr()
L.sort()
answer = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        candidate = L[j+1:]
        index = bisect_left(candidate, (L[i]+L[j]))
        answer += index

print(answer)


# Optimized solution
import sys
from bisect import bisect_left

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
L = lr()
L.sort()
answer = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        index = bisect_left(L, (L[i]+L[j]))
        answer += index - j - 1

print(answer)
# Original solution
import sys
from bisect import bisect_left

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
L = lr()
L.sort()
answer = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        index = bisect_left(L, (L[i]+L[j]))
        answer += index - j - 1

print(answer)


# Optimized solution
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
L = lr()
L.sort()
answer = 0
for i in range(N-1, -1, -1):
    # iが一番大きい辺
    x = L[i]
    left = 0
    right = i - 1
    while left < right:
        if L[left] + L[right] <= x:
            left += 1
            continue
        answer += (right - left)
        right -= 1

print(answer)
# Original solution
from bisect 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):
		for k in range(j+1, bisect(L, L[i]+L[j]-1)):
			ans+=1
print(ans)

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

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

list = list(itertools.combinations(L, 3))

count = 0

for i in list:
  if i[0] < i[1] + i[2]:
    if i[1] < i[0] + i[2]:
      if i[2] < i[1] + i[0]:
        count += 1

print(count)

# Optimized solution
import itertools

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

count = 0

for i in itertools.combinations(L, 3):
  if i[0] < i[1] + i[2]:
    if i[1] < i[0] + i[2]:
      if i[2] < i[1] + i[0]:
        count += 1

print(count)
# Original solution
from itertools import accumulate

N, *L = list(map(int, open(0).read().split()))

A = [0] * (2 * 10 ** 3 + 7)
for l in L:
    A[l] += 1

S = list(accumulate(A))

ans = 0
for i in range(N):
    b = L[i]
    for j in range(i + 1, N):
        c = L[j]
        l, r = abs(b - c), b + c
        ans += S[r - 1] - S[l] - (l < b < r) - (l < c < r)

print((ans // 3))


# Optimized solution
from itertools import accumulate, combinations

N, *L = list(map(int, open(0).read().split()))

A = [0] * (2 * 10 ** 3 + 7)
for l in L:
    A[l] += 1

S = list(accumulate(A))

ans = 0
for b, c in combinations(L, 2):
    l, r = abs(b - c), b + c
    ans += S[r - 1] - S[l] - (l < b < r) - (l < c < r)

print((ans // 3))
# Original solution
from itertools import combinations
from bisect import bisect_right

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

    L.sort()

    print((sum(bisect_right(L, L[i] + L[j] - 1, lo=j + 1) - (j + 1) for i, j in combinations(list(range(N)), 2))))

if __name__ == '__main__':
    main()


# Optimized solution
from itertools import combinations
from bisect import bisect_right

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

    L.sort()

    print((sum(bisect_right(L, L[i] + L[j] - 1, j + 1) - (j + 1) for i, j in combinations(list(range(N)), 2))))

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

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

ans = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        a = L[i]
        b = L[j]
        ans += bisect.bisect_right(L[j + 1:], a + b - 1)

print(ans)


# Optimized solution
import bisect

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

ans = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        a = L[i]
        b = L[j]
        ans += max(0, bisect.bisect_right(L, a + b - 1) - (j + 1))

print(ans)
# Original solution
import bisect

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

ans=0

def find_gt(a,x):
    i = bisect.bisect_right(a,x)
    if i != len(a):
        return i
    return(-1)

for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        l=L[:j]
        if len(l)>=1:
            num=find_gt(l,L[i]-L[j])
            if num!=-1:
                ans+=len(l)-num
        else:
            continue


print(ans)

# Optimized solution
import bisect

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):
        T=bisect.bisect_left(L,L[i]+L[j])
        count+=T-j-1
print(count)
# Original solution
import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
count = 0
for a in range(N):
    for b in range(a+1, N):
        Ll = L[b+1:N]
        la = L[a]
        lb = L[b]
        ab = la + lb
        sa = abs(la-lb)
        first = bisect.bisect_left(Ll, ab) -1 
        second = bisect.bisect_right(Ll, sa)
        count += first - second +1
print(count)




# Optimized solution
import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
count = 0
total = []
for a in range(N-2):
    for b in range(a+1, N-1):
        la = L[a]
        lb = L[b]
        ab = la + lb
        sa = abs(la-lb)
        first = bisect.bisect_left(L, ab) -1 
        second = bisect.bisect_right(L, sa)
        if first > second and first >= b+1:
            count += first - max(second, b+1) +1
print(count)
# Original solution
import bisect

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

SUM = 0
for i,a in enumerate(A):
    for j,b in enumerate(A[i+1:]):
        SUM += bisect.bisect_left(A[i+j+2:], a+b)

print(SUM)


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

for i in range(N-1,0,-1):
    l = 0
    r = i -1
    while(l< r):
        if (A[l] + A[r] >A[i]):
            count += (r-l)
            r -= 1
        else:
            l += 1
print(count)
# Original solution
import bisect
import itertools

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

cnt = 0

for i in range(N):
    L_t = L[i+1:N]
    for v in itertools.combinations(L_t, 2):
        a = int(L[i])
        b = int(v[0])
        c = int(v[1])

        if a < b + c and b < a + c and c < a + b:
            cnt += 1
print(cnt)




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

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ab = L[i] + L[j]
        c_index = bisect.bisect_left(L, ab)
        cnt += c_index - 1 - j
print(cnt)
# Original solution
#import heapq
import itertools
#import math
#import numpy as np
#import sys

N = int(eval(input()))
L = list(map(int, input().split()))
#S = [input() for _ in range(H)]
#T = [list(map(int,input().split())) for _ in range(N)]
#sys.exit()
L = sorted(L)
a = [(x, y, z) for (x, y, z) in itertools.combinations(L, 3) if ((x+y) > z) and ((x+z) > y) and ((y+z) > x)]
print((len(a)))

# Optimized solution
#import heapq
import itertools
#import math
#import numpy as np
#import sys

N = int(eval(input()))
L = list(map(int, input().split()))
L = sorted(L)
#print(L)
C = itertools.combinations(list(range(0,N-1)), 2)
ans = 0
i = 1
for c in C :
    #print(c)
    while True :
        #print(L[c[1] + i])
        if L[c[0]] + L[c[1]] > L[c[1] + i] :
            ans += 1
            i += 1
        else :
            i = 1
            break

        if c[1] + i > N - 1:
            i = 1
            break
print(ans)


#a = [(x, y, z) for (x, y, z) in itertools.combinations(L, 3) if ((x+y) > z) and ((x+z) > y) and ((y+z) > x)]
#print(len(a))
# Original solution
#import heapq
import itertools
#import math
#import numpy as np
#import sys

N = int(eval(input()))
L = list(map(int, input().split()))
L = sorted(L)
#print(L)
C = itertools.combinations(list(range(0,N-1)), 2)
ans = 0
i = 1
for c in C :
    #print(c)
    while True :
        #print(L[c[1] + i])
        if L[c[0]] + L[c[1]] > L[c[1] + i] :
            ans += 1
            i += 1
        else :
            i = 1
            break

        if c[1] + i > N - 1:
            i = 1
            break
print(ans)


#a = [(x, y, z) for (x, y, z) in itertools.combinations(L, 3) if ((x+y) > z) and ((x+z) > y) and ((y+z) > x)]
#print(len(a))

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

ans = 0
ans2 = 0
for k in range(N-2):
  for j in range(k+1, N-1):
    cnt = 0
    for l in range(N-1, j, -1):
      if L[k] + L[j] <= L[l]:
        cnt += 1
        continue
      else:
        ans += N-1-j-cnt
        break
print(ans)

# Optimized solution
# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)


N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
bit = BIT(L[-1]*2+1)
bit.add(L[0]+L[1], 1)
total = 1
ans = 0
for k in range(2, N):
  ans += total - bit.sum(L[k])
  for j in range(k):
    bit.add(L[j]+L[k], 1)
    total += 1

print(ans)
# Original solution
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 20:56:06 2020

@author: liang
"""

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

L.sort()
ans = 0
#print(L)
for i in range(N-2):
    #print("1:",i)
    p = i+2
    #以下O(2?N)　定数倍が遅い
    for j in range(i+1,N-1):
        #print("2",i,j)
        while p < N and L[p] < L[i] + L[j] :
            p += 1
            #print("up")
        #print(p)
        #ans += len(L[j+1:p])
        ans += max(0, p - j - 1)
print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 21:39:55 2020

@author: liang
"""

# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 20:56:06 2020

@author: liang
"""

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

from bisect import bisect_left

L.sort()
ans = 0
#print(L)
for i in range(N-2):
    #print("1:",i)
    #p = i+2
    #以下O(2N)　定数倍が遅い
    for j in range(i+1,N-1):
        #print("2",i,j)
        t = L[i] + L[j]
        #while p < N and L[p] < L[i] + L[j] :
        #    p += 1
        p = bisect_left(L,t)
            #print("up")
        #print(p)
        #ans += len(L[j+1:p])
        ans += max(0, p - j -1)
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))

from itertools import combinations

comb = combinations(L, 3)

ans = 0
for c in comb:
    if 2*max(c)<sum(c):
        ans+=1
        
print(ans)

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

from bisect import bisect_right

L = sorted(L, reverse=True)
L = [-L[i] for i in range(N)]

cnt=0
for i in range(N-2):
    for j in range(i+1, N-1):
        diff = L[i]-L[j]
        idx = bisect_right(L, diff-1, j+1, N)
        cnt+=(idx-j)-1
    
print(cnt)
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
count=0
for i in range(n-2):
  for j in range(i+1,n-1):
    left=j+1
    right=n-1
    while left<=right:
      center=(right+left)//2
      if center==n-1:
        if l[i]+l[j]>l[center]:
          count+=center-j
        break
      elif l[center+1]>l[i]+l[j]>l[center] :
        count+=center-j
        break
      elif l[i]+l[j]>l[center]:
        left=center+1
      else:
        right=center-1
print(count)

# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
l.reverse()
count=0
for i in range(n-2):
  j=i+1
  k=n-1
  while j<k:
    if l[i]<l[j]+l[k]:
      count+=k-j
      j+=1
    else:
      k-=1
print(count)
# Original solution
import bisect

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

    L.sort()
    ans = 0
    for i in range(N-2):
        for j in range(i+1,N-1):
            tmp = L[i] + L[j]
            insert_index = bisect.bisect_left(L[j+1:], tmp)
            #print(insert_index)
            ans += insert_index

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import bisect
import time

def main():
    N = int(eval(input()))
    L = [int(i) for i in input().split()]
    #N = 2000
    #L = [int(i) for i in range(N)]

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

    print(ans)


if __name__ == "__main__":
    #start = time.time()
    main()
    #elapsed_time = time.time() - start
    #print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
# Original solution
import bisect
import time

def main():
    N = int(eval(input()))
    L = [int(i) for i in input().split()]
    #N = 2000
    #L = [int(i) for i in range(N)]

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

    print(ans)


if __name__ == "__main__":
    #start = time.time()
    main()
    #elapsed_time = time.time() - start
    #print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")


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

def main():
    N = int(readline())
    L = [int(i) for i in readline().split()]
    L.sort()

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

    print(ans)


if __name__ == "__main__":
    main()
# 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):
        a = L[i]+L[j]
        ind = bisect.bisect_left(L[j+1:],a)
        cnt += ind
print(cnt)

# Optimized 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):
        a = L[i]+L[j]
        ind = bisect.bisect_left(L,a)
        cnt += ind-j-1
print(cnt)
# Original solution
from bisect import bisect_left,bisect_right
from itertools import combinations
N = int(eval(input()))
L = sorted(list(map(int,input().split())))
cnt = 0
for x in combinations(list(range(N)),2):
    i,j = x[0],x[1]
    if j<i:
        i,j = j,i
    indr = bisect_left(L,L[i]+L[j])
    indl = bisect_right(L,abs(L[i]-L[j]))
    if j<indl or i>indr:
        cnt += indr-indl
    elif indr>j>=indl and i<indl:
        cnt += indr-indl-1
    elif indr>j and i>=indl:
        cnt += indr-indl-2
    elif j>=indr and indr>i>=indl:
        cnt += indr-indl-1
print((cnt//3))

# Optimized solution
from bisect import bisect_right,bisect_left
N = int(eval(input()))
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        a = L[i]
        b = L[j]
        indU = bisect_left(L,a+b)
        indL = bisect_right(L,b-a)
        if j<indU and i>= indL:
            cnt += indU-indL-2
        elif indL<=i<indU and j>=indU or i<indL and indL<=j<indU:
            cnt += indU-indL-1
        elif j<indL or i>=indU:
            cnt += indU-indL
print((cnt//3))