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())
list = input().split()
L = [int(n) for n in list]
L.sort()
sum = 0
for i in range(N):
  for j in range(N):
    if i > j:
      a = L[i]
      b = L[j]
      if a < 2 * b:
        for k in range(N):
          if j > k: 
            c = L[k]
            if (a<b+c) & (b<c+a) :
              sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
array = list(map(int, input().split()))
array.sort()
ans = 0
# print(array)
for i in range(N):
    for k in range(i+1,N):
        for j in range(k+1,N):
            if (array[i] < array[k] + array[j]) and (array[j] < array[i] + array[k]) and (array[k] < array[i] + array[j]):
                ans += 1
                # print(array[i],array[k],array[j])
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
L.sort(reverse = True)
M = 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]:
        M += 1
print(M)

Submission status: Time Limit Exceeded

Solution code:

from sys import stdin
import itertools

n = int(stdin.readline().rstrip())
ls = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
for v in itertools.combinations(ls, 3):
    a,b,c = [int(i) for i in v]
    if a<b+c and b<c+a and c<a+b:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

from bisect import bisect_left, bisect_right

kumi = set()
for i in range(N):
    a = l[i]
    for j in range(i, N):
        if i == j:
            continue
        b = l[j]
        start = bisect_right(l, max(a,b)-min(a,b))
        end = bisect_left(l, a+b)
        for c in l[start:end]:
            if c == a or c == b:
                continue
            kumi.add(tuple(sorted([a,b,c])))
print(len(kumi))

Submission status: Time Limit Exceeded

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

res = 0

for i in range(N-2):
    L1 = L[i+1:]
    a = L[i]
    for j in range(len(L1)-1):
        L2 = L1[j+1:]
        b = L1[j]
        temp1 = max(L2)
        temp2 = min(L2)
        if temp2 >= a + b:
            break
        elif temp1 <= a - b:
            break
        elif temp1 <= b - a:
            break
        LS2 = list(set(L2))
        M2 = len(LS2)
        for k in range(M2):
            c = LS2[k]
            sum = a + b + c
            if (sum > 2*a) & (sum > 2*b) & (sum > 2*c):
                res += L2.count(c)

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import itertools
C = [x for x in range(N)]

def check(c):
  if L[c[0]] >= L[c[1]]+L[c[2]]:return 0
  if L[c[1]] >= L[c[0]]+L[c[2]]:return 0
  if L[c[2]] >= L[c[1]]+L[c[0]]:return 0
  return 1

ans = sum([check(c) for c in list(itertools.combinations(C,3))])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
N=int(input())
L=[int(i) for i in input().split()]
L.sort(reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
L= np.array(list(map(int,input().split())))
ret=0
for i,l in enumerate(L):
  for j,m in enumerate(L[i+1:]):
    LL=np.delete(L,[i,i+j+1])
    #print(LL[np.logical_and(LL> abs(l-m),LL< abs(l+m))])
    ret+=np.count_nonzero(np.logical_and(LL> abs(l-m),LL< abs(l+m)))
print(ret//3)

Submission status: Time Limit Exceeded

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

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

for i in range(0, N-2):
       for k in range(i+1, N-1):
            for l in range(k+1, N):
                if A[i]+A[k] > A[l]:
                    ans +=  1
                elif A[i]+A[k] <= A[l]:                  
                    break
print(ans)

Submission status: Time Limit Exceeded

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

def nibunki_left(L, s, f, p):
	cent = (f-s)//2 + s
	if s == f:
		return s
	elif s+1 == f:
		if L[s] > p:
			return s
		else:
			return f

	if L[cent] <= p:
		return nibunki_left(L, cent, f, p)
	else:
		return nibunki_left(L, s, cent, p)

def nibunki_right(L, s, f, p):
	cent = (f-s)//2 + s
	if s == f:
		return f
	elif s+1 == f:
		if L[f] < p:
			return f
		else:
			return s

	if L[cent] < p:
		return nibunki_right(L, cent, f, p)
	else:
		return nibunki_right(L, s, cent, p)



ans = 0

for a in range(N-2):
	for b in range(a+1, N-1):
		l = max(L[a] - L[b], L[b] - L[a])
		r = L[a] + L[b]

		l_ind = nibunki_left(L, 0, N-1, l)
		r_ind = nibunki_right(L, 0, N-1, r)

		if l_ind <= b and r_ind <= b:
			continue
		elif l_ind <= b and r_ind > b:
			ans += r_ind - b
		elif l_ind > b and r_ind > b:
			ans += r_ind - l_ind + 1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
ans = 0
L.sort(reverse=True)
for i in range(len(L) - 2):
    a = L[i]
    for j in range(i + 1, len(L) - 1):
        b = L[j]
        upperC = a+b
        lowerC = abs(a-b)
        l_in =  [i for i in L[j+1:] if lowerC < i < upperC]
        ans += len(l_in)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=list(map(int, input().split()))
S.sort(reverse=True)
count=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if(S[i]>=S[j]+S[k]):
                count=count+1
print(int(n*(n-1)*(n-2)/6-count))

Submission status: Time Limit Exceeded

Solution code:
# 1行目の入力を数値として扱う
n = int(input())
# 2行目の入力を数値のリストとして扱う
a = list(map(int, input().split()))

#
ans = 0

#
for i in range(0, n - 2):
    for j in range(0, n - 1):
        if j <= i:
            continue
        for k in range(0, n):
            if k <=j:
                continue
#            print(str(a[i]) + "," + str(a[j]) + "," + str(a[k]))
            if a[i] >= a[j] + a[k]:
                continue
            if a[j] >= a[i] + a[k]:
                continue
            if a[k] >= a[i] + a[j]:
                continue
            ans+=1

# 答えの出力
print(ans)

Submission status: Time Limit Exceeded

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

a = list(itertools.combinations(l,3))
v = 0
for c in a:
  if c[0] >= c[1]+c[2] or c[1] >= c[2]+c[0] or c[2] >= c[0]+c[1]:
    continue
  v += 1
print(v)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

# print(list(combinations(L,3)))

for i, j ,k in list(combinations(L, 3)):
    if i < j + k and j < i + k and k < i + j:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in itertools.combinations(L, 3):
    # print(i)
    if i[2] < i[0] + i[1]:
        answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted(list(map(int, input().split())))
s = 0
for i in range(n-1,1,-1):
  a = l[i]
  for j in range(i-1,0,-1):
    b = l[j]
    for k in range(0,j):
      c = l[k]
      if(b+c>a):
        s += j-k
        break
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def is_triangle(l):
    a, b, c = l
    if a < b + c and b < c + a and c < a + b :
        return 1
    else:
        return 0

ans = 0

for m in list(itertools.combinations(l,3)):
    ans += is_triangle(m)

print(ans)

Submission status: Time Limit Exceeded

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

for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1, n):
            if S[a]+S[b]>S[c]:
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
L = list(map(int, input().split()))
ans = 0
  
for i, j, k in combinations(L,3):
  if abs(i-j) < k and k < i+j:
    ans += 1
          
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools

def calc(a, b, c):
  if a < b + c:
    return True
  return False

n = int(input())
l = [int(s) for s in input().split()]
conter = 0
for v in itertools.combinations(l, 3):
  if calc(v[0],v[1],v[2]) and calc(v[1],v[0],v[2]) and calc(v[2],v[1],v[0]):
    conter += 1
print(conter)

Submission status: Time Limit Exceeded

Solution code:
def Triangles(N, Lrand):
    L = sorted(Lrand, reverse=True)
    cnt = 0
    for i in range(N-2):
        if L[i] >= L[i+1] * 2: break
        for j in range(i+1, N-1):
            if L[i] >= L[j] + L[j+1]: break
            for k in range(j+1, N):
                if L[i] >= L[j] + L[k]: break
                cnt += 1
    return cnt

N = int(input())
L = [int(x) for x in input().split()]
print(Triangles(N, L))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
               if length[k] < length[i]+length[j]:
                   count += 1
               else:
                   pass
print(count)

Submission status: Time Limit Exceeded

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

def check(i,j,k):
	if i < j + k:
		if j < i + k:
			if k < i + j:
				return 1
	return 0

cnt = 0
for i in range(int(N)):
	for j in range(i+1, N):
		for k in range(j+1, N):
			cnt += check(L[i],L[j],L[k])

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
new=sorted(l,reverse=True)
ans=0

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            k = 0
            for k, lk in enumerate(L[i+j+2+k:]):
                if lk-lj >= li:
                    res += k
                    break
            else:
                res += k + 1
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort(reverse=True)
c = 0
for ll in range(n):
    for lm in range(ll+1, n):
        for lr in range(lm+1, n):
            if l[ll] < l[lm] + l[lr]:
                c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import itertools
n = int(input())
l = [int(x) * -1 for x in input().split()]

l.sort()
ans = 0

for i in range(n):
    a = heapq.heappop(l)
    for b,c in list(itertools.combinations(l,2)):
        if a > b+c:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
l= list(map(int, input().split()))
a=0
list.sort(l, reverse=True)
for i in range(n-2):
    ten = l[0]
    l.pop(0)
    l2 = copy.copy(l)
    #print(ten,"/",l)
    for j in range(len(l2)-1):
        for k in range(j+1,len(l2)):
            if ten < l[j] + l[k] and l[j] < ten + l[k] and l[k] < l[j] + ten:
                #print("a++ : ",ten,"/",l[j],"/",l[k])
                a+=1
            else:
                l2.pop(len(l2)-1)
                break
        if(len(l2) <= j ):
            break
    #print("l2 : ",l2)
print(a)

Submission status: Time Limit Exceeded

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

for i in range(n):
  for j in range(i + 1, n):
    for k in range(j + 1, n):
      a = data[i]
      b = data[j]
      c = data[k]
      if c < a + b:
        count+=1
      else:
        break
      
print(count)

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)

List = []
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(len(List)):
        if List[j] > L[i]:
            Sum += 1

    del List[0:N - i - 2]

print(Sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
count = 0
for i, li in enumerate(l_list):
    for j, lj in enumerate(l_list[i+1:], i+1):
        for lk in l_list[j+1:]:
            if li + lj <= lk:
                break
            else:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:

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

x = 0


for i in range(len(L)):
    
    for j in range(i+1, len(L)):
        if L[i] > 2 * L[j]:
            break
        for k in range(j+1, len(L)):
            if L[i] > L[j] + L[k]:
                break
            
            if (L[k] < L[i] + L[j]):
                if (L[i] < L[j] + L[k]):
                    if  (L[j] < L[k] + L[i]):
                        x += 1

print(x)

Submission status: Time Limit Exceeded

Solution code:
n, *l = map(int, open(0).read().split())
sl = sorted(l,reverse=True)

ans = 0
for i in range (n):
  for j in range (i+1,n):
    for k in range(j+1,n):
      if sl[i]<sl[j]+sl[k]:
        if sl[j]<sl[k]+sl[i]:
          if sl[k]<sl[i]+sl[j]:
            ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(x) for x in input().split()]
L.sort()
ans = 0
for i in range(N):
  for j in range(i+1,N):
    k = j+1
    while k < N:
      if L[k] >= L[i] + L[j]:
        break
      k += 1
    k -= 1
    ans += max((k-j),0)
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
count=0
for l in range(N):
  for k in range(l+1,N):
    for j in range(k+1,N):
      if (L[l]<L[k]+L[j])and(L[k]<L[j]+L[l])and(L[j]<L[l]+L[k]):
        count=count+1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort()
m=0
for i in range(N):
    for j in range(0,i):
        for k in reversed(range(0,j)):
            if S[k]>S[i]-S[j]:
                m+=1
            else:
                break

print(m)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

count = 0
# for a, b, c in combinations(ls, 3):
#     if a < b + c and b < c + a and c < a + b:
#         count += 1
for j in range(n - 1, 1, -1):
    last = ls[j]
    for a, b in combinations(ls[:j], 2):
        if a + b > last:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
ans = 0
a.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        b = a[j+1:]
        tmp = a[i] + a[j] - 1
        tt = bisect.bisect_right(b,tmp)
        # print(i,j,tmp,tt,b)
        if tmp >= a[-1]:
            ans += tt
        elif tt > 0 :
            ans += tt
        
print(ans)

Submission status: Time Limit Exceeded

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

L.sort()
n = 0
for i in range(len(L) - 2):
    for j in range(i + 1, len(L) - 1):
        for k in range(j + 1, len(L)):
            if L[i] + L[j] > L[k]:
                n += 1
            else:
                break

print(n)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i,j,k in list(itertools.combinations(L,3)):
  if i < j+k and j < i+k and k < i+j:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


def main():
    N = int(input())
    edges = [int(i) for i in input().split()]

    ans = set()
    edges.sort()
    for a in range(N - 2):
        for b, c in combinations(range(a + 1, N), 2):
            if edges[a] < edges[b] + edges[c] and edges[b] < edges[c] + edges[a] and edges[c] < edges[a] + edges[b]:
                ans.add((a, b, c))
    print(len(ans))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

L.sort()

ans = 0
b = 1
c = 2
while b < N-1:
  sub = L[c] - L[b]

  a = 0
  while L[a] <= sub:
    a += 1
    if a >= b:
      b += 1
      c = b
      break
  else:
    ans += b-a
    
  c += 1
  if c >= N:
    b += 1
    c = b + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = [int(i) for i in input().split()]

import itertools
X = list(itertools.combinations(range(N), 3))

Y = 0
import math
Z = int(math.factorial(N) / (math.factorial(3) * math.factorial(N - 3)))

if N >= 4:
    for i in range(Z):
        a = L[X[i][0]]
        b = L[X[i][1]]
        c = L[X[i][2]]
        if a < b + c and b < c + a and c < a + b:
            Y += 1

elif N == 3:
    a = L[X[0][0]]
    b = L[X[0][1]]
    c = L[X[0][2]]
    if a < b + c and b < c + a and c < a + b:
        Y += 1

print(Y)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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):
    for k in range(j+1,n):
      if l[i] >= l[j]+l[k]:
        continue
      if l[j] >= l[i]+l[k]:
        continue
      if l[k] >= l[i]+l[j]:
        continue
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

#print(L)

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

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

print(ans)


# for i in range(N - 2):
#     if L[i] < L[i + 1] + L[i + 2] and L[i + 1] < L[i + 2] + \
#             L[i] and L[i + 2] < L[i] + L[i + 1]:
#         ans += 1

# print(ans)

Submission status: Time Limit Exceeded

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

res = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if L[k] < L[i] + L[j]:
                res += 1
            else:
                break

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
L = [int(a) for a in input().split()]

comb_sides = list(itertools.combinations(L, 3))

num_triangles = 0
for sides in comb_sides:
    if sides[0] + sides[1] > sides[2] and sides[1] + sides[2] > sides[0] and sides[2] + sides[0] > sides[1]:
        num_triangles += 1

print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import copy

N = int(input())
L = [int(i) for i in input().split()]

l=list(itertools.combinations(L,3))
result = 0

for i in l:
    i = list(i)
    isOk=True
    for index,j in enumerate(i):
        k = copy.copy(i)
        k.pop(index)
        if j>=sum(k):
            isOk=False
    if isOk:
        result+=1

print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
# index: 0,...,N-1

ans = 0
for i in range(N-2): # i: 0,...,N-3
    for j in range(i+1, N-1): # j: i+1,...,N-2
        # k: j+1,...,N-1
        rest = Ls[j+1:]
        idx_left  = bisect.bisect_left(rest, Ls[j] - Ls[i] + 1)
        idx_right = bisect.bisect_left(rest, Ls[j] + Ls[i])
        if idx_left < idx_right:
            ans += idx_right - idx_left

print(ans)

Submission status: Time Limit Exceeded

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

from functools import lru_cache
import itertools
@lru_cache(maxsize=None)
def ok(a,b,c):
    if a < b+c and b < c+a and c < a+b:
        return 1
    return 0
res = 0
for a,b,c in itertools.combinations(L,3):
    m = ok(a,b,c)
    res += m
print(res)
#for ai, a in enumerate(L):
#    for b in L[ai+1:]:
#        print(a,b)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import sys

n = int(input())
*l, = map(int, input().split())
heapq.heapify(l)
c = 0
s = []
try:
    for i in range(n):
        while len(s) < 2:
            s.append(heapq.heappop(l))
        m = heapq.heappop(l)
        for j in range(len(s)):
            for k in range(j+1, len(s)):
                if m < s[j] + s[k]:
                    c += 1
        s.append(m)
except:
    print(c)
    sys.exit(0)
print(c)

Submission status: Time Limit Exceeded

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

for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if l[k]>=l[i]+l[j]:
        break
      if l[i]<l[j]+l[k] and l[j]<l[k]+l[i]:
        n=n+1

print(n)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]<l[j]+l[k]:
                if l[j]<l[i]+l[k]:
                    if l[k]<l[i]+l[j]:
                        ans+=1
            else:
                continue
                
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Llist.sort(reverse=True)
num = 0
for i in range(N-2):
    for j in range(N-2-i):
        for k in range(N-2-i-j):
            if Llist[i] >= Llist[i+1+j] + Llist[i+2+j+k]:
                break
            else:
                num += 1
        
print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations
import bisect
import math
n = int(input())
l_ls = [int(i) for i in sys.stdin.readline().split()]
l_ls.sort()
l_dict = { i : j for i, j in enumerate(l_ls)}
_sum_ls = []
cnt = 0
for combi in combinations(l_ls, 2):
    bisect.insort_left(_sum_ls, combi[0] + combi[1])
len_sum_ls = len(_sum_ls)
for l in l_ls:
    ind = bisect.bisect_right(_sum_ls, l)
    cnt += ind
print(int(math.factorial(n) / math.factorial(3) / math.factorial(n-3)) - cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from array import array

N = int(input())
lengths = array('I', sorted(map(int, input().split(" "))))

print(sum(1 for x, y, z in combinations(lengths, 3) if z < x + y))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            res_k = 0
            for k, lk in enumerate(L[i+j+2+res_k:]):
                if lk-lj >= li:
                    res_k += k
                    break
            else:
                res += k + 1
            res += res_k
    print(res)

Submission status: Time Limit Exceeded

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

lsorted = sorted(l, reverse=True)

for longest in range(len(l)-2):

    for second in range(longest+1, len(l)):
        if lsorted[longest] - 2*lsorted[second] >= 0:
            break 
        for k in range(second+1, len(l)):
            if lsorted[longest] - lsorted[second] - lsorted[k] >= 0:                
                break
            else:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = []
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] and L[j] < L[k]+L[i] and L[k] < L[i]+L[j]:
                ans.append(0)
print(len(ans))

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)

import itertools
from math import factorial

nCr = factorial(7) / factorial(3) / factorial(7 - 3)
A = []*(int(nCr))

A = list(itertools.combinations(L,3))

count = 0
 
for i in range(len(A)):
    a = A[i][0]
    b = A[i][1]
    c = A[i][2]
    
    if a+b > c and b+c > a and c+a > b:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

N = int(input())

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

patterns = list(itertools.combinations(edge, 3))

# print(patterns)

sum = 0
for p in patterns:
    # print(p)
    if p[0] < (p[1] + p[2]) and p[1] < (p[0] + p[2]) and p[2] < (p[0] + p[1]):
        sum += 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

import numpy as np

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


Ls = np.asarray(list(combinations(Ls, 3)))

print(
    len(
        Ls[
            (Ls[:, 0] < Ls[:, 1] + Ls[:, 2])
            & (Ls[:, 1] < Ls[:, 2] + Ls[:, 0])
            & (Ls[:, 2] < Ls[:, 0] + Ls[:, 1])
        ]
    )
)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=sorted(list(map(int, input().split())))
ans=0
x=[]
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,(n-sum((x>l[j]+l[i]) for x in l))):
            if (l[i]<(l[j]+l[k])and l[j]<(l[i]+l[k]) and l[k]<(l[j]+l[i]) and x.count([l[i],l[j],l[k]])==0):
                x.append([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()))

def check(i,j,k):
	if i < j + k:
		if j < i + k:
			if k < i + j:
				return 1
	return 0

cnt = 0
for i in range(int(N)):
	for j in range(i, N):
		for k in range(j, N):
			if i == j or j == k or k == i:
				continue
			cnt += check(L[i],L[j],L[k])

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l = sorted(list(map(int,input().split())),reverse=True)
ans=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]:
                ans+=1
            else:
                ans+=0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
L=np.array(list(map(int, input().split())))
S=0
L.sort()
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]: 
                S+=1
            else:
                break
print(S)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num =list(map(int,input().split()))
 
s_num = sorted(num, reverse=True)
 
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(1,n-j):
            if s_num[i] - s_num[j] < s_num[-k]:
                c += (n - j - k)
                break
                
print(c)

Submission status: Time Limit Exceeded

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

#ls = [218, 786, 704, 233, 645, 728, 389]

ls = sorted(ls, reverse=True)
#print(ls)
result = 0

#count = 0
for i in range(len(ls)):
    a = ls[i]
    for j in range(i+1, len(ls)):
        b = ls[j]
        if a > b*2:
            break
        for k in range(j+1, len(ls)):
            c = ls[k]
            #print(a,b, c)
            #count += 1
            if a < (b+c):
                result += 1

#print('count: ', count)
print(result)