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-----
4
3 4 2 1

-----Sample Output-----
1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Difficulty: interview

Starter code:

Solutions:
def main():
	N = int(input())
	L = [int(l) for l in input().split(" ")]
	L.sort()
	m = len(L)
	cnt = 0
	for i in range(m):
		k = m - 1
		for j in range(i + 1, m):
			while m + i - j < k:
				if L[m + i - j] + L[i] <= L[k]:
					k -= 1
				else:
					cnt += k - m - i + j
					break
	print(cnt)

main()

import sys
from bisect import bisect_left

input = sys.stdin.readline


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):
            x = bisect_left(L, L[a] + L[b], lo=b)
            ans += (x - 1 - b)

    print(ans)


def __starting_point():
    main()

__starting_point()

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

for i in range(N-2):
    for j in range(i+1,N-1):
        num = L[i] + L[j]
        ind = bisect.bisect_right(L,num - 1)
        if ind > j - 1:
            ans += ind - j - 1
print(ans)

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

import bisect

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

import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
ans=0
for i in range(n-1,1,-1):
    for j in range(i-1,0,-1):
        t=bisect.bisect_right(a,a[i]-a[j])
        #print(a[i],a[j],a[i]-a[j],t,j-t)
        if j-t>0:
            ans+=j-t
print(ans)


from bisect import bisect_left

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

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


import bisect

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

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

print(count)

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

import itertools   # accumulate, compress, permutations(nPr), combinations(nCr)
import bisect      # bisect_left(insert位置), bisect_right(slice用)
# import math        # factorical（階乗) # hypot(距離)
# import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # Python3.6以降
# --------------------------------------------------------------

n  = int(input())
bo = list(map(int,input().split()))
 
cnt = 0
bo.sort()
 
for a in range(n-1):
    for b in range(a+1,n):
        cnt += bisect.bisect_left(bo, bo[a]+bo[b]) - (b+1)

print(cnt)

from bisect import bisect_left
N = int(input())
L_list = list(map(int, input().split()))
L_list.sort()

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        a, b = L_list[i], L_list[j]
        r = bisect_left(L_list, a+b)
        ans += max(0,r-j-1)
print(ans)


from bisect import bisect_left
n = int(input())
L = sorted(list(map(int, input().split())))

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        a, b = L[i], L[j]
        #c < a+b
        r = bisect_left(L, a+b)
        l = j+1
        cnt += max(0, r-l)
print(cnt)


from bisect import*
n, *l = map(int, open(0).read().split())
l.sort()
print(sum(max(0, bisect_left(l, l[i] + l[j]) - j - 1) for i in range(n) for j in range(i+1, n)))

import bisect
n=int(input())
lis=list(map(int, input().split())) 
lis.sort()
out=0
for i in range(n):
    for j in range(1+i,n):
        out+=bisect.bisect_left(lis,lis[i]+lis[j])-j-1
print(out)

from bisect import *
N=int(input())
*L,=tuple(sorted(map(int,input().split())))

r=0

for a in range(N):
 for b in range(a+1,N):
      x=L[a]
      y=L[b]
      r+=max(0,bisect_left(L,x+y)-(b+1))
print(r)

from bisect import *
N=int(input())
*L,=sorted(map(int,input().split()))

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

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]
        k = bisect_left(l, a+b)
        cnt += k-(j+1)
print(cnt)

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


from bisect import bisect_left

N = int(input())
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tmp = bisect_left(L,L[i]+L[j])
        cnt += tmp - j - 1

print(cnt)


#!/usr/bin/env python3
import sys


def solve(N: int, L: "List[int]"):
    from itertools import combinations
    from bisect import bisect_left as bl
    L = sorted(L)
    ans = 0
    for ai, a in enumerate(L):
        for bi, b in enumerate(L[ai+1:-1], ai+1):
            ci = bl(L, a+b)
            ans += ci - bi - 1
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print((solve(N, L)))

def test():
    import doctest
    doctest.testmod()

def __starting_point():
    #test()
    main()

__starting_point()

from bisect import *
n = int(input())
l = sorted(list(map(int, input().split())))
res = 0
for i in range(n-1):
    for j in range(i + 1, n):
        a, b = l[i], l[j]
        c_cnt = bisect_left(l, a + b) - j - 1
        res += c_cnt
print(res)


import sys
import bisect

input = sys.stdin.readline
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):
        l = L[i] + L[j]
        p = bisect.bisect_left(L, l)
        # print(p)
        ans += p - j - 1

print(ans)

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):
    sum = l[i] + l[j]
    index = bisect.bisect_left(l, sum)
    cnt += index - j - 1

print(cnt)

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    import bisect
    n = i_input()
    l = sorted(i_list())
    ans = 0
    for a in range(n-2):
        for b in range(a+1,n-1):
            ans += bisect.bisect(l, l[a]+l[b]-1) -b-1
    print(ans)

def __starting_point():
    main()

__starting_point()

#!/usr/bin/env python3

import bisect

def main():
  N = int(input())
  L = list(sorted(map(int,input().split())))
  res = 0
  for i in range(N-2):
    x = L[i]
    for j in range(i+1,N-1):
      y = L[j]
      res += bisect.bisect_left(L,x+y) - j - 1


  print(res)
  return

main()


import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=bisect.bisect_left(l,l[i]+l[j])-j-1
print(ans)

N=int(input())
L=list(map(int,input().split()))
ans=0
c=[0]*1001
for i in L:c[i]+=1
for i in range(1000):c[i+1]=c[i]+c[i+1]
for i in range(N-1):
    for j in range(i+1,N):
        l,r=abs(L[i]-L[j]),min(L[i]+L[j]-1,1000)
        ans+=c[r]-c[l]
        if l<L[i] and L[i]<=r:ans-=1
        if l<L[j] and L[j]<=r:ans-=1
print(ans//3)

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

cnt = 0

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

print(cnt)

import bisect
N = int(input())
L = list(map(int, input().split()))
count = 0

L.sort()

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

print(count)

n = int(input())
a_ls = list(map(int, input().split()))
def isOK(a,b,c):
    return abs(a-b) < c < a+b
a_ls.sort()
ans = 0
for i in range(n):
    short = a_ls[i]
    r = i+1
    num = 0
    for l in range(i+1,n-1):
        while r+1 < n and isOK(short, a_ls[l], a_ls[r+1]):
            r += 1
        num += r - l
        if l == r:
            r += 1
    ans += num
print(ans)

import bisect

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

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

import bisect


def main():
    n = int(input())
    l = sorted(list(int(i) for i in input().split()))

    cnt = 0

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

    print(cnt)


def __starting_point():
    main()

__starting_point()

import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for a in range(1, n-1):
    for b in range(a+1, n):
        ans += max(0, a-bisect.bisect(l, l[b]-l[a]))                                       
print(ans)

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):
        l1, l2 = l[i], l[j]
        ans += max(bisect.bisect_left(l, l1+l2)-j-1, 0)
print(ans)


from bisect import bisect_left

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

# 二分探索
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        a, b = L[i], L[j]
        # c < a + b
        r = bisect_left(L, a+b)
        l = j+1
        cnt += max(0, r-l)
print(cnt)

import bisect

def binary_search(items, a, b, i, j):
    def c_is_x(c):
        is1 = c > max(a - b, b - a)
        is2 = c < a + b

        if is1 and is2:
            return 0
        elif is1:
            return 1
        else:
            return 2

    low = j+1
    high = len(items) - 1

    while low <= high:
        mid = (low + high) // 2
        ans = items[mid]
        c_type = c_is_x(ans)
        if c_type == 0 and mid != i and mid != j:
            return mid
        elif c_type == 1:
            low = mid + 1
        else:
            high = mid - 1

    return None


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

L.sort()
# print(L)
count = 0
for i in range(N):
    for j in range(i+1, N):
        # i = N - i - 1
        # j = N - j - 1
        a = L[i]
        b = L[j]
        k = bisect.bisect_left(L, a+b, lo=j) - 1

        if k < N:
            c = L[k]
            # print(a, b, c, a+b)
            # print(i, j, k)
            count += max(k - j, 0)


print(count)




import bisect


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

    count = 0
    for i in range(n - 1):
        for j in range(i + 1, n):

            a = l_lst[i]
            b = l_lst[j]
            tmp = bisect.bisect_left(l_lst, a + b)
            tmp -= j + 1
            tmp = max(0, tmp)
            count += tmp

    print(count)


def __starting_point():
    main()
__starting_point()

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
L = readInts()
L = sorted(L)
# 1,2番目を特定する
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = L[i]
        b = L[j]
        c = bisect.bisect_left(L, a + b)
        ans += c - (j+1)
print(ans)


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):
        l1, l2 = l[i], l[j]
        ans += max(bisect.bisect_left(l, l1+l2)-j-1, 0)
print(ans)

from bisect import *
N=int(input())
*L,=sorted(map(int,input().split()))

r=0

for a in range(N):
 for b in range(a+1,N):
  x=L[a];y=L[b]
  r+=max(0,bisect_left(L,x+y)-(b+1))
print(r)

#それゆけにぶたんまん
#python3.8.2のTLEの壁に阻まれました←ぱいぱいまんに助けてもらった
#てかライブラリ使えばよくねver
from bisect import bisect_left
n = int(input())
l = sorted(list(map(int,input().split())))

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

print(ans)


import bisect

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

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



### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import bisect

def bin_search(arr,ls,c):
    l=ls-1
    r = len(arr)
    while (r-l) > 1:
        m = l + (r-l)//2
        if arr[m] >= c:
            r = m
        else:
            l = m
    return l-ls+1

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    arr.sort()
    ans=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            c = arr[i] + arr[j]
            ans += (bisect.bisect_left(arr,c,j+1) - j - 1)
            #ans += bin_search(arr,j+1,c)
    print(ans)
    return

if 'doTest' not in globals():
    resolve()
    return

### ----------------
### ここまで 
### ----------------


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


from bisect import bisect


from bisect import bisect_left

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

lis.sort()

cnt = 0
for i in range(n-2):
    a = lis[i]
    for j in range(i+1, n-1):
        b = lis[j]
        tmp = bisect_left(lis, a+b)
        
        cnt += tmp - 1 -j
    

print(cnt)

import bisect
from copy import deepcopy
N = int(input())
L = sorted(map(int, input().split()))

ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        b = L[j] + L[i]
        x = bisect.bisect_left(L, b) - j - 1
        if x > 0:
            ans += x

print(ans)


import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
cnt = 0
for i in range(n):
  for j in range(i+1, n):
    b = a[i] + a [j]
    x = bisect.bisect_left(a, b)   
    
    cnt += max(0, x-j-1)
print(cnt)


import bisect
def resolve():
    n = int(input())
    l = sorted(list(map(int,input().split())))
    ans = 0
    for a in range(n):
        for b in range(a+1,n):
            c = bisect.bisect_left(l,l[a]+l[b])
            if c > b:
                ans += c-b-1
            else:
                pass
    print(ans)
resolve()

from collections import deque
from bisect import bisect_left

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

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

from bisect import bisect_left
for i in range(n-2):
    for j in range(i+1,n-1):
        ab = l[i]+l[j]
        idx = bisect_left(l,ab)
        ans += max(0, idx-j-1)
print(ans)

#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(500000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    L = list(sorted(list(map(int, input().split()))))
    ans = 0
    for i in range(N):
        a = L[i]
        for j in range(i + 1, N):
            b = L[j]
            ans += bisect_left(L, a + b) - j - 1

    print(ans)


def main():
    solve()


def __starting_point():
    main()

__starting_point()

from bisect import bisect_left


def can_make_tri(a, b, c):
    return a < b + c and b < c + a and c < a + b


N, *L = list(map(int, open(0).read().split()))
L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        pos = bisect_left(L, L[i] + L[j], lo=j + 1)
        ans += pos - (j + 1)
print(ans)


n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
import bisect
for i in range(n-2):
    for j in range(i+1, n-1):
        ab = l[i]+l[j]
        idx = bisect.bisect_left(l, ab)
        ans += max(0, idx-j-1)
print(ans)

n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
  k=i
  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)

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):#二番目に短い棒
    #1+2番目の棒の長さより短く、2番目に短い棒より長い棒の範囲を探す
    ans += bisect_left(l,l[i]+l[j])-(j+1)
print(ans)

import sys, bisect

N = int(input())
L = list(map(int, sys.stdin.readline().rsplit()))
L.sort()

res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        a, b = L[i], L[j]
        c_l = bisect.bisect_left(L, a + b)
        
        if c_l <= j:
            continue
        
        # print(i, j, c_l)
        res += c_l - (j + 1)

print(res)



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 

n = int(input())
arr=[int(x) for x in input().split()]
print((findnumberofTriangles(arr)))



import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        x=bisect.bisect_left(l,l[i]+l[j])-j-1
        ans+=max(0,x)
print(ans)

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):
        k = l[i] + l[j]
        pos = bisect_left(l, k)
        ans += max(0, pos - j - 1)
print(ans)

# 小さいのを2つ選んで最後の1つをにぶたん
# なぜかTLEなる
from bisect import bisect_left
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        # ok, ng = j, n
        # while (ng - ok) > 1:
        #     mid = (ng + ok) // 2
        #     if l[i] + l[j] > l[mid]:
        #         ok = mid
        #     else:
        #         ng = mid
        # ans += ok - j
        # ↑とやってることは同じはずなんだけどなぜかTLEなるので組み込みのやつを使ってみる
        a = bisect_left(l, l[i] + l[j])
        ans += a - 1 - j
print(ans)


import bisect
n = int(input())
L = sorted(map(int, input().split()))
m = L[-1]
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        k = L[i] + L[j]
        ans += bisect.bisect_left(L, k) - j-1
print(ans)


from bisect import bisect_left,bisect

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

#n=7
#l=[218, 233, 389, 645, 704, 728, 786]

#print(l)
icnt=0
for a in range(n-2):
    for b in range(a+1,n-1):
        nc=bisect(l,l[a]+l[b]-1)
        if nc>b+1:
            icnt+=nc-(b+1)
#            print(a,b,nc,l[a],l[b],l[a]+l[b])
        
print(icnt)


import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            k = bisect.bisect_left(l, l[i]+l[j])
            res += max(k-(j+1), 0)
    print(res)
    return 0

def __starting_point():
    solve()
__starting_point()

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

from bisect import *

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


ans = 0
for i in range(n):
    for j in range(i + 1, n):
        k = bisect_right(L, L[i] + L[j] - 1)
        ans += k - j - 1
print(ans)

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


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

ans = 0
for i, a in enumerate(L[2:]):
    k = i + 1
    for j, b in enumerate(L[:i + 2]):
        while j < k and a - b < L[k]:
            k -= 1
        ans += i - max(k, j) + 1

print(ans)


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

n = int(input())
L = sorted(map(int,input().split()))
ans = 0

import bisect
#二分探索をするライブラリ

# c <= b <= a とする
# b < c + a と c < a + b　は自動で満たされる

for i in range(n-2):
    for j in range(i+1,n-1):
        a = L[n-1-i]
        b = L[n-1-j]
        
        c = a - b + 1
        # a < b + c を満たすｃの最小値
        
        if c <= b:
            ans += (n-1-j) - bisect.bisect_left(L,c)
        
print(ans)

n = int(input())
import bisect
a = sorted(list(map(int, input().split(" "))))
ans = 0
for i in range(1, n-1):
  b = a[:i]
  c = a[i + 1:]
  #print(b, c)
  for j in b:
    ans += bisect.bisect(c, a[i]+j-0.1)
    #print(bisect.bisect(c, a[i]+j-0.1))
print(ans)

import sys
from bisect import bisect_left

input = sys.stdin.readline


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):
            x = bisect_left(L, L[a] + L[b])
            ans += (x - 1 - b)

    print(ans)


def __starting_point():
    main()

__starting_point()

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

L = sorted(L)

import bisect

# 二本を決める
ans = 0
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    # L[i] + L[j] より短い棒で且つjより大きいインデックスを数える
    ind = bisect.bisect_left(L, L[i] + L[j])
    num = ind - (j + 1)
    ans += max(num, 0)
    
print(ans)

from bisect import bisect_left
n, *l = list(map(int, open(0).read().split()))
l.sort()

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


from bisect import *
N=int(input())
*L,=sorted(map(int,input().split()))

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

import bisect
from itertools import combinations

def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for l in combinations(L, 2):
        a = l[0]
        b = l[1]
        x = bisect.bisect_left(L, a + b)
        y = bisect.bisect(L, b - a)
        if b - a < a :
            ans += x - y - 2
        else:
            ans += x - y - 1
    print((ans // 3))


def __starting_point():
    main()

__starting_point()

from bisect import bisect_left
 
n = int(input())
l = sorted(list(map(int,input().split())))

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

print(ans)

from bisect import bisect_left

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

ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(arr, arr[small] + arr[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

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

@author: liang
"""

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

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)

import bisect


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


N = int(input())
L = LI()
L.sort()
ans = 0

for i in range(N-1, 1, -1):
    for j in range(i-1, 0, -1):
        xl = L[i]-L[j]
        ind = bisect.bisect_right(L, xl)
        if j > ind:
            ans += j-ind
print(ans)


from bisect import bisect_left
N = int(input())
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ind = bisect_left(L,L[i]+L[j])
        cnt += ind-j-1
print(cnt)

from bisect import *
N = int(input())
L = sorted(map(int,input().split()))
a = 0

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

import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n):
        k = i
        for j in range(i+1, n):
            while(k < n and l[k] < l[i]+l[j]):
                k += 1
            res += k - (j+1)
    print(res)
    return 0

def __starting_point():
    solve()
__starting_point()

def main():
    from collections import deque
    from bisect import bisect_left

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


def __starting_point():
    main()
__starting_point()

from bisect import bisect_left


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

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


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):
        c = L[i] + L[j]
        # a+bが入る場所を返す
        idx = bisect_left(L, c)
        ans += max(0, idx - (j + 1))

print(ans)


import bisect

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

l.sort()
ans = 0
for i in range(n-1):
    b = l[:i]
    c = l[i+1:]
    for j in b:
        ans += bisect.bisect_left(c, l[i] + j)#2番目の棒より短く(left), 一定以上の長さを持つ([i+1:])
print(ans)


import bisect
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):
        k=bisect.bisect_left(L,L[i]+L[j])
        ans+=k-j-1
print(ans)

from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    """
    lo=0
    hi=N
    x=a+b
    while lo<hi:
      mid=(lo+hi)//2
      if L[mid]<x: lo=mid+1
      else: hi=mid
    ans+=lo-(j+1) 
    """
    ans+=bisect_left(L,a+b)-(j+1)
print(ans)


import bisect

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

L_list_min = sorted(L_list)
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        #min = isect.bisect_left(L_list_min, L_list_min[j]+1)
        min = j+1
        max = bisect.bisect_left(L_list_min, L_list_min[i]+L_list_min[j])
        #print(i, j, max, min)
        if max - min >= 0:
            ans += max - min
        
print(ans)

import bisect
N=int(input())
arr=list(map(int,input().split()))

arr.sort()

ans=0

for i in range(N-2):
    for j in range(i+1,N-1):
        k=bisect.bisect_left(arr,arr[i]+arr[j])
        if k>j:
            ans+=k-j-1
        else:
            pass
print(ans)

n = int(input())
l_ls = list(map(int, input().split()))
l_ls.sort()
def check(a,b,c):
    return abs(a-b) < c < a+b
ans = 0
for i in range(n):
    short = l_ls[i]
    num = 0
    r = i+1
    for l in range(i+1,n):
        while r+1 < n and check(short, l_ls[l], l_ls[r+1]):
            r += 1
        num += r - l
        if r == l:
            r += 1
    ans += num
print(ans)
            


N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
max = l[N-1]
tc = N
st = [j+1 for j in range(N-1)]
for i in range(N-2):
    if l[i]+l[i+1] > max:
        k = N-i-1
        ans += ((k-1)*k*(k+1))//6
        break
    for j in range(i+1,N-1):
        if j == tc:
            ans += tp
            break
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > max:
            tc = j 
            tp = (N-j-1) * (N-j) //2 #これをiの中でできないか
            ans += tp
            break
        start = st[j]
        if s <= l[start]:
            ans += start-j-1
            continue
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        st[j] = end
        ans += end-j-1
print(ans)

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

from bisect import bisect_left
n, *l = list(map(int, open(0).read().split()))
l.sort()

print((sum(bisect_left(l, l[i] + l[j]) - 1 - j for i in range(n)
          for j in range(i + 1, n))))


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

import bisect


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


N = int(input())
L = LI()
L.sort()
ans = 0
for i in range(N-1, 1, -1):
    for j in range(i-1, 0, -1):
        ind = bisect.bisect_right(L, L[i]-L[j])
        if ind < j:
            ans += j-ind
print(ans)