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())
Ln = list(map(int,input().split(' ')))
Ln.sort(reverse=True)

count = 0

def binary_area_search(target_list: list, target_item: int) -> int:
    '''
    @params
    target_list: [1,3,5](ACC)
    target_item: 2

    @return
    return index
    '''
    low = 0
    high = len(target_list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = target_list[mid]
        if guess > target_item:
            if mid == 0:
                return 0
            if target_item > target_list[mid-1]:
                return mid 
            high = mid -1
        else:
            if mid == len(target_list) - 1:
                return None
            if target_list[mid+1] > target_item:
                return mid + 1 
            low = mid + 1
    return None

for a in range(N):
    a_l = Ln[a]
    '''
    N^2*logN
    '''
    for b in range(a+1, N):
        num_b = N - b - 1
        flag = True
        b_l = Ln[b]
        c_threshold = a_l - b_l
        c_list = Ln[b+1:N]
        c_list.sort()
        c_idx = binary_area_search(c_list,c_threshold)
        if c_idx is not None:
            count += len(c_list) - c_idx
    '''
    N^2
    '''
    '''
    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
    '''
print(count)

Submission status: Time Limit Exceeded

Solution code:
def bs(x,l,r):
    ans=-1
    while l<=r:
        m=(l+r)//2
        if a[m]<x:
            l=m+1
        else:
            ans=m
            r=m-1
    return ans
  
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
t=(n*(n-1)*(n-2))//6
for i in range(n-1):
    for j in range(i+1,n):
        if j!=n-1:
            s=a[i]+a[j]
            k=bs(s,j+1,n-1)
            if k!=-1:
                t-=(n-k)
print(t)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
Lmat = [int(n) for n in input().split()]
Lmat.sort()

def binary_search_nearest(list, item):#もっとも近い値のindexをbsで探して返す関数
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return low-1

def iftriangle(first,second,third):
    if third < len(Lmat):
        if Lmat[first]>=Lmat[second]+Lmat[third]:
            return 0
        elif Lmat[second]>=Lmat[first]+Lmat[third]:
            return 0
        elif Lmat[third]>=Lmat[first]+Lmat[second]:
            return 0
        else:
            #print([first,second,third])
            return 1
    else:
        return 0

N2patern = list(itertools.combinations(range(N), 2)) #大小関係はこの時点で決まってしまう(小、大)のペアが出てくる

sum = 0
for patern in N2patern:
    #print("hoge")
    min_index = patern[1]
    max_index = binary_search_nearest(Lmat, Lmat[patern[0]]+Lmat[patern[1]])#これだとjustの値しか取得できない=>bs自体を実装する必要がある
    #print(binary_search_nearest(Lmat, Lmat[patern[0]]+Lmat[patern[1]]))#これだとjustの値しか取得できない=>bs自体を実装する必要がある)
    for Lk_index in range(min_index+1,max_index+1):
        sum += iftriangle(patern[0],patern[1],Lk_index)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def bs(x,l,r):
    ans=-1
    while l<=r:
        m=(l+r)//2
        if a[m]<x:
            l=m+1
        else:
            ans=m
            r=m-1
    return ans

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
t=(n*(n-1)*(n-2))//6
for i in range(n-1):
    for j in range(i+1,n):
        s=a[i]+a[j]
        k=bs(s,0,n-1)
        if k!=-1:
            t-=(n-k)
print(t)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    N = int(input())
    base_list=input().split()
    int_list=[]
    i = 0
    [int_list.append(int(i)) for i in base_list]
    int_list=sorted(int_list)
    anslist=list(itertools.combinations(int_list,3))
    ans=0
    for t in anslist:
        if t[0] < (t[1]+t[2]) and t[1] < (t[2]+t[0]) and t[2] < (t[0]+t[1]):
            ans+=1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int, input().split()))
l.sort()
count=0
for i in range(n-2):
	for j in range(i+1,n-1):
		k=j+1
		while k<n and l[k]<l[i]+l[j]: #whileでlist indexはみ出さないように注意
			count+=1
			k+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# import sys
# import bisect

# sys.setrecursionlimit(4100000)


# def inputs(num_of_input):
#     ins = [input() for i in range(num_of_input)]
#     return ins


def bis_insert(L, target, top=None, bottom=None):
    if top is None:
        top = len(L)
    if bottom is None:
        bottom = 0

    while bottom < top:
        half = (top + bottom) // 2
        if target > L[half]:
            bottom = half + 1
        else:
            top = half
    return bottom


def solve(inputs):
    L = string_to_int(inputs)
    L.sort()
    total_count = 0
    for i in range(len(L) - 2):
        for j in range(i + 1, len(L)-1):
            a = L[i]
            b = L[j]
            target = a + b
            r = bis_insert(L, target)
            # r = bisect.bisect_left(L, target)
            total_count += r - j - 1
    return total_count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(input())
    print(ret)

Submission status: Time Limit Exceeded

Solution code:
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 math
#import time
import random  # randome is not available at Codeforces
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')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
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(naive(a))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N=int(input())
L_list=[int(thing) for thing in input().split()]
L_list.sort(reverse=True)

ret=0
s_list=[]
def my_bisect(l:list,f,left_true=True):
    def bis(begin:int,end:int):
        # print("{}:{}".format(begin,end))
        if end-begin<=1:
            if f(l[end]) ==True:
                return end
            elif f(l[begin])==True:
                return begin
            else:
                return -1
        v=int((end+begin)/2//1)
        res=f(l[v])
        if res and left_true:
            return bis(v,end)
        elif not res and left_true:
            return bis(begin,v)
        elif res and not left_true:
            return bis(begin,v)
        elif not res and not left_true:
            return bis(v,end)
        else:
            print("what")
    return bis(0,len(l)-1)
for i in range(N):
    n=L_list[i]
    diff=0
    for j in range(i+1,N-1):
        k=L_list[j]
        m=n-k
        l=L_list[j+1:N]
        s=my_bisect(l,lambda x:x>m)+1
        s_list.append(s)
        if s==0:
            break
        else:diff=diff+s
    ret=ret+diff
print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def bis_insert(L, target, top=None, bottom=None):
    if top is None:
        top = len(L)
    if bottom is None:
        bottom = 0

    while bottom < top:
        half = (top + bottom) // 2
        if target > L[half]:
            bottom = half + 1
        else:
            top = half
    return bottom


def solve(inputs):
    L = string_to_int(inputs[0])
    L.sort()
    total_count = 0
    for i in range(len(L) - 2):
        for j in range(i + 1, len(L)-1):
            a = L[i]
            b = L[j]
            target = a + b
            r = bis_insert(L, target)
            total_count += r - j - 1
    return total_count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Time Limit Exceeded

Solution code:
length = 2010

n = int(input())
L = list(map(int, input().split()))
ans = 0
L.sort()
sum_1 = [ 0 for _ in range(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)

Submission status: Time Limit Exceeded

Solution code:
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
            current_min = N-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)

Submission status: Time Limit Exceeded

Solution code:
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)

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

li.sort()

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      cnt = bisect.bisect_left(li[a+1+b+1:], aa + bb)
      ans += cnt
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

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

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

Submission status: Time Limit Exceeded

Solution code:
from math import *

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):
        left = abs(arr[i]-arr[j])
        right = arr[i]+arr[j]
        k = j+1
        count = 0
        while(k<n and arr[k]>left and arr[k]<right):
            count+=1
            k+=1
        ans+=count
print(ans)

Submission status: Time Limit Exceeded

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

li.sort()

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      for c, cc in enumerate(li[a+1+b+1:]):
        if aa + bb <= cc:
          break
        else:
          ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

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

li.sort()

for a in range(n):
  if a < n - 2:
    for b in range(a+1, n-1, 1):
      for c in range(b+1, n, 1):
        if li[a] + li[b] <= li[c]:
          break
        if li[a] < li[b] + li[c] and li[b] < li[c] + li[a] and li[c] < li[a] + li[b]:
          ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

l.sort()

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

print(t)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

for a in range(len(L)-2):
    for b in range(a+1, len(L)-1):
        ans += bisect.bisect_left(L[b+1:], L[a]+L[b])
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 a in range(len(L)):
    for b in range(a+1, len(L)):
        ans += bisect.bisect_left(L[b+1:], L[a]+L[b])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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[j+1:], l[i] + l[j])

    print(result)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

li.sort(reverse=True)

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      for cc in li[a+1+b+1:]:
        if bb + cc <= aa:
          break
        if aa < bb + cc and bb < cc + aa and cc < aa + bb:
          ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import bisect
input = sys.stdin.readline


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

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

    print(result)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lengths=sorted([int(i) for i in input().split()])
import itertools as it
import math as ma

cnt=0
triangle=[list(i) for i in it.combinations(lengths,3)]

for i in range(len(triangle)):
    a=triangle[i].pop(0)
    b=triangle[i].pop(0)
    c=triangle[i].pop(0)
    if  ma.floor(b-a)<c<(b+a):
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for low in range(N-2):
    for mid in range(low+1,N-1):
        for hi in range(N-1,mid,-1):
            if L[hi] < L[low] + L[mid]:
                ans += (hi - mid)
                break
print(ans)

Submission status: Time Limit Exceeded

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

h.sort()
cnt = 0
ny = 0

z = 0
for x in range(n):
    for y in range(x+1,n):
        for z in range(y+1,n):
            if(h[x] < h[y]+h[z] and h[y] < h[x]+h[z] and h[z] < h[x]+h[y]):
                cnt += 1
            #print (x,y,z)        

print (cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for low in range(N-2):
    for mid in range(low+1,N-1):
        for hi in range(mid+1,N):
            if L[hi] < L[low] + L[mid]: ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
 
def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    # print(l)
    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 
            # print("start",s, e)
            while(True):
                mid = int((s + e) / 2)
                # print("S",s, e, mid)
                
                if s == e:
                    break
                else:
                    if second >= first + l[mid]:
                        if s == mid:
                            s = e
                        else:
                            s = mid
                    else:
                        e = mid
            # print(s)
            ans += j - s
            # print("ans", ans)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = sorted([int(item) for item in input().split(' ')])
count = 0
 
for i in range(N-2):
    for j in range(i+1, N-1):
        low = j + 1
        high = N - 1
        idx = (low + high + 1) // 2 
        for _ in range(10):
            if low == high:
                if not l[i] + l[j] > l[idx]:
                    idx -= 1
                break
            if l[i] + l[j] > l[idx]:
                low = idx
                idx = (low + high + 1) // 2
            else:
                high = idx - 1
                idx = (low + high + 1) // 2
        count += idx - j
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
l.sort()
s=0
for a in range(0,n-2):
    for b in range(a+1,n-1):
        c=b+1
        while l[c]<l[a]+l[b]:
            s=s+1
            c=c+1
            if c==n:
                break
print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(x) for x in input().split()]

c=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]:
        c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
# import os
# import sys
# from lib import pytime

# sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

n = int(input())
l = list(map(int,input().split()))
cnt = 0
rcnt = 0
tcnt = 0

# n * n-1 * n-2 / 2
# a < b + c
# b < a + c
# c < a + b

# start = pytime.pytime('start')

for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            s = l[i] + l[j] + l[k]
            if s - l[i] <= l[i] or s - l[j] <= l[j] or s - l[k] <= l[k]:
                pass
            else:
                cnt += 1
            
# pytime.pytime('end',start)
print(cnt)

Submission status: Time Limit Exceeded

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

tri = []
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                tri.append((L[i], L[j], L[k]))

print(len(set(tri)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
s=0
for a in range(0,n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if abs(l[a]-l[b])<l[c] and l[c]<l[a]+l[b]:
                s=s+1
print(s)

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): 
    ans += sum([1 for k in L[j+1:] if abs(L[j]-L[i]) < k < L[j]+L[i]])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(map(int, input().split()))
     
count = 0
for i in range(n-2):
    start_j = i + 1
    for j in range(start_j, n-1):
        start_k = j + 1
        for k in range(start_k, n):
            a = l_list[i]
            b = l_list[j]
            c = l_list[k]
               
            if (c<a+b and b<a+c and a<b+c):
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=sorted(list(map(int,input().split())),reverse=True)
L1 = []
cnt=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if (L[i] < L[j] + L[k])*(L[j] < L[i] + L[k])*(L[k] < L[i] + L[j]):
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=sorted(list(map(int,input().split())),reverse=True)
L1 = []
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if L[i] < L[j] + L[k]:
                L1.append([L[i],L[j],L[k]])
cnt=0
for i in range(len(L1)):
    if (L1[i][1] < L1[i][0]+L1[i][2])*(L1[i][2] < L1[i][0]+L1[i][1]):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

result = 0
for i in range(N-2) :
  for j in range(i+1,N-1) :
    for k in range(j+1,N) :
      if L[i] < L[j] + L[k] :
        result += 1

print(result)

Submission status: Time Limit Exceeded

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

l.sort()
l.reverse()

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        count = count + sum(k > l[i] - l[j] for k in l[j + 1 : n])

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

result = 0
for i in list(itertools.combinations(range(N),3)) :
  if L[i[0]] < L[i[1]] + L[i[2]] and L[i[1]] < L[i[0]] + L[i[2]] and L[i[2]] < L[i[1]] + L[i[0]] :
    result += 1

print(result)

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):
    for j in range(i+1, n):
        length = l[i] + l[j]

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
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)
        #print(index)
        if index > 0:
            ans += index


print(ans)

Submission status: Time Limit Exceeded

Solution code:
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):
        print()
        ab = L[a] + L[b]
        r = bisect_left(L, ab)
        cnt += r - (b + 1) 
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = input().split()
L = [int(i) for i in L ]
total = 0

L_sort = sorted(L)


def test(total):
	for i in range(N-2):
		for j in range(i+1,N - 1):
							temp_L = L_sort[j + 1:]
							
							#total += len(temp_L[temp_L < L_sort[i]+ L_sort[j]])
							temp_L = [k for k in temp_L if k < L_sort[i]+ L_sort[j]]
							total += len(temp_L)

	return total
						
				  	
print(test(total))

Submission status: Time Limit Exceeded

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

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

        l = j+1
        r = n-1
        m = (l + r) // 2

        while True:
            if l > r:
                #m = -1
                break
            m = (l + r) // 2
            if L[m] < length:
                l = m + 1
            else:
                r = m - 1

#        print(i, j, m)
        if m+1 < n and L[m+1] < length:
#            print('increment!')
            m += 1
        if L[m] >= length and L[m-1] < length:
            m -= 1
#            print('decrement!')
        if L[m] < length:
            #print('count up: ' + str(m - j) + '\n')
            ans += m - j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Triangles
from bisect import bisect_left
import numpy as np
N = int(input())
L = sorted(np.array(list(map(int, input().split()))))

ans = 0
for i, a in enumerate(L):
    if i == N - 2:
        break
        
    for j, b in enumerate(L[i + 1:]):
        j += i + 1
        if j == N - 1:
            break
            
        s = a + b
        ans += bisect_left(L[j + 1:], s)
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Triangles
import numpy as np
N = int(input())
L = sorted(np.array(list(map(int, input().split()))))

ans = 0
for i, a in enumerate(L):
    if i == N - 2:
        break
        
    for j, b in enumerate(L[i + 1:]):
        j += i + 1
        if j == N - 1:
            break
            
        s = a + b
        ans += np.count_nonzero(L[j + 1: ] < s)
                
print(ans)

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):
    for k in range(N-1,j,-1):
      if L[i] + L[j] > L[k]:
        ans += k-j
        break
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):
    for j in range(i+1, N):
        lower_bound = bisect.bisect_left(L, L[i]+L[j])
        for k in range(lower_bound):
            if k == i or k == j:
                continue
            if L[i]+L[j] > L[k] and L[i]+L[k] > L[j] and L[j]+L[k] > L[i]:
                ans += 1
        # print(L[i], L[j])
        # print(bisect.bisect_left(L, L[i]+L[j])-2)
        # ans += max(bisect.bisect_left(L, L[i]+L[j])-2, 0)
print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
# D - Triangles
N = int(input())
L = sorted(list(map(int, input().split())))

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

Submission status: Time Limit Exceeded

Solution code:
# D - Triangles
N = int(input())
L = sorted(list(map(int, input().split())))

ans = []
for i, a in enumerate(L):
    if i == N - 2:
        break
        
    for j, b in enumerate(L[i + 1:]):
        j += i + 1
        if j == N - 1:
            break
            
        s = a + b
        for k, c in enumerate(L[j + 1:]):
            k += j + 1
            if c < a + b:
                ans.append((a, b, c))
            else:
                break
                
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

L.sort()

n = 0

# Choose two edges
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)
        #   assert all(v < a for v in L[:k]) and all(v >= a for v in L[k:])
        # the number of candidates of the third edge
        n += k - (j + 1)

print(n)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
leng = [int(i) for i in input().split()]
leng.sort(reverse=True)
cnt = 0

for i, a in enumerate(leng[:-2]):
    for j, b in enumerate(leng[i+1:-1], i+1):
        for k, c in enumerate(leng[j+1:], j+1):
            if a < b+c and b < a+c and c < a+b:
                cnt += 1
            else:
                break

print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
cnt = 0

for i, a in enumerate(l[:-2]):
    for j, b in enumerate(l[i+1:-1], i+1):
        for k, c in enumerate(l[j+1:], j+1):
            if a < b+c and b < a+c and c < a+b:
                cnt += 1

print(cnt)