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



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ns = list(map(int, input().split()))
ns = sorted(ns)
rslt = 0
for i in range(n):
    for j in range(i+1, n):
        a = ns[i]+ns[j]
        b = abs(ns[i]-ns[j])
        for k in range(j+1, n):
            if ns[k] < a and ns[k] > b:
                rslt += 1
            elif ns[k] >= a:
                break
print(rslt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l = list(map(int, input().split()))
p = list(itertools.combinations(l,3))
def triangle(a, b, c):
    if a < b + c and b < c + a and c < a + b:
        return True
    else:
        return False
ans = 0
for i in p:
    if triangle(i[0], i[1], i[2]):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
Ls = list(map(int, input().split()))

sls = sorted(Ls)
count = 0
for i in range(N - 1):
    for j in range(i+1, N):
        cs = sls[j + 1:]
        a, b = sls[i], sls[j]
        count += bisect.bisect_left(cs, b + a)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
Ls = list(map(int, input().split()))
 
sls = sorted(Ls)
count = 0
for i, a in enumerate(sls):
    for j, b in enumerate(sls[i+1:]):
        cs = sls[i+j+2:]
        cmin, cmax = b - a, b + a
        left, right = bisect.bisect_right(cs, cmin), bisect.bisect_left(cs, cmax)
        count += (right - left)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l = list(map(int, input().split()))
counter = 0
for v in itertools.combinations(l, 3):
     if 2 * max(v) < sum(v):
         counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
l = list(map(int, input().split()))
l=sorted(l)
ans=0
for i in range(n):
  for k in range(i+1,n):
    for _ in range(k+1,n):
      if -l[i]+l[k]>=l[_]:
        continue
      elif l[i]+l[k]<=l[_]:
        break
      else:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

y=list(itertools.combinations(x,3))
z=len(y)

count=0
for i in range(0,z):
  if y[i][0]<y[i][1]+y[i][2] and y[i][1]<y[i][0]+y[i][2] and y[i][2]<y[i][0]+y[i][1]:
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())

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

listarray = itertools.combinations(L,3)
count = 0

for items in listarray:
  a = items[0]
  b = items[1]
  c = items[2]
  if a < b + c and b < c + a and c < a + b:
    count +=1

print(count)

Submission status: Time Limit Exceeded

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

def check(x, a):
    if a < x:
        return True
    else:
        return False

def bin_search(x, ok, ng, l):
    while ng - ok > 1:
        mid = (ng + ok) // 2
        if check(x, l[mid]):
            ok = mid
        else:
            ng = mid
    return ok + 1

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
def binary_search(S,key): 
    left  = 0
    right = N
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return mid
d = 0
A.sort()
for i in range(N-1):
    for j in range(i+1,N):
        s = A[i]+A[j]
        dex = binary_search(A,s)
        while A[dex] >= s :
            dex -= 1
        d = d + dex - j
print(d)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
l=list(map(int,input().split()))


def triangle(num):
    a,b,c=num
    if a<(b+c) and b<(a+c) and c<(a+b):
        return True
    else:
        return False
ans=0
for num in itertools.combinations(l,3):
    ans+=triangle(num)
print(ans)

Submission status: Time Limit Exceeded

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


def triangle(num):
    a,b,c=num
    if a<(b+c) and b<(a+c) and c<(a+b):
        return True
    else:
        return False
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            num=[l[i],l[j],l[k]]
            ans+=triangle(num)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
import itertools
A = list(itertools.combinations(L,3))
ans = 0
for a in A:
    ok = True
    if a[0] >= a[1]+a[2]:
        ok = False
    if a[1] >= a[0]+a[2]:
        ok = False
    if a[2] >= a[0]+a[1]:
        ok = False
    if ok:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

def main():
    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):
            k = bisect_left(L[j+1:], a + L[j])
            ans += k

    print(ans)

    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

    L = sorted(L)
    ans = 0
    comb = [p for p in combinations(L, 3)]
    for a, b, c in comb:
        if c < a + b:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))

cnt=0
n=ri()
lu=rli()
lu.sort()
if n<=2:
  print(0)
else:
  for i in range(n-2):
    for j in range(i+1,n-1):
      r=n
      l=j
      if lu[-1]<lu[i]+lu[j]:
        cnt+=n-1-j
        continue
      if lu[j+1]>lu[j]+lu[i]:
        continue
      
      while r-l>1 :
        mid=(r+l)//2
        if lu[i]+lu[j]>lu[mid]:
          l=mid
        else:
          r=mid
      cnt+=l-j
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(map(str, input().split()))
def pl(a): print(" ".join(list(map(str, a))))
def ma():return map(int,input().split())
from itertools import accumulate as acc
import operator as op
import copy as cp
import math 


cnt=0
n=ri()
lu=rli()
lu.sort()
if n<=2:
  print(0)
else:
  for i in range(n-2):
    for j in range(i+1,n-1):
      r=n
      l=j
      
      while r-l>1 :
        mid=(r+l)//2
        if lu[i]+lu[j]>lu[mid]:
          l=mid
        else:
          r=mid
      cnt+=l-j
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        left = j+1
        right = N-1
        while a+b <= L[right]:
            if right==j:
                break
            right-=1
        ans += right - left + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
while len(l) >= 3:
  max_l = l.pop()
  for i in range(1, len(l)):
    rest_l = max_l - l[i]
    inf = -1
    sup = i
    while sup - inf > 1:
      x = (inf + sup) // 2
      if l[x] > rest_l:
        sup = x
      else:
        inf = x
    triangle += i - sup
print(triangle)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l = sorted(l, reverse=True)
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        cnt=1
        
        while True:
            k=j+cnt
            if n<=k or l[i]>=l[j]+l[k] or l[j]>=l[i]+l[k] or l[k]>=l[i]+l[j]:
                cnt-=1
                
                break
            
            cnt+=1
        ans+=cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N=int(input())
L=sorted(map(int,input().split()))
cnt=0
for i in range(N):
    for j in range(i):
        a=L[i]
        b=L[j]
        right=a+b
        left=abs(a-b)
        res=bisect.bisect_left(L,right)-bisect.bisect_right(L,left)
        if(left<a<right):
            res-=1
        if(left<b<right):
            res-=1
        cnt+=res
print(cnt//3)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

N = int(sys.stdin.readline())
L = np.array(list(map(int, sys.stdin.readline().split())))
L = np.sort(L)

count = 0

for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        c_cand = L[j + 1:]
        c_num = np.count_nonzero(c_cand < a + b)
        count += c_num
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

N = int(input())
L = np.array(list(map(int, sys.stdin.readline().split())))
L = np.sort(L)

count = 0

for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        c_cand = L[j + 1:]
        c_num = np.count_nonzero((c_cand < a + b) & (a < b + c_cand) & (b < a + c_cand))
        count += c_num
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

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

c_list = list(itertools.combinations(L, 3))
count = 0

for v in c_list:
    if v[0] < v[1] + v[2] and v[1] < v[0] + v[2] and v[2] < v[0] + v[1]:
        count += 1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import numpy as np
n = int(input())
l_list = list(map(int,input().split()))
l_list = np.sort(l_list)
ans = 0
for i in range(n-2):
    for j in range(i+1 , n-1):
        ans += bisect.bisect_left(l_list,l_list[i] + l_list[j]) -j -1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import numpy as np
n = int(input())
l_list = list(map(int,input().split()))
l_list = np.sort(l_list)
ans = 0
for i in range(n):
    for j in range(i+1 , n):
        ans += bisect.bisect_left(l_list,l_list[i] + l_list[j]) -j -1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
total = 0
def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok


for i in range(N):
  for j in range(i + 1, N):
    a = L[i] - L[j]
    total += max(bisect_left_reverse(L, a) - j - 1, 0)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)

comb=itertools.combinations(L,2)
comb=list(comb)
total=0
for c in comb:
    s = c[0] - c[1]
    for l in L:
        if(l > s and c[1] > l):
            total+=1
print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
total=0
large=L.pop(0)
def func(lst, value):
   tmp = [i for i, x in enumerate(lst) if x > value]
   return len(tmp)


while L != []:
    for n,i in enumerate(L[:]):
        s = large - i
        length=func(L[n+1:],s)
        if(length==0):
            large=L.pop(0)
            break
        else:
            total+=length
    
print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=list(map(int,input().split()))

p=itertools.combinations(L,3)
total=0
for e in p:
    a=e[0]
    b=e[1]
    c=e[2]
    if(a < b + c and b < c + a and c < a + b):
        total+=1
print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=list(map(int,input().split()))

p=itertools.permutations(L,3)
total=0
for e in p:
    a=e[0]
    b=e[1]
    c=e[2]
    if(a < b + c and b <c + a and c < a + b):
        total+=1
print(total//6)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
ans = 0
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]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
#def LI(): return list(map(int, input().split())
n=I()
bls=list(MI())
ls=sorted(bls, reverse=True)
trans=0
for i in range(n-2):
    answer=0
    for j in range(i+1,n-1):
        l1=ls[i]
        l2=ls[j]
        l,r = j,n
#あえて左右一つ分ずつ広く取る
        while l+1 < r:
#この条件で探索の終点がうまく定められる
            mid = (l+r)//2
            if l1<l2+ls[mid]:
                l = mid
            else:
                r = mid
        ansij=l-j
        #print(ansij)
        answer+=ansij
    trans+=answer
print(trans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort()
ans=int(0)
for i in range(n-2):
    for j in range(i+1,n-1):
        now=A[i]+A[j]
        l=int(j+1)
        r=int(n)
        while r-l>=1:
            x=int((r+l)/2)
            if A[x]<now:
                l=x+1
            else:
                r=x
        ans+=r-j-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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):
    small = bisect.bisect_left(L, L[j]-L[i])
    large = bisect.bisect_left(L, L[j]+L[i])
    
    #print(i,j,L[i],L[j],"  ",L[j]-L[i],L[j]+L[i],small,large)
    ans += max(large-j-1,0)    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
pairs = []
for i in range(n):
    for j in range(i + 1, n):
        pairs.append((i, j))

ans = 0
for i, j in pairs:
    p = L[:i] + L[i + 1:j] + L[j + 1:]
    a, b = L[i], L[j]
    l = bisect_left(p, b - a + 1)
    r = bisect_left(p, a)
    if l < r:
        ans += (r - l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
List = list(map(int, input().split()))

List.sort()

counter = 0

for i in range(0, n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if List[i] + List[j] > List[k]:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#D
n = int(input())
l = list(map(int,input().split()))
cnt = 0
l.sort(reverse=True)



for i in range(len(l)-2):
    for j in range(i+1,len(l)-1):
        x = l[i]-l[j]
        right = n-1
        left = j
 
        while left <= right:
            mid = (right + left) //2
            if l[mid] == x:
                mid -= 1
                break
                
        
            elif l[mid] > x:
                left = mid+1
            elif l[mid] < x:
                right = mid-1
        if (mid - j) > 0:
            cnt += mid - j
 
        
print(cnt)

Submission status: Time Limit Exceeded

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

def binary_search_left(list,target):
    '''
    配列に対してある数nを配列のソート順を崩さないように挿入するためのindexを返す関数。
    同一の数が配列に複数含まれていた場合は最も小さいindexを返す。
    '''
    result = -1
    left = 0
    right = len(list) - 1

    while left <= right:
        center = (left + right)//2
        if list[center] == target:          # 一致した場合
            if list[center - 1] == target:  # -> その一つ前も一致した場合、rightをcenterにしてもう一周
                right = center
            else:                           # -> その一つ前は一致しない場合、一番左で一致したということでcenterを返す
                return center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1
    return left                             # 一致したらcenterを返すが（上記）、なければleftのインデックスを返す

L_list = sorted(L_list)

ans = 0
for a_index in range(0, N-2):
    for b_index in range(a_index+1, N-1):
        a = L_list[a_index]
        b = L_list[b_index]
        c_right_index = binary_search_left(L_list, a+b)
        if c_right_index > b_index:
            ans += c_right_index - b_index - 1
        else:
            pass

print(ans)

Submission status: Time Limit Exceeded

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

def binary_search_left(list,target):
    '''
    配列に対してある数nを配列のソート順を崩さないように挿入するためのindexを返す関数。
    同一の数が配列に複数含まれていた場合は最も小さいindexを返す。
    '''
    result = -1
    left = 0
    right = len(list) - 1

    while left <= right:
        center = (left + right)//2
        if list[center] == target:          # 一致した場合
            if list[center - 1] == target:  # -> その一つ前も一致した場合、rightをcenterにしてもう一周
                right = center
            else:                           # -> その一つ前は一致しない場合、一番左で一致したということでcenterを返す
                return center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1
    return left                             # 一致したらcenterを返すが（上記）、なければleftのインデックスを返す

L_list = sorted(L_list)

ans = 0
for a_index in range(0, N):
    for b_index in range(a_index+1, N):
        a = L_list[a_index]
        b = L_list[b_index]
        c_right_index = binary_search_left(L_list, a+b)
        if c_right_index > b_index:
            ans += c_right_index - b_index - 1
        else:
            pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    for j in range(i,n-1):
        for k in range(j,n):
            if i != j != k and l[i] < l[j]+l[k] and l[j] < l[i]+l[k] and l[k] < l[i]+l[j]:
                cnt += 1
                
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=list(map(int,input().split()))
cmlist=list(itertools.combinations(L,3))
ans=0
for i in cmlist:
  i=sorted(i)
  if i[2]<i[1]+i[0]:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=list(map(int,input().split()))
cmlist=list(itertools.combinations(L,3))
ans=0
for i in cmlist:
  for j in i:
    if j>=sum(i)-j:
      ans+=1
print(len(cmlist)-ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = [int(i) for i in input().split()]
count = 0
l_new = sorted(l)
for i in range(N-2):
    for j in range(i+1,N-1):
        k = j+1
        while k < N and l_new[i] + l_new[j] > l_new[k]:
            k += 1
        count += max(k-(j+1),0)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(1,N-1):
  for j in range(i+1, N):
    a = l[:-j]
    L = len(a)
    if l[-j] - (l[-i]-1) < (l[-i] + 1) - l[-j]: m = (l[-i]+1) - l[-j]
    else : m = l[-j]-(l[-i]-1)
    n = bisect.bisect_left(a, m)
    ans += (L - n)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

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

    cnt=0
    for i in combinations(L,3):
        if sum(i)-2*i[0]>0 and sum(i) - 2 * i[1] > 0 and sum(i)-2*i[2]>0:
            cnt+=1
            
    print(cnt)

resolve()

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(1,N-1):
  for j in range(i+1, N):
    a = l[:-j]
    L = len(a)
    Min = l[-j]-(l[-i]-1)
    Max = (l[-i]+1) - l[-j]
    n = max(bisect.bisect_left(a, Min), bisect.bisect_left(a, Max))
    ans += (L - n)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = [int(i) for i in input().split()]
count = 0
l_new = sorted(l,reverse=True)
for i in range(N-2):
    for j in range(i+1,N-1):
        for c in range(j+1,N):
            if l_new[i] >= l_new[j] + l_new[c]:
                break
            else:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
l = [int(i) for i in input().split()]
count = 0
for v in itertools.combinations(l,3):
    if max(v[0],v[1],v[2])*2 < sum(v):
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
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):
        for k in range(j + 1 ,N):
            a = L[i]
            b = L[j]
            c = L[k]
            if a < b + c and b < a + c and c < a + b:
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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):
        for k in range(j + 1 ,N):
            a = L[i]
            b = L[j]
            c = L[k]
            if a < b + c and b < a + c and c < a + b:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    a = l[j+1:]
    for x in range(len(a)):
      if l[i] < l[j] + a[x] and abs(l[j] - a[x]) < l[i]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
d = int(input())
d = list(map(int,input().split()))
n = 3
ans = 0
for i in itertools.combinations(d,n):
    if i[0] < i[1]+i[2] and i[1] < i[0]+i[2] and i[2] < i[1]+i[0]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
l = [int(i) for i in input().split()]
count = 0
for v in itertools.combinations(l,3):
    if v[0] < v[1] + v[2]:
        if v[1] < v[0] + v[2]:
            if v[2] < v[1] + v[0]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right, bisect_left

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

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i + 1:], start=i + 1):
        left = bisect_right(L, abs(a - b))
        right = bisect_left(L, a + b)
        ans += right - left

        if left <= i < right:
            ans -= 1
        if left <= j < right:
            ans -= 1

print(ans // 3)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    L = [int(i) for i in input().split()]
    L.sort()
    # from bisect import bisect_left
    ans = 0
    for i in range(2, N):
        # i番目を最長辺とする
        for j in range(i):
            for k in range(j+1, i):
                if L[j]+L[k] > L[i]:
                    ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
l = [int(i) for i in input().split()]
count = 0
for v in itertools.permutations(l,3):
    if v[0] < v[1] + v[2]:
        if v[1] < v[0] + v[2]:
            if v[2] < v[1] + v[0]:
                count += 1
print(count//6)

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    l = LI()
    l.sort()
    ans = 0
    s = []
    for i in range(n):
        ans += len(s)-bisect.bisect_right(s,l[i])
        for j in range(i):
            s.append(l[i]+l[j])
        s.sort()
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
l.append(0)
c = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    z = l[i]-l[j]
    if l[j+1] <= z:
      break
    else:
      a = j+1
      b = n+1
      while a+1 < b:
        m = (a+b)//2
        if l[m] > z:
          a = m
        else:
          b = m
      c += a-j
print(c)

Submission status: Time Limit Exceeded

Solution code:
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):
        a = L[i]
        b = L[j]
        ok = j
        ng = N-1
        if b-a < L[ng] and L[ng] < a+b:
            ans += N-1-j
        else:
            while ng - ok > 1:
                mid = (ok+ng) // 2
                if b-a < L[mid] and L[mid] < a+b:
                    ok = mid
                else:
                    ng = mid
       
            ans += ok - j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

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

zzz = list(itertools.combinations(l,3))

cnt = 0

for z in zzz:
    
    a = z[0]
    b = z[1]
    c = z[2]

    if abs(b-c) < a < b+c:
         cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

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

zzz = list(itertools.combinations(l,3))

cnt = 0

for z in zzz:
    
    a = z[0]
    b = z[1]
    c = z[2]

    if a >= b + c:
        continue

    if b >= c + a:
        continue

    if c >= a + b:
        continue

    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n =int(input())
l = [ int(i) for i in input().split()]
list.sort(l)
count=0
for a in range(len(l)-2):
    for b in range(a+1,len(l)-1):
        for c in range(b+1, len(l)): 
#             print("a=={}, b=={}, c=={}".format(a,b,c))
#             print("a=={}, b=={}, c=={}".format(l[a], l[b], l[c]))
            if l[c]<l[a]+l[b]:
#                 print("count")
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
ans = 0
for a in range(N-2):
  for b in range(a+1,N-1):
    Lc = L[b+1::]
    ans  += len([lc for lc in Lc if (abs(L[a]-L[b]) < lc) and (lc < L[a]+L[b])])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
ans = 0
for a in range(N-2):
  for b in range(a+1,N-1):
    for c in range(b+1,N):
      if (L[a] < L[b] + L[c])and (L[b] < L[c] + L[a])and(L[c] < L[a] + L[b]):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
L = sorted(list(map(int, input().split())))
i = n - 1
count = 0
for a in L[::-1]:
    j = 1
    for b in L[:i-1]:
        k = j
        for c in L[j:i]:
            if a < b + c:
                count += (i-k)
                break
            k += 1
        j += 1
    i -= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
L = sorted(list(map(int, input().split())))
i = n - 1
count = 0
for a in L[::-1]:
    j = 1
    for b in L[:i-1]:
        for c in L[j:i]:
            if a < b + c:
                count += 1
        j += 1
    i -= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      A = L[i] + L[j] + L[k]
      if(max(L[i],  L[j],  L[k]) < (A - max(L[i],  L[j],  L[k]))):
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int, input().split()))
ans = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if max(L[i], L[j], L[k]) < L[i] + L[j] + L[k] - max(L[i], L[j], L[k]):
                ans = ans + 1

print(ans)