CodeEff/ECCO huggingface dataset:
# Original solution
# ABC143 D Triangles

n = int(eval(input()))
l_list = [int(x) for x in input().split()]

l_list.sort()
ans = 0

# (i < j < k) -> (_a < _b < _c)
for i in range(n-2):
    _a = l_list[i]
    for j in range(i+1,n-1):
        _b = l_list[j]
        _tmp = _a + _b
        for k in range(j+1,n):
            _c = l_list[k]
            if _c < _tmp:
                ans += 1
            else:
                break

print(ans)

# Optimized solution
# ABC143 D Triangles

import bisect

n = int(eval(input()))
l_list = [int(x) for x in input().split()]

l_list.sort()
ans = 0

for i in range(n-2):
    _a = l_list[i]
    for j in range(i+1,n-1):
        _b = l_list[j]
        _tmp = bisect.bisect_left(l_list, _a+_b)
        if j < _tmp:
            ans += _tmp - j - 1

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

from itertools import combinations
X = list(combinations(L, 3))

ans = 0
for a,b,c in X:
    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()))
SL = sorted(list(L))
A = [0] * (10 ** 3 + 10)

for i in SL:
    A[i] = True
for i in range(len(A)):
    if A[i] == True:
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]

# print(A[4-1] - A[2])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            # print(i, j, k)
            a = SL[i]
            b = SL[j]
            c = SL[k]
            if a < b + c and b < c + a and c < a + b:
                ans += 1
print(ans)
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
SL = sorted(list(L))
A = [0] * (10 ** 3 + 10)

for i in SL:
    A[i] = True
for i in range(len(A)):
    if A[i] == True:
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]

# print(A[4-1] - A[2])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        # for k in range(j+1, N):
        #     a = SL[i]
        #     b = SL[j]
        #     c = SL[k]
        #     if a < b + c and b < c + a and c < a + b:
        #         ans += 1
        a = SL[i]
        b = SL[j]
        for k in range(j+1, N):
            c = SL[k]
            if abs(a - b) >= c:
                print('continue')
                continue
            elif c >= a + b:
                break
            else:
                ans += 1
print(ans)

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

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ab = SL[i] + SL[j]
        # print(i, j)
        # print(SL[i], SL[j])
        r = bisect.bisect_left(SL, ab)
        l = j + 1
        # print('r', r)
        # print('l', l)
        # print('---')
        ans += max(0, r - l)

print(ans)
# Original solution
import bisect
n = int(eval(input()))
l = list(map(int,input().split()))
co = []
ol = sorted(l)
nl = sorted(l,reverse=True)
for i in range(1,n):
    for j in range(1,n):
        if i<j:
            co.append(nl[i]+nl[j])
nco = list(reversed(co))
sk = 0
g = 0
for i in range(2,n):
    a = ol[i]
    x = nco[:(i)*(i-1)//2]
    ind = bisect.bisect(x,a)
    g += len(x)-ind
print(g)

# Optimized solution
import bisect
n=int(eval(input()))
l=sorted(list(map(int,input().split())))
g=0
for ai in range(n-2):
    for bi in range(ai+1,n-1):
        g+=max(0,bisect.bisect_left(l,l[bi]+l[ai])-1-bi)
print(g)
# Original solution
N=int(eval(input()))
L=list(map(int,input().split()))
L=sorted(L)

a=0
for i in range(N-1):
    for k in range(1,N-i-1):
        a=a+sum(x<L[i]+L[i+k] for x in L[i+k+1:N])

print(a)

# Optimized solution
import bisect

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

L=sorted(L)

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

print(ans)
# Original solution
import itertools

n = int(eval(input()))
list_score = list(map(int, input().split()))
list_score.sort()
p_list = list(itertools.combinations(list_score, 3))
a = len(p_list)
ans = 0

for i in range(a):
    if p_list[i][0] + p_list[i][1] > p_list[i][2]:
       ans += 1

print(ans)

# Optimized solution
import itertools

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

for i in range(0, n):
    for j in range(i+1, n):
        for k in range(i+1, j):
            if list_score[k] + list_score[i] > list_score[j]:
                ans += 1

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

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

import itertools
comb = list(itertools.combinations(ll ,3))
  
ans = len(list(filter(is_triangle, comb)))
print(ans)

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

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

ans = 0
for i, a in enumerate(ll):
  for j, b in enumerate(ll[i+1:]):
    climit = a + b
    for k, c in enumerate(ll[i+j+2:]):
      if c >= (climit):
        break
      if is_triangle(a, b, c):
        ans += 1
print(ans)
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))

l.sort(reverse=True)
ans=0

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

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

l.sort(reverse=True)
ans=0

for i in range(0,n-2):
  for j in range(i+1,n-1):
    left = j
    right = n
    while right-left>1:
      mid = (left + right)//2
      
      if l[i]+l[j]>l[mid] and l[i]+l[mid]>l[j] and l[mid]+l[j]>l[i]:
        left = mid
      else:
        right = mid
    #print(i,j,left)
    ans+=(left-j)
      
print(ans)
# Original solution
n = int(eval(input()))
L = list(map(int,input().split()))

def tri_judge(a,b,c):
    if a<b+c and b<c+a and c<a+b:
        return 1
    else:
        return 0
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        check = L[i]+L[j]
        for k in range(j+1,n):
            if check>L[k]:
                if(tri_judge(L[i],L[j],L[k])):
                    cnt += 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
from bisect import bisect_left

n = int(eval(input()))
a = sorted(map(int, input().split()))
print((sum(bisect_left(a, a[i] + a[j], i + 1) - i - 1
          for i in range(1, n - 1) for j in range(i))))


# Optimized solution
from bisect import bisect_right
 
n = int(eval(input()))
a = sorted(map(int, input().split()))
print((sum(j - bisect_right(a, a[i] - a[j], 0, j)
          for i in range(2, n) for j in range(1, i))))
# Original solution
import itertools


def d():
    _ = int(eval(input()))
    ls = list(map(int, input().split()))
    combs = list(itertools.combinations(ls, 3))
    count = 0
    a = 0
    b = 1
    c = 2

    for comb in combs:
        if comb[a] < comb[b] + comb[c] and comb[b] < comb[c] + comb[a] and comb[c] < comb[a] + comb[b]:
            count += 1
    print(count)


if __name__ == '__main__':
    d()


# Optimized solution
import itertools


def d():
    _ = int(eval(input()))
    ls = list(map(int, input().split()))
    combs = list(itertools.combinations(ls, 2))
    count = 0
    a = 0
    b = 1
    visited = set()

    for comb in combs:
        for l in ls:
            if {comb[a], comb[b], l} not in visited:
                visited.add(frozenset({comb[a], comb[b], l}))
                if l != comb[a] and l != comb[b] and abs(comb[a] - comb[b]) < l < comb[a] + comb[b]:
                    count += 1

    print(count)


if __name__ == '__main__':
    d()
# Original solution
import itertools


def d():
    _ = int(eval(input()))
    ls = list(map(int, input().split()))
    combs = list(itertools.combinations(ls, 2))
    count = 0
    a = 0
    b = 1
    visited = set()

    for comb in combs:
        for l in ls:
            if {comb[a], comb[b], l} not in visited:
                visited.add(frozenset({comb[a], comb[b], l}))
                if l != comb[a] and l != comb[b] and abs(comb[a] - comb[b]) < l < comb[a] + comb[b]:
                    count += 1

    print(count)


if __name__ == '__main__':
    d()


# Optimized solution
def d():
    n = int(eval(input()))
    ls = list(map(int, input().split()))
    ls.sort()
    count = 0
    for i in range(n-1):
        k = i + 2
        for j in range(i+1, n-1):
            while k < n and ls[i] + ls[j] > ls[k]:
                k += 1
            count += k - j - 1

    print(count)


if __name__ == '__main__':
    d()
# Original solution
import bisect
n = int(eval(input()))
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n-2):
  a = l[i]
  for j in range(i + 1, n-1):
    ans += bisect.bisect_left(l, l[j]+a, lo = j + 1)-j-1
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):
  a = l[i]
  for j in range(i + 1, n-1):
    ans += bisect.bisect_left(l, l[j]+a)-j-1
print(ans)
# Original solution
import math
N = int(eval(input()))
L = sorted(list(map(int, input().split())))

ans = 0

for a in range(N - 2):
    b = a + 1
    c = a + 2
    while c < N and b < N - 1:
        if L[c] >= L[a] + L[b]:
            ans += c - 1 - b
            b += 1
            if b == c:
                c += 1
        else:
            if c == N - 1:
                ans += c - b
                b += 1
            else:
                c += 1
        
print(ans)        

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

ans = 0

for a in range(N - 2):
    b = a + 1
    c = a + 2
    while c < N and b < N - 1:
        if L[c] >= L[a] + L[b]:
            ans += c - 1 - b
            b += 1
            if b == c:
                c += 1
        else:
            if c == N - 1:
                ans += (c - b) * (c - b + 1) // 2 
                break
            else:
                c += 1
        
print(ans)
# Original solution
import math
N = int(eval(input()))
L = sorted(list(map(int, input().split())))

ans = 0

for a in range(N - 2):
    b = a + 1
    c = a + 2
    while c < N and b < N - 1:
        if L[c] >= L[a] + L[b]:
            ans += c - 1 - b
            b += 1
            if b == c:
                c += 1
        else:
            if c == N - 1:
                ans += (c - b) * (c - b + 1) // 2 
                break
            else:
                c += 1
        
print(ans)        

# Optimized solution
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(0, N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        ok = j + 1
        ng = N - 1
        if L[ng] < a + b:
            ans += ng - j
            continue
        if L[ok] >= a + b:
            continue
        while ok + 1 < ng:
            c = (ok + ng) // 2
            if L[c] < a + b:
                ok = c
            else:
                ng = c
        ans += ok - j
print(ans)
# Original solution
value = 0
N = int(eval(input()))
L = list(map(int,input().split()))
L = sorted(L)  

for i in range(N-2):
  for j in range(i+1,N-1):
    x = L[i]+L[j]
    B = N-1
    A = j
    max_c_index = j
 #   while True:
    while A <= B: #A>Bとなったときに停めるようにすれば簡潔
     # M = A + (B-A)//2
      M = (A+B)//2 #こう書くほうがシンプル
      if L[M] < x:
        max_c_index = M
        A = M+1
      else:
#        B = M
        B = M-1
    value += max_c_index - j
print(value)

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

# 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):  # 真ん中の長さの棒
    ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)
# Original solution
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 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 a < b + c and b < c + a and c < a + b:
                ans += 1
            else:
                break
print(ans)

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

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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


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

"""
短いほうから２本固定して条件に合うものをさがす（長いほうから２本固定でもOK）
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""


ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        # そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや！
        k = bisect_left(L, L[i]+L[j], lo=j)
        ans += k - j - 1



"""
ans = 0
for i in range(N):
    for j in range(i+1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]
        #  a < b < c（場合によっては等号を含む）で考えたときの、b - a < cを満たすもの 
        il = bisect_right(L, l, lo=j)
        #  a < b < c（場合によっては等号を含む）で考えたときの、c < a + bを満たすもの
        ir = bisect_left(L, r, lo=j)
        # b - a < cを満たすものがない場合、飛ばす
        if il == N-1:
            break
        
        ans += ir - il - 1
"""

print(ans)


# Optimized solution
from bisect import bisect_left
from bisect import bisect_right


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

"""
短いほうから２本固定して条件に合うものをさがす（長いほうから２本固定でもOK）
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""


ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        # そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや！
        k = bisect_left(L, a+b)
        ans += k - j - 1



"""
ans = 0
for i in range(N):
    for j in range(i+1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]
        #  a < b < c（場合によっては等号を含む）で考えたときの、b - a < cを満たすもの 
        il = bisect_right(L, l, lo=j)
        #  a < b < c（場合によっては等号を含む）で考えたときの、c < a + bを満たすもの
        ir = bisect_left(L, r, lo=j)
        # b - a < cを満たすものがない場合、飛ばす
        if il == N-1:
            break
        
        ans += ir - il - 1
"""

print(ans)
# Original solution
from bisect import bisect_left
from bisect import bisect_right


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

"""
短いほうから２本固定して条件に合うものをさがす（長いほうから２本固定でもOK）
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""


ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        # そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや！
        k = bisect_left(L, a+b)
        ans += k - j - 1



"""
ans = 0
for i in range(N):
    for j in range(i+1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]
        #  a < b < c（場合によっては等号を含む）で考えたときの、b - a < cを満たすもの 
        il = bisect_right(L, l, lo=j)
        #  a < b < c（場合によっては等号を含む）で考えたときの、c < a + bを満たすもの
        ir = bisect_left(L, r, lo=j)
        # b - a < cを満たすものがない場合、飛ばす
        if il == N-1:
            break
        
        ans += ir - il - 1
"""

print(ans)


# Optimized solution
from bisect import bisect_left
from bisect import bisect_right


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

"""
短いほうから２本固定して条件に合うものをさがす（長いほうから２本固定でもOK）
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""


ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        #b = L[j]
        # そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや！
        k = bisect_left(L, a+L[j])
        ans += k - j - 1



"""
ans = 0
for i in range(N):
    for j in range(i+1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]
        #  a < b < c（場合によっては等号を含む）で考えたときの、b - a < cを満たすもの 
        il = bisect_right(L, l, lo=j)
        #  a < b < c（場合によっては等号を含む）で考えたときの、c < a + bを満たすもの
        ir = bisect_left(L, r, lo=j)
        # b - a < cを満たすものがない場合、飛ばす
        if il == N-1:
            break
        
        ans += ir - il - 1
"""

print(ans)
# Original solution
import bisect

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

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

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

n = int(eval(input()))
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
    l_a = ld.popleft()
    for b in range(a + 1, n - 1):
        cnt += bisect_left(l[b + 1 :], l_a + l[b])
print(cnt)

# Optimized solution
from collections import deque
from bisect import bisect_left

n = int(eval(input()))
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
    l_a = ld.popleft()
    for b in range(a + 1, n - 1):
        cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt)
# Original solution
from collections import deque
from bisect import bisect_left

n = int(eval(input()))
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
    l_a = ld.popleft()
    for b in range(a + 1, n - 1):
        cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt)

# Optimized solution
def main():
    from collections import deque
    from bisect import bisect_left

    n = int(eval(input()))
    l = sorted(map(int, input().split()))
    ld = deque(l)
    cnt = 0
    for a in range(n - 2):
        l_a = ld.popleft()
        for b in range(a + 1, n - 1):
            cnt += bisect_left(l, l_a + l[b]) - b - 1
    print(cnt)


if __name__ == "__main__":
    main()
# Original solution
#coding:utf-8
import sys
import bisect
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    L = LMIIS()
    L.sort()
    count = 0
    for i in range(N):
        a = L[i]
        for j in range(i+1,N):
            b = L[j]
            k = j+1
            while k < N and a+b > L[k]:
                k += 1
                count += 1
    print(count)



if __name__ == '__main__':
    main()


# Optimized solution
#coding:utf-8
import sys
import bisect
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    L = LMIIS()
    L.sort()
    count = 0
    for i in range(N):
        a = L[i]
        k = i+2
        for j in range(i+1,N):
            b = L[j]
            while k < N and a+b > L[k]:
                k += 1
            count += k - 1 - j
    print(count)



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

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

T = list(itertools.combinations(L,3))
ans = 0
for t in T:
    if t[0] < t[1]+t[2] and t[1] < t[0]+t[2] and t[2] < t[0]+t[1]:
        ans += 1
print(ans)



# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for n1 in range(N):
    for n2 in range(n1+1, N):
        for n3 in range(n2+1, N):
            if L[n1] + L[n2] > L[n3]:
                ans += 1 

print(ans)
# Original solution
import math
N=int(eval(input()))
S=input().split()
list=[]
for i in range(0,N):
  list.append(int(S[i]))
list.sort()
ans=0
for i in range(0,N-2):
  a=list[i]
  for j in range(i+1,N-1):
    b=list[j]
    L=j+1
    R=N-1
    while True:
      if L==R or R==L+1:
        break
      if list[math.floor((L+R)/2)]>=a+b:
        R=math.floor((L+R)/2)
      else:
        L=math.floor((L+R)/2)
    if list[L]>=a+b:
      ans=ans+L-j-1
    else:
      if list[R]>=a+b:
        ans=ans+L-j
      else:
        ans=ans+R-j
print(ans)

# Optimized solution
import bisect
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 = bisect.bisect_left(l,l[i]+l[j])
    count += index - j - 1
    
print(count)
# Original solution
import itertools

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

l=list(itertools.combinations(L,3))
result = 0

for i in l:
    isOk=True
    a,b,c=i
    if a+b>c and a+c>b and c+b>a:
        result+=1

print(result)

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

result = 0

for aIndex,a in enumerate(L):
    for bIndex,b in enumerate(L[aIndex+1:]):
        for c in L[aIndex+bIndex+2:]:
            if a<b+c and b<a+c and c<a+b:
                result+=1

print(result)
# Original solution
from bisect import bisect_left

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

for aIndex,a in enumerate(L[:N-2]):
    for bIndex,b in enumerate(L[aIndex+1:N-1]):
        bIndex = aIndex + bIndex + 1
        ab = a+b
        n = bisect_left(L,ab) - bIndex - 1
        result += n
print(result)

# Optimized solution
from bisect import bisect_left

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

for i,a in enumerate(L[:N-2]):
    i += 1
    for j,b in enumerate(L[i:N-1]):
        j += i + 1
        n = bisect_left(L,a+b) - j
        result += n
print(result)
# Original solution
import bisect

n = int(eval(input()))
l = sorted([int(i) for i in input().split()])
ans = 0
for d in range(n):
    for e in range(d+1, n):
        a, b = l[d], l[e]
        idx = bisect.bisect_right(l, a + b)
        for c in l[e+1:idx]:
            if not c < a + b:
                break
            ans += 1
print(ans)


# Optimized solution
import bisect

n = int(eval(input()))
l = sorted([int(i) for i in input().split()])
ans = 0
for d in range(n):
    for e in range(d+1, n):
        a, b = l[d], l[e]
        idx = bisect.bisect_left(l, a + b)
        ans += max(idx - e - 1, 0)
print(ans)
# Original solution
from bisect import bisect_left

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

L.sort()

num_triangles = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_left(a=L, x=L[i]+L[j], lo=j+1)        
        num_triangles += idx-(j+1) 
print(num_triangles)


# 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):
        endpt = bisect_left(l, l[i] + l[j])
        ans += endpt-j-1

print(ans)