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 subprocess
import gzip, base64, os
import stat

gz = b'H4sIADYDq10C/+19e3wURbZwz0wSJhAyA6KGhxI0KoiEDAmQEZWEZKBbJhBJeKyvZphMSHSSiTM9IVFQ2CRqO46yrneX3bsP7t67e929u/fu7rfrqnfFII+AL8AHqCjEBzpDRCMqBBXmO6eqetLdM52Fu/vd3/cHraTmnDpVdc6pU6dOVXdX3+dyzzebTJxymbkbOIT+ML6MwGUM/2AoSQK4Ui4b/k7kJnBZAGeq6Mq4Mk06wKpWUiujs8C/DPhXaqZwqblMk05gdEpqUqWZnPoq06QFt3OalOPyk+WQ1zebKPbNppWa1J5B8UXDtOXMrNwAKzfA6JWUM3OaVJEvg/2rZfhaJpeSVjK6ShU9XtVHpDr8nbeCwnkryjRpJ6Pr1JW7CcplcWd/2Vm6hLVnpJfJjH8lVfphur9x1ayS6f66af7G5nDbtLbSWdNmlRSGAoUzCE92Rrtg0VKNHvMYz2OYDWB+v1P853//4N6Ljv1y/2hXRfVzy0fV1WCek5XDLulqtjdkTMo2m7gSbj1UjXnXwb9y+PfHd4rfGL5ho/hT77M7HmlK7Hqwy3vR6zWbOx7+Ttnn0z4Xb8/Nby2a7HrD3X30yu4xm3Iqfjah5al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ioPOorapAP1FLHsgQhcUiefdfDId8dVTvoIEmb1pV1wd9vhQGcLTNJqOtvjE45HADcf0phoDMpWdN1A96YhCOIhGlgboC7S4Dg0DzdvoU71uypsEjuVrTuoliFeMGPmKwZQfYIutRf0qbtUKKKekNA8RTPCLTM7RnIEKNVOIFO0tFO5M2pZdIrAsFxAaYaUF5+JhQwJ92zKG3YyEU9VMBaoaKJ0pjjeCaQLZB00WjrcXAzFUzS6xeWFMs+vV+q8nX1BRoTbEW1NJgz+ilQz829EheFQqpLCIws94fDjWk9i1OtkU47ts8qxpbHTh0Q404MKE4ej2QtT4AOocS5fME0VFYrBtKGKCn9SLo3UD3okoGfSWD8hnVguPIqAaxBUSHAF2809fOPF9aP5U6zkHl3qaWNA6COR2QLW3nzvT6fR5YnEgQnwggP/yToFXd0PcF6vXmhKKQftJKQOZyMgbPYQol6yOdQPXkSJAUE9LOzWCLBhWnm5Znq6dl0pmtRsMdjKZG9DW1SO3gn1qgqUDQs9rnStefq8B/NYPHl7wNOlWQZ9dgDm9rE1t8wVAAPEcjVNhalGo25zg3gPdAmyA9thjm16ZAnS/NxJhGOjbDpTi6pc1r0Bku8YXCTVhVRQXgiyhzs9DsYeGcOrmAVmez4ZomwiluCUsubxomwNaqRLC7O8FjwcIgjSm3tA/2vKNEG/alztAYQ3DUr/1f9idL9qWbAAA='
bin = gzip.decompress(base64.b64decode(gz))
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
with open(pymain, "wb") as f:
    f.write(bin)
os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if p == "":
    pymain = "./" + pymain
subprocess.call(pymain)



'''

import numpy as np
i8 = np.int64
i4 = np.int32


def solve(L):
    ans = 0
    for n in range(L.shape[0] - 3):
        j = n + 2
        for i in range(n + 1, L.shape[0] - 2):
            while L[n] + L[i] > L[j] and j < L.shape[0]:
                j += 1
            ans += j - i - 1
    return ans


def main2():
    stdin = open('/dev/stdin')
    N = int(stdin.readline())
    L = np.empty(N + 1, i8)
    for i, c in enumerate(map(int, stdin.readline().split())):
        L[i] = c
    L[N] = 2000
    L = np.sort(L)
    ans = solve(L)
    print(ans)
'''

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


answer=0
for i in range(N-2):
  index_c=i+2
  for j in range(i+1,N-1):
    for k in range(index_c,N):
      if L[i]+L[j]<=L[k]:
        
        answer+=k-j-1
        index_c=k-1
        break
    else:
      
      answer+=N-j-1
      index_c=N-1
        
print(answer)

Solution (Python):
def solve(lengths):
    
    
    
    
    
    

    c_counts = {}
    lengths.sort(reverse=True)
    ans = 0
    for i in range(len(lengths)):
        for j in range(i + 1, len(lengths)):
            a, b = lengths[i], lengths[j]
            c_limit = (j, a - b)
            if c_limit in c_counts:
                ans += c_counts[c_limit]
                continue
            c_count = 0
            for k in range(j + 1, len(lengths)):
                c = lengths[k]
                if c > a - b:
                    c_count += 1
                else:
                    
                    break
            c_counts[c_limit] = c_count
            ans += c_count
    return ans


if __name__ == "__main__":
    n = int(input())
    l_s = [int(l) for l in input().split(' ')]
    print(solve(l_s))

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, L):
    L.sort()
    ans = 0
    for i, a in enumerate(L):
        for j in range(i+1, N):
            b = L[j]
            l = max(a-b, b-a)
            r = a+b
            x = bisect.bisect_left(L, l, lo=j+1)
            y = bisect.bisect_left(L, r, lo=j+1)
            ans += y - x
            if x <= j <= y:
                ans -= 1
            if x <= i <= y:
                ans -= 1

    return ans


def main():
    N = read_int()
    L = read_int_n()
    print(slv(N, L))

    
    
    


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 ia, a in enumerate(L):
    for ib, b in enumerate(L[ia+1:], ia):
        ans += bisect_left(L, a+b) - ib - 2

print(ans)

Solution (Python):
from sys import stdout
import bisect
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
l = inl()
acc = 0
l.sort()
for i in range(n-2):
  a = l[i]
  for j in range(i+1,n-1):
    b = l[j]
    e = bisect.bisect_left(l[j+1:],a+b)
    
    acc += e  
print(acc)

Solution (Python):
from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left
from bisect import insort
from bisect import insort_right
from bisect import insort_left

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


cnt = 0
for i in range(N):
  for j in range(i+1, N):
    s = L[i] + L[j]
    x = bisect_left(L, s)
    
    cnt += max(x - j - 1, 0)
print(cnt)

Solution (Python):
from bisect import bisect_left
n = int(input())
lst = list(map(int,input().split()))
ans = 0

lst.sort()

for i in range(n):
    for j in range(i+1,n):
        b,c = lst[i],lst[j]
        posr = bisect_left(lst,b+c)
        posl = max(j+1,bisect_left(lst,abs(b-c)))
        ans += (posr - posl)
print(ans)

Solution (Python):
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for ia, a in enumerate(L):
    for ib, b in enumerate(L[ia+1:], ia):
        ans += bisect_left(L, a+b) - ib - 2

print(ans)

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

L.sort()
'''
print(L)
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] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j]:
                print(i,j,k)
                '''
ans = 0

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


print(ans)

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

memo = [0]*1001
for x in range(1001):
    for i in arr:
        if i < x:
            memo[x] += 1

result = 0
for a in range(N):
    for b in range(a+1, N):
        aa = arr[a]
        bb = arr[b]
        if aa+bb > 1000:
            result += N-b-1
        else:
            result += memo[aa+bb]-b-1

print(result)

Solution (Python):
import bisect

n = int(input())
bar = [ int(v) for v in input().split() ]
bar.sort()

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

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

from bisect import bisect_left
def get_number_triangle(i, j, L):
    two_sum = L[i]+L[j]
    idx = bisect_left(L, two_sum)
    return idx - j - 1

ret = 0
for i in range(N):
    for j in range(i+1, N):
        ret += get_number_triangle(i, j, L)
print(ret)

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from bisect import bisect_left, bisect_right
n = getN()

nums = getList()
nums.sort()

ans = 0
for i, num1 in enumerate(nums):
    for j , num2 in enumerate(nums[i+1:]):
        tmp = num1 + num2
        idx_min = bisect_left(nums, tmp)
        idx_max = bisect_right(nums, num2 - num1)
        
        ans += idx_min - idx_max - 2
        if num2 >= num1 * 2:
            ans += 1










print(ans// 3)


"""
1 2 1  0
1 3 1  0
1 4 1  0
1 5 1  0
2 3 3  234 - 23 > 1 234
2 4 3  345 - 4 > 234, 245 
2 5 2  45 - 5 > 245
3 4 4  2345 - 34 > 234, 345
3 5 3  345 - 35 > 345 
4 5 4  2345 - 45 > 245, 345 
"""

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)

dp = defaultdict(lambda x:-1)

def main():
	n = int(input())
	l = list(map(int,input().split()))
	l.sort()
	ans = 0
	for mx in reversed(range(1,n)):
		for sc in reversed(range(1,mx)):
			tr_mx = l[mx] - l[sc] + 1
			tr = bisect.bisect_left(l,tr_mx)
			if(sc - tr > 0):
				ans += sc-tr
	print(ans)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Solution (Python):
import bisect

N = int(input())
Ls = list(map(int, input().strip().split()))

Ls.sort()

total = 0

for i in range(N):
	a = Ls[i]
	for j in range(i + 1, N):
		b = Ls[j]
		c_min = b - a + 1
		c_max = a + b - 1
		l = bisect.bisect_left(Ls, c_min, lo = j + 1)
		if l != N:
			r = bisect.bisect_right(Ls, c_max, lo = j + 1)
			if r:
				r = r - 1
				if r >= l:
					total += r - l + 1

print(total)

Solution (Python):
n = int(input())
a = sorted([int(x) for x in input().split()])
ret = 0
for i in range(n-1, 0, -1):
	l = 0
	r = i-1
	while l<r:
		if a[l]+a[r]>a[i]:
			ret += r - l
			r -= 1
		else:
			l += 1

print(ret)

Solution (Python):
import bisect

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


ans = 0

l.sort()

for x in range(n):
    for y in range(x+1, n):
        t = bisect.bisect_left(l, max(l[x] - l[y], l[y] - l[x])+1, y+1)
        
        t2 = bisect.bisect_left(l, l[x] + l[y], y+1)
        
        
        t3 = t2 - t
        if t3 > 0:
            ans += t3
print(ans)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict
import bisect



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


def main():
	N = int(input())
	L = getlist()
	L = sorted(L)
	ans = 0
	for i in range(N):
		for j in range(i + 1, N):
			x = L[i] + L[j]
			ans += bisect.bisect_left(L, x) - j - 1
	print(ans)


if __name__ == '__main__':
	main()

Solution (Python):
import bisect
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for k in range(N-2):
    for l in range(N-k-2):

        ans += min(N-k-l-2,N-bisect.bisect_left(L,L[-l-1]-L[k]+1)-l-1)
print(ans)

Solution (Python):
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
R = sorted(L)
ans = 0
diff = [L[i] - L[i+1] for i in range(N-1)]

for i in range(N):
    d = 0
    for j in range(i+1, N):
        d += diff[j-1]
        k = bisect.bisect_left(R, d+1)
        ans += max(N-k-1 - j, 0)

print(ans)