Problem:
 Score : 400 points    Problem Statement Takahashi has N sticks that are distinguishable from each other. The length of the i -th stick is L_i .  He is going to form a triangle using three of these sticks. Let a , b , and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:   a < b + c  b < c + a  c < a + b   How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.      Constraints  All values in input are integers.  3 \leq N \leq 2 \times 10^3  1 \leq L_i \leq 10^3         Input Input is given from Standard Input in the following format:  N  L_1  L_2  ...  L_N       Constraints Print the number of different triangles that can be formed.        Sample Input 1 4
3 4 2 1      Sample Output 1 1  Only one triangle can be formed: the triangle formed by the first, second, and third sticks.       Sample Input 2 3
1 1000 1      Sample Output 2 0  No triangles can be formed.       Sample Input 3 7
218 786 704 233 645 728 389      Sample Output 3 23

Solution (Python):
import bisect
n = int(input())
l = sorted(map(int, input().split()))
ans = 0
for mid in range(n-1, -1, -1):
    for low in range(mid - 1, -1, -1):
        itr = bisect.bisect_left(l, l[mid] + l[low])
        ng = n - itr
        ans += ((n - 1 - mid) - ng)
print(ans)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
    l = b + 1
    r = l
    for a in range(b):
        maxL = L[a] + L[b]
        while r<N and L[r]<maxL: r += 1
        ans += max(0, r-l)
print(ans)

Solution (Python):
length = 2010

n = int(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)

Solution (Python):

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]):
        
        c_i = bisect.bisect_right(l_list, abs(a - b))
        total += max(b_i - c_i, 0)

ans = total
print(ans)

Solution (Python):
from bisect import *

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = max(j+1, bisect_right(l, b-a))
        upper = bisect_left(l, a+b)
        cnt += upper-lower

print(cnt)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
from bisect import bisect_right
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):ans+=bisect_right(a,a[j]+a[i]-0.5)-j-1
print(ans)

Solution (Python):
from bisect import *

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = max(j+1, bisect_right(l, b-a))
        upper = bisect_left(l, a+b)
        cnt += max(0, upper-lower)

print(cnt)

Solution (Python):
from bisect import bisect_left

N = int(raw_input())
L = map(int, raw_input().split())

L.sort()
result = 0
for i in xrange(N-2):
    a = L[i]
    for j in xrange(i+1, N-1):
        b = L[j]
        k = bisect_left(L, a + b, j + 1)
        result += k - (j + 1)
print result

Solution (Python):
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
    l = b + 1
    for a in range(b):
        maxL = L[a] + L[b]
        r = bisect.bisect_left(L, maxL)
        ans += max(0, r-l)
print(ans)

Solution (Python):
import bisect

n=int(input())
l=sorted(map(int,input().split()))

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

print(t)

Solution (Python):
import bisect

n=int(input())
l=sorted(map(int,input().split()))

t=0
for i in range(n):
  for j in range(i+1,n):
    a = j+1
    b = bisect.bisect_left(l,l[i]+l[j])
    t += b-a if b>a else 0

print(t)

Solution (Python):
import bisect

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

li.sort()

for i in range(n):
  for j in range(i+1, n):
    cnt = bisect.bisect_left(li, li[i]+li[j])
    ans += cnt - j - 1
            
print(ans)

Solution (Python):
import bisect

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

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

Solution (Python):
N = int(input())
csum = list(0 for _ in range(2000+1))
L = []
for l in map(int,input().split()):
    L.append(l)
    csum[l] += 1
for i in range(1,len(csum)): csum[i] += csum[i-1]
ans = 0
for ib in range(N):
    b = L[ib]
    for ia in range(ib):
        a = L[ia]
        minL, maxL = abs(a-b), a+b
        ans += csum[maxL-1] - csum[minL]
        if minL < a < maxL: ans -= 1
        if minL < b < maxL: ans -= 1
print(ans//3)

Solution (Python):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string


import random  
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')



input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
a=sorted(LI())[::-1]

def solve(a):
    s=set()
    for i in a:
        s.add(i)
    s=sorted(list(s))[::-1]
    L=1010
    k=[0]*(L)
    ak=[0]
    for i in a:
        k[i]+=1
    for i in range(L):
        ak.append(ak[-1]+k[i])
    ans,a1,a2,a3,a4=0,0,0,0,0
    un=len(s)
    for i in range(un):
        c=s[i]
        if k[c]>=3:
            a1+=k[c]*(k[c]-1)*(k[c]-2)//6
        if k[c]>=2:
            a2+=ak[c]*k[c]*(k[c]-1)//2
        for j in range(i+1,un):
            sc=s[j]
            a3+=(1 if 2*sc>c else 0)*k[c]*k[sc]*(k[sc]-1)//2
            mm=c-sc+1
            if mm<0:
                continue
            elif mm>sc:
                break
            else:
                a4+=k[c]*k[sc]*(ak[sc]-ak[mm])
            
    ans=a1+a2+a3+a4
    return ans,a1,a2,a3,a4

def naive(a):
    b=sorted(a)[::-1]
    n=len(b)
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if b[j]+b[k]>b[i]:
                    ans+=1
    return ans

print(solve(a)[0])

Solution (Python):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string


import random  
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')



input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
a=sorted(LI())[::-1]

def solve(a):
    s=set()
    for i in a:
        s.add(i)
    s=sorted(list(s))[::-1]
    L=1010
    k=[0]*(L)
    ak=[0]
    for i in a:
        k[i]+=1
    for i in range(L):
        ak.append(ak[-1]+k[i])
    ans,a1,a2,a3,a4=0,0,0,0,0
    un=len(s)
    for i in range(un):
        c=s[i]
        if k[c]>=3:
            a1+=k[c]*(k[c]-1)*(k[c]-2)//6
        if k[c]>=2:
            a2+=ak[c]*k[c]*(k[c]-1)//2
        for j in range(i+1,un):
            sc=s[j]
            a3+=(1 if 2*sc>c else 0)*k[c]*k[sc]*(k[sc]-1)//2
            mm=c-sc+1
            if mm<0:
                continue
            elif mm>sc:
                break
            else:
                a4+=k[c]*k[sc]*(ak[sc]-ak[mm])
            
    ans=a1+a2+a3+a4
    return ans,a1,a2,a3,a4

def naive(a):
    b=sorted(a)[::-1]
    n=len(b)
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if b[j]+b[k]>b[i]:
                    ans+=1
    return ans

print(solve(a)[0])

Solution (Python):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string


import random  
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')



input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
a=sorted(LI())[::-1]


def solve(a):
    
    s=set()
    for i in a:
        s.add(i)
    s=sorted(list(s))[::-1]
    L=1080
    
    k=[0]*(L)
    ak=[0]
    ans=0
    for i in a:
        k[i]+=1
    for i in range(L):
        ak.append(ak[-1]+k[i])
    a1,a2,a3,a4=0,0,0,0
    un=len(s)
    for i in range(un):
        c=s[i]
        if k[c]>=3:
            a1+=k[c]*(k[c]-1)*(k[c]-2)//6
        if k[c]>=2:
            a2+=ak[c]*k[c]*(k[c]-1)//2
        for j in range(i+1,un):
            
            
            sc=s[j]
            a3+=(1 if 2*sc>c else 0)*k[c]*k[sc]*(k[sc]-1)//2
            if ak[sc]==0:
                break
            mm=c-sc+1
            if mm<0:
                continue
            elif mm>sc:
                continue 
            else:
                a4+=k[c]*k[sc]*(ak[sc]-ak[mm])
            
    
    ans=a1+a2+a3+a4
    
    return ans,a1,a2,a3,a4

def naive(a):
    b=sorted(a)[::-1]
    n=len(b)
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if b[j]+b[k]>b[i]:
                    ans+=1
    return ans

print(solve(a)[0])

Solution (Python):
from itertools import *
N = int(input())
csum = list(0 for _ in range(2000+1))
L = []
for l in map(int,input().split()):
    L.append(l)
    csum[l] += 1
csum = list(accumulate(csum))
ans = 0
for ia in range(N-1):
    for ib in range(ia+1,N):
        a, b = L[ia], L[ib]
        minL, maxL = abs(a-b), a+b
        ans += csum[maxL-1] - csum[minL]
        if minL < a and a < maxL: ans -= 1
        if minL < b and b < maxL: ans -= 1
print(ans//3)

Solution (Python):
N = int(input())
L = [int(x) for x in input().split()]

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

Solution (Python):
from bisect import bisect_left
n = int(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):
   ans += bisect_left(l,l[i] + l[j]) - j - 1
print(ans)

Solution (Python):
from itertools import *
N = int(input())
csum = list(0 for _ in range(2000+1))
L = []
for l in map(int,input().split()):
    L.append(l)
    csum[l] += 1
csum = list(accumulate(csum))
ans = 0
for ib in range(N):
    for ia in range(ib):
        a, b = L[ia], L[ib]
        minL, maxL = abs(a-b), a+b
        ans += csum[maxL-1] - csum[minL]
        if minL < a and a < maxL: ans -= 1
        if minL < b and b < maxL: ans -= 1
print(ans//3)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i + 1, n):
    lf = j
    rf = n
    while rf - lf > 1:
      md = (lf + rf) // 2
      if l[md] < l[i] + l[j]:
        lf = md
      else:
        rf = md
    ans += lf - j
    
print(ans)

Solution (Python):
from itertools import *
N = int(input())
L = list(map(int,input().split()))
csum = list(0 for _ in range(2000+1))
for i in range(N): csum[L[i]] += 1
csum = list(accumulate(csum))
ans = 0
for ib in range(N):
    for ia in range(ib):
        a, b = L[ia], L[ib]
        minL, maxL = abs(a-b), a+b
        ans += csum[maxL-1] - csum[minL]
        if minL < a and a < maxL: ans -= 1
        if minL < b and b < maxL: ans -= 1
print(ans//3)

Solution (Python):
import sys
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

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


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import sys
input = sys.stdin.readline


def main():
    n = int(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()

Solution (Python):

import bisect
import sys
input = sys.stdin.readline


def main():
    n = int(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.bisect_left(l, l[i] + l[j]) - (j + 1)

    print(result)


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import sys
input = sys.stdin.readline


def main():
    n = int(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.bisect_left(l, l[i] + l[j]) - (j + 1)

    print(result)


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left
n = int(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):
   ans += bisect_left(l,l[i] + l[j]) - j - 1
print(ans)

Solution (Python):
N = int(input())
Ln = list(map(int,input().split(' ')))
Ln.sort(reverse=True)

count = 0
for a in range(N):
    a_l = Ln[a]
    current_min = N-1
    b = a +1
    while b <= current_min:
        c_idx = current_min
        bc = Ln[b] + Ln[c_idx]
        if a_l < bc:
            count += (current_min - b)
            b += 1
            continue
        current_min -= 1
    '''
    for b in range(a+1, N):
        if b >= current_min:
            break
        for c in range(b+1,N):
            c_idx = current_min
            bc = Ln[b] + Ln[c_idx]
            if a_l < bc:
                count += (current_min - b)
                break
            current_min -= 1
    '''
print(count)

Solution (Python):
import bisect

n = int(input())
l_list = list(map(int,input().split()))

l_list.sort()

count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        a=l_list[i]
        b=l_list[j]
        
        count+=(bisect.bisect_left(l_list,a+b)-j-1)

print(count)

Solution (Python):
def nibun(a,x):
    return bisect.bisect_left(a, x) 

import bisect
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
N = I()
ans = int(0)
L = LI()

L.sort()
t = int(0)
for i in range(N):
    for j in range(i+1,N):
        t = L[i] + L[j]
        count =int(0)
        count += nibun(L,t) - (j+1)
        ans += max(count,0)


print(ans)

Solution (Python):
from sys import stdin
 
def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    
    ans = 0
    for i in range(len(l)-2):
        first = l[i]
        for j in range(i + 2, len(l)):
            second = l[j]
            s = i + 1
            e = j 
            
            while(True):
                mid = int((s + e) / 2)
                
                
                if s == e:
                    break
                else:
                    if second >= first + l[mid]:
                        if s == mid:
                            s = e
                        else:
                            s = mid
                    else:
                        e = mid
            
            ans += j - s
            
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left

N = int(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)

Solution (Python):
import bisect
a=int(input())
b=list(map(int,input().split()))
b.sort()
ans=0
for i in range(a):
  for j in range(i+1,a):
    k=bisect.bisect_right(b,b[i]+b[j]-1)
    ans+=k-j-1
print(ans)

Solution (Python):
import bisect

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

ans = 0

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

print(ans)

Solution (Python):
import bisect

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

    L = sorted(L)
    
    ans = 0
    
    
    
    
    

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect

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

    L = sorted(L)
    
    ans = 0
    
    
    
    
    

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect

N = int(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):
        insert_index = bisect.bisect_left(l, l[i] + l[j],j) 
        ans += (insert_index - j - 1)

print(ans)

Solution (Python):
import bisect

N=int(input())

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

L_sorted=sorted(L)

ans=0

for i in range(2,N):  
    for j in range(1,i):   
        MIN=L_sorted[i]-L_sorted[j]+1
        MIN_index=bisect.bisect_left(L_sorted,MIN)
        number_of_indexes=(j-1)-MIN_index+1
        if number_of_indexes>0:
            ans+=number_of_indexes
        
print(ans)

Solution (Python):
N = int(input())
L = list(map(int, input().split()))

L.sort()

from bisect import*
ans = 0
for i in range(N):
    for j in range(i+1, N):
        a = L[i]
        b = L[j]
        r = bisect_left(L, (a + b))
        l = j + 1
        ans += max(0, r-l)
print(ans)

Solution (Python):
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

def f(j, max1, max2):
    L_temp = L[j+1:]
    
    dif = max1 - max2
    left = -1
    right = len(L_temp)
    while right - left != 1:
        temp = (left+right)//2
        if dif < L_temp[temp]:
            left = temp
        else:
            right = temp
    return left+1


ans = 0
max1 = 0
max2 = 0
for i in range(N):
    max1 = L[i]
    for j in range(i+1, N-1):
        max2 = L[j]
        ans += f(j, max1, max2)
        
print(ans)

Solution (Python):
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

def f(j, max1, max2):
    L_temp = L[j+1:]
    
    dif = max1 - max2
    left = -1
    right = len(L_temp)
    while right - left != 1:
        temp = (left+right)//2
        if dif < L_temp[temp]:
            left = temp
        else:
            right = temp
    return left+1


ans = 0
max1 = 0
max2 = 0
for i in range(N):
    max1 = L[i]
    for j in range(i+1, N-1):
        max2 = L[j]
        ans += f(j, max1, max2)
        
print(ans)

Solution (Python):
N = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
from bisect import *
ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        a = l_list[i]
        b = l_list[j]
        high = a + b
        id1 = bisect_right(l_list, high - 1)
        ans += max(0, id1 - (j + 1))
print(ans)

Solution (Python):
import bisect

if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))

    l = sorted(l)

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

    print(answer)

Solution (Python):
from bisect import bisect_left

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

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

print(result)

Solution (Python):
N = int(input())
A = sorted([int(a) for a in input().split()])
X = [0] * 1001
for a in A:
    X[a] += 1
for i in range(1, 1001):
    X[i] += X[i-1]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += X[min(A[i]+A[j]-1, 1000)] - (j+1)
print(ans)

Solution (Python):
from bisect import bisect_right


def d():
    n = int(input())
    ls = list(map(int, input().split()))
    ls.sort()
    count = 0
    for i in range(n-1, -1, -1):
        for j in range(i-1, -1, -1):
            k = bisect_right(ls, ls[i]-ls[j])
            if j >= k:
                count += j - k

    print(count)


if __name__ == '__main__':
    d()

Solution (Python):

from bisect import bisect_left

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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        tmp = l[i] + l[j]
        back = bisect_left(l, tmp)
        ans += (back-1) - j
        

print(ans)

Solution (Python):
from bisect import bisect
from bisect import bisect_left

_ = input()
l = input()
l = sorted(list(map(int, l.split())))
count = 0
n = len(l)

for i in range(n):
	for j in range(i+1, n):
		
		count += bisect_left(l,l[i]+l[j]) - (j+1)

print(count)

Solution (Python):
from bisect import bisect
from bisect import bisect_left

_ = input()
l = input()
l = sorted(list(map(int, l.split())))
count = 0

for i in range(len(l)):
	for j in range(i+1, len(l)):
		
		count += bisect_left(l,l[i]+l[j]) - (j+1)

print(count)

Solution (Python):
from bisect import bisect
from bisect import bisect_left

n = int(input())
l = input()
l = sorted(list(map(int, l.split())))
count = 0

for i in range(n):
	for j in range(i+1, n):
		c = l[i]+l[j]
		count += bisect_left(l,c) - (j+1)

print(count)

Solution (Python):
from bisect import bisect
from bisect import bisect_left

_ = input()
l = input()
l = sorted(list(map(int, l.split())))
count = 0

for i in range(len(l)):
	for j in range(i+1, len(l)):
		c = l[i]+l[j]
		count += bisect_left(l,c) - (j+1)

print(count)

Solution (Python):

def triangle_check(a, b, c):
  if a>b+c:
    return False
  elif b>a+c:
    return False
  elif c>a+b:
    return False
  else:
    return True

def count_triangles(n, sticks):
  assert len(sticks) == n, "lenght of sticks does not match `n`"
  count = 0

  for i in range(len(sticks)-2):
    for j in range(i+1, len(sticks)-1):
      for k in range(j+1, len(sticks)):
        count += triangle_check(sticks[i], sticks[j] , sticks[k])

  return count

def findnumberofTriangles(arr): 
  
    
    n = len(arr) 
    arr.sort() 
    count = 0
  
    
    
    for i in range(0, n-2): 
  
        
        k = i + 2
  
        
        for j in range(i+1,n): 
  
            
            
            
            
            
            
            
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
            
            
            
            
            
            
            
            
            
            count += k - j - 1
  
    return count 

if __name__ == "__main__":

  n = int(input())
  sticks = sorted(list(map(int, input().split(" "))))
  
  num_triangles = findnumberofTriangles(sticks)
  print(num_triangles)

Solution (Python):
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0

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

print(ans)

Solution (Python):

def triangle_check(a, b, c):
  if a>b+c:
    return False
  elif b>a+c:
    return False
  elif c>a+b:
    return False
  else:
    return True

def count_triangles(n, sticks):
  assert len(sticks) == n, "lenght of sticks does not match `n`"
  count = 0

  for i in range(len(sticks)):
    for j in range(i+1, len(sticks)):
      for k in range(j+1, len(sticks)):
        count += triangle_check(sticks[i], sticks[j] , sticks[k])

  return count

def findnumberofTriangles(arr): 
  
    
    n = len(arr) 
    arr.sort() 
    count = 0
  
    
    
    for i in range(0,n-2): 
  
        
        k = i + 2
  
        
        for j in range(i+1,n): 
  
            
            
            
            
            
            
            
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
            
            
            
            
            
            
            
            
            
            if(k>j): 
                count += k - j - 1
  
    return count 

if __name__ == "__main__":

  n = int(input())
  sticks = sorted(list(map(int, input().split(" "))))
  
  num_triangles = findnumberofTriangles(sticks)
  print(num_triangles)

Solution (Python):
def answer_143d():    
    n = int(input())
    ls = list(map(int,input().split()))

    ls.sort()
    ans = 0

    for i in range(n-1, 0, -1):
        l = 0
        r = i - 1

        while l < r:
            if ls[l] + ls[r] > ls[i]:
                ans += r - l
                r -= 1
            else:
                l += 1
    print(ans)

if __name__ == '__main__':
    answer_143d()

Solution (Python):
import bisect

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

for i in range(N-1):
  k = A[i]
  for j in range(i+1, N):
    l = A[j]
    res = bisect.bisect_left(A, k+l)
    ans += res-j-1
    
print(ans)

Solution (Python):
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0

for i in range(n):
    for j in range(i+1, n):
        length = l[i] + l[j]

        index = bisect.bisect_left(l[j+1:], length)
        ans += index

print(ans)

Solution (Python):
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
biSet = set()


for i in range(n):
    for j in range(i+1, n):
        length = l[i] + l[j]

        index = bisect.bisect_left(l[j+1:], length)
        
        if index > 0:
            ans += index


print(ans)

Solution (Python):
import bisect
N = int(input())
L = list(map(int, input().split()))

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

print(ans)

Solution (Python):
from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for b in range(N):
    for a in range(b):
        ab = L[a] + L[b]
        r = bisect_left(L, ab)
        cnt += r - (b + 1) 
print(cnt)

Solution (Python):
from bisect import bisect_left
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
 
cnt = 0
 

for b in range(N):
    
    for a in range(b):
        ab = L[a] + L[b]
        
        r = bisect_left(L, ab)
        
        cnt += r - (b + 1)
 
print(cnt)

Solution (Python):
import bisect
N = int(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):
        b = bisect.bisect_left(L,L[i]+L[j])
        cnt += b-j-1
print(cnt)

Solution (Python):
import bisect

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

L.sort()

n = 0

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

print(n)

Solution (Python):
import  bisect
N=int(input())
L=list(map(int,input().split()))
L.sort()
tmp=0
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        tmp=bisect.bisect_left(L,L[i]+L[j])
        ans+=tmp-j-1

print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
N = int(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):
        ab = L[i]+L[j]
        r = bisect_left(L,ab)
        ans += r-(j+1)
print(ans)

Solution (Python):
from bisect import bisect_left
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(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):
            n = bisect_left(L, L[i] + L[j])
            ans += n - (j + 1)
    print(ans)


main()

Solution (Python):
import bisect
N = int(input())
l = list(map(int, input().split()))
ans = 0
tmp = 0
l.sort()
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        tmp = bisect.bisect_left(l, l[i] + l[j])
        ans += tmp - j - 1

print(ans)

Solution (Python):
import bisect

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

l.sort()

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

print(ans)

Solution (Python):
from bisect import bisect_left as bl
from bisect import bisect_right as br
n=int(input())
s=sorted(list(map(int,input().split())))
q=0
d=[[""]*(1001)for i in range(1001)]
for i in range(n):
    for j in range(i+1,n):
        x,y=max(s[i],s[j]),min(s[i],s[j])
        if d[x][y]=="":
            c=br(s,x+y-1)-bl(s,x-y+1)-1
            if x-y<y:
                c-=1
            c=max(c,0)
            d[x][y]=c
        q+=d[x][y]
print(q//3)

Solution (Python):
from bisect import bisect_left

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

L.sort()

cnt = 0


for b in range(N):
    
    for a in range(b):
        ab = L[a] + L[b]
        
        r = bisect_left(L, ab)
        
        cnt += r - (b + 1)

print(cnt)

Solution (Python):
from bisect import bisect_left

n = int(input())
l = sorted(list(map(int, input().split())))
answer = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        lij = l[i] + l[j]
        r = bisect_left(l, lij)
        answer += r - j - 1
        
print(answer)

Solution (Python):
from bisect import bisect_left

n = int(input())
l = sorted(list(map(int, input().split())))
answer = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        lij = l[i] + l[j]
        r = bisect_left(l, lij)
        answer += max(0, r - j - 1)
        
print(answer)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Solution (Python):
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(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()

Solution (Python):
from bisect import bisect_left

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

for b in range(N):
  for a in range(b):
    ab = L[a] + L[b]
    r = bisect_left(L, ab)
    l = b + 1
    
    ans += r-l

print(ans)