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())
L = list(map(int, input().split(' ')))
number = 0

for i in range(N):
    for j in range(i + 1 , N):
        for k in range(j + 1 , N):
            sum = L[i] + L[j] + L[k]
            M = max([L[i], L[j], L[k]])
            if M < sum - M:
                number += 1

print(number)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

array = np.sort(L)[::-1]

sum = 0
length = len(array)

for i in range(length):
  for j in range(i+1, length):
    sum += np.count_nonzero(array[j+1::] > (array[i] - array[j]))
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int, input().split()))
cnt = n * (n - 1) * (n - 2) / 6
jud = []

for i in range(n):
    for j in range(n):
        if i > j:
            jud.append(L[i] + L[j])

for m in range(n):
    for p in range(len(jud)):
        if L[m] >= jud[p]:
            cnt -= 1

if cnt < 0:
    print(0)
else:
    print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
from bisect import*
N,*L=map(int,open(0).read().split());L.sort()
a=0
for i,l in enumerate(L):
    for j,m in enumerate(L[i+1:],i+1):
      	a+=bisect_left(L,l+m,j+1)-bisect(L,abs(l-m),j+1)
print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = [int(x) for x in input().split()]
L.sort(reverse=True)

count = 0
for a in range(n-2):
    for b in range(a + 1, n - 1):
        if L[b]*2 <= L[a]:
            break
        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]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def sol():
    n=int(input())
    l=[int(i) for i in input().split()]
    l.sort()
    ans=chk=0
    for i in range(1,n-1):
        for j in range(i):
            for k in range(i+1,n):
                #print(l[i],l[j],l[k])
                if i!=j and i!=k and j!=k and j<i<k:
                    if l[k]<l[i]+l[j] and l[i]<l[j]+l[k] and l[j]<l[i]+l[k]:
                        ans+=1
    print(ans)

if __name__=="__main__":
    sol()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int,input().split()))
L = sorted(L,reverse=True)
total = 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[j] + L[k] > L[i]:
                total += 1
            else:
                continue
print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
readline = sys.stdin.readline
n = int(readline())
A = list(map(int,readline().split()))
A.sort()
ans =0
for i in range(1,n):
    for j in range(i+1,n):
        ans += i- bisect.bisect(A,A[j]-A[i],hi=i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

combi = list(combinations(l, 3))

for i in range(len(combi)):
  max_num = max(combi[i])
  if max_num < (sum(combi[i]) - max_num):
    ans += 1
    
print(ans)

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):
        if s_num[i] - s_num[j] < s_num[-1]:
            c += (n - j -1)
            continue
        else:
            for k in range(j+1,n):
                if s_num[i] < s_num[j] + s_num[k]:
                    c += 1
                
print(c)

Submission status: Time Limit Exceeded

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

l.sort()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]+l[j]
        b = 0
        for k in reversed(range(j+1,n)):
            if a > l[k]:
                b = k
                break
        if b != 0:
            cnt += b-j

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
numbers = [int(i) for i in input().split()]
count = 0
list1 = list(itertools.combinations(numbers,3))
for item in list1:
    a = item[0]
    b = item[1]
    c = item[2]
    if max([a,b,c])<sum([a,b,c])/2:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
array = list(map(int, input().split()))
count = 0
array.sort(reverse = True)

for a in range(n):
    A = array[a]
    for b in range(a+1,n):
        B = array[b]
        ab = A - B
        for c in range(n-1,b,-1):
            if ab < array[c]:

                count += c - b
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in 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 abs(l[j] - l[k]) < l[i] < l[j] + l[k]: ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def tri_d(a,b,c):
  if (a+b>c) and (b+c>a) and (c+a>b):
    return True
  else:
    return False


ans=0
C=list(itertools.combinations(L, 3))
for c in C:
  if tri_d(c[0], c[1], c[2]):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def judge(a,b,c):
  if a<b+c and b<c+a and c<a+b:
    return 1
  else:
  	return 0
  
N = int(input())
L = [int(x) for x in input().split()]
ans = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      ans += judge(L[i],L[j],L[k])
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in 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):
            #print(a[i],a[j],a[k])
            if a[i]<a[j]+a[k] and a[j]<a[k]+a[i] and a[k]<a[i]+a[j]:
                ans+=1

print(ans)

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):
  j = N-2
  while j > i:
    k = N - 1
    while k > j:
      if L[i]-L[j]-L[k] < 0:
        ans += 1
      k -=1
    j -= 1
  
print(ans)

Submission status: Time Limit Exceeded

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

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

l.sort()
cnt = 0

for a,b,c in combinations(l, 3):
    if abs(b-a)+1 <= c <= a+b-1:
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

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

for i in itertools.combinations(L, 3):
    if i[0] >= i[1] + i[2]:
        continue
    elif i[1] >= i[0] + i[2]:
        continue
    elif i[2] >= i[1] + i[0]:
        continue
    else:
        answer += 1
print(answer)

Submission status: Time Limit Exceeded

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

for i in range(n - 2):
    for j in range(n - i - 2):
        for k in range(n - i - j - 2):
            if l[i] < l[j + i + 1] + l[k + j + i + 2] and l[j + i + 1] < l[k + j + i + 2] + l[i] and l[k + j + i + 2] < l[i] + l[j + i + 1]:
                m += 1
                
print(m)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
counter=0
for t in range(N):
  for i in range(t+1,N):
    for p in range(i+1,N):
      if L[p]<L[t]+L[i] and L[t]<L[i]+L[p] and L[i]<L[p]+L[t]:
        counter+=1
print(counter)

Submission status: Time Limit Exceeded

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

ans = 0

i = 0
j = 1
k = 2

while i < n-2:
    while j < n-1:
        while k < n:
            if ll[i] + ll[j] <= ll[k]:
                break
            else:
                # print([ll[i], ll[j], ll[k]])
                k += 1
                ans += 1
        j += 1
        k = j + 1
    i += 1
    j = i + 1
    k = 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 k in range(N-2):
    for j in range(k+1, N-1):
        ans += bisect.bisect_left(L[j+1:], L[k]+L[j])


print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if sl[i]+sl[j] > sl[k]:
                cnt += 1
            else:
                break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
listed = list(map(int,input().split()))
count = 0
for x in range(0,N):
    
    for y in range(x+1,N):
        for z in range(y+1,N):
            if listed[x] < listed[y]+listed[z] and listed[y] < listed[x]+listed[z] and listed[z] < listed[x]+listed[y]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            s = [l[a],l[b],l[c]]
            s.sort()
            if s[2] < s[0] + s[1]:
                co += 1

print(co)

Submission status: Time Limit Exceeded

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

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):
            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 tri_able(x, y, z):
    if x+y > z and y+z > x and z+x > y:
        return True

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split(" ")))
 
counter = 0
 
for num_1, i in enumerate(L):
  for num_2, j in enumerate(L):
    if num_1 <= num_2:
      break
    else:
      for num_3, k in enumerate(L):
        if num_2 <= num_3:
          break
        else:
          if i+j >k and j+k>i and k+i>j:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
from bisect import bisect_left, bisect_right

def main():
    N = int(input())
    L = [int(c) for c in input().split()]
    L = sorted(L)
    num = 0
    for ai in range(N):
        for bi in range(ai+1, N):
            if bi - ai == 1:
                continue
            a = L[ai]
            b = L[bi]
            ci_left = bisect_right(L, abs(L[ai] - L[bi]))
            ci_right = bisect_left(L, L[ai] + L[bi])
            if ci_left == ci_right:
                continue
            else:
                ci_left = max(ci_left, ai + 1)
                ci_right = min(ci_right, bi)
            # print(a, b, ci_left, min(ci_right, bi) - max(ci_left, ai) - 1)
            # num += min(ci_right, bi) - max(ci_left, ai) - 1
                num += ci_right - ci_left
            # print(a, b, ci_right, ci_left, num)

    print(num)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

height_num = input()
input_list = input().split()
triangle_list = itertools.combinations(input_list, 3)
triangle_num = 0
for triangle in list(triangle_list):
    num_0 = int(triangle[0])
    num_1 = int(triangle[1])
    num_2 = int(triangle[2])
    if num_0 >= num_1 + num_2:
        continue
    elif num_1 >= num_2 + num_0:
        continue
    elif num_2 >= num_0 + num_1:
        continue
    triangle_num += 1
print(triangle_num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sticks = sorted([int(s) for s in input().split()])
point = 0

for i in range(n-2):
  for j in range(n - i- 2):
    a = sticks[i] + sticks[i+j+1]
    for k in range(1,n):
      if sticks[-k] >= a:
        point+=1
      else:
        break
      
    
print(int(n*(n-1)*(n-2)/6)-point)

Submission status: Time Limit Exceeded

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

def triangle(a, b, c):
    if a < b + c and b < a + c and c < a + b:
        return 1
    else:
        return 0
    
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            cnt += triangle(L[i], L[j], L[k])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=input()
L=L.split()
L=[int(item) for item in L]
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):
            if (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()))
su=0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i<j and j<k and L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[j]+L[i]:
                su+=1
print(su)

Submission status: Time Limit Exceeded

Solution code:
def f(a,b,c):
        if a < b+c and b < c+a and c < a+b:
                return True
        else:
                return False

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):
                for k in range(j+1, n):
                        if f(l[i], l[j], l[k]) == True:
                                ans += 1
                        else:
                                break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for a in range(N-2):
        for b in range(a+1,N-1):
                for c in range(b+1, N):
                        if l[c]<l[b]+l[a] and l[c]>l[b]-l[a]:
                                ans += 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):
    for j in range(i + 1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]
        ans += bisect.bisect_left(L[j+1:], r) - bisect.bisect_right(L[j+1:], l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def is_triangle(a,b,c):
	if a<b+c :
		return True
	return False

_ = input()
rods = list(map(int,input().split()))
rods.sort(reverse=True)
num = 0
for i,a in enumerate(rods) :
	for j,b in enumerate(rods[i+1:],start=1):
		if not is_triangle(a,b,b):
			break
		for c in rods[i+j+1:]:
			if is_triangle(a,b,c):
				num += 1
			else :
				break
print(num)

Submission status: Time Limit Exceeded

Solution code:
def Triangles(N, Lrand):
    L = sorted(Lrand)
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            L2 = L[i] + L[j]
            for k in range(j+1, N):
                if L[k] >= L2: 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())
li = list(map(int,input().split()))
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):
      a = li[i]
      b = li[j]
      c = li[k]
      if a < b + c and b < c + a and c < a + b:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = 0
for cs in combinations(Ls, 3):
    a, b, c = cs

    if not a < (b + c):
        continue

    if not b < (c + a):
        continue

    if not c < (a + b):
        continue

    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

ans = 0

for i in range(N):
  for j in range(N):
    for k in range(N):
      if i <= j or j <= k:
        pass
      else:
        if L[k] >= L[i]+L[j]:
          break
        elif abs(L[i]-L[j]) < L[k]:
          ans += 1
          
          
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=[i for i in map(int,input().split())]
#print(L)
M=[]
ans=0
for i in itertools.permutations(L,3):
    X=list(i)
    X.sort()
    if X not in M :
        M.append(X)
#print(M)

for i in M :
    if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[0] + i[1] :
        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):
  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:
from itertools import combinations

n = int(input())
ls = map(int, input().split())
res1 = filter(lambda x: x[0] < x[1] + x[2], combinations(ls, 3))
res2 = filter(lambda x: x[1] < x[2] + x[0], res1)
res3 = filter(lambda x: x[2] < x[0] + x[1], res2)
print(sum(map(lambda x: 1, res3)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int,input().split()))
ans = 0
import itertools
for l in list(itertools.combinations(L,3)):
    a, b, c = l
    if a < b + c and b < c + a and c < a + b:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int,input().split()))
L = list(itertools.combinations(L,3))
ans = 0
for a,b,c in L:
  if a + b > c and b + c > a and a + c > b:
    ans += 1
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):
    for j in range(i+1, N):
        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()
k2 = 2
ans = 0
for i in range(N-2):
    for j in range(1,N-1-i):
        s = L[i] + L[N-j-1]
        if L[N-j] >= s:
            ans += j
        else:
            for k in range(N-j+1,N):
                if L[k] >= s:
                    ans += N-k
                    break
print((N*(N-1)*(N-2))//6 - ans)

Submission status: Time Limit Exceeded

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

L.sort()
cnt = 0
for i in range(N-1):
    for j in range(i):
        a, b = L[i], L[j] 
        k = i + 1
        l = 0
        r = 0
        for k in range(i+1, N):
            if L[k] > a - b:
                l = k
                break
        for k in range(N-1, i, -1):
            if L[k] < a + b:
                r = k
                break
        
        cnt += max(r - l + 1, 0)
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
arr = list(map(int,input().split()))

arr.sort(reverse = True)
count = 0
combiarr = [[arr[i]+arr[j] if i < j else 0 for j in range(n)] for i in range(n)]
combiarr = np.array(combiarr)
for i in range(n-2):
    long = arr[i]
    tmparr = combiarr[i+1:,i+1:] - long
    count += sum(sum(tmparr > 0))    
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int, input().split(" ")))
l.sort()
t = 0
for i in range(N-2):
    a = l[i]
    for j in range(i+1, N-1):
        b = l[j]
        low, upp = abs(b-a), a+b
        flag = 0
        for k in range(j+1, N):
            if low < l[k] < upp:
                t += 1
                flag = 1
            else:
                if flag == 1:
                    break
                else:
                    continue
print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(int(i) for i in input().split())
list.sort(l_list, reverse=True)
count = 0
for i in range(n):
    a = l_list[i]
    for j in range(i+1, n):
        b = l_list[j]
        for k in range(j+1, n):
            c = l_list[k]
            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 = [int(x) for x in input().split()]

ans = 0

for a in range(n):
    for b in range(a+1, n):
        ll = [x for x in l[b:] if x<l[a]+l[b]]
        #print(ll)
        for c in range(1, len(ll)):
            #print(a, b, c)
            if l[a]<l[b]+ll[c] and l[b]<ll[c]+l[a]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l = [int(i) for i in input().split()]
ans = 0
for x in itertools.combinations(l,3):
    if(x[0] >= x[1]+x[2]): continue
    if(x[1] >= x[0]+x[2]): continue
    if(x[2] >= x[0]+x[1]): continue
    ans += 1


print(ans)

Submission status: Time Limit Exceeded

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

result = 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]:
                result += 1
            else:
                break

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = [int(x) for x in input().split()]
L.sort(reverse=True)

count = 0
for a in range(n-2):
    for b in range(a + 1, n - 1):
        if b*2 <= a:
            break
        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]:
                count += 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):
                L1 = L[i]
                L2 = L[j]
                L3 = L[k]
                if L1<L2+L3 and L2<L1+L3 and L3<L1+L2:
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

l = len(L)

def judge(a, b, c):
    if a >= b + c:
        return False
    if b >= c + a:
        return False
    if c >= a + b:
        return False
    return True

count = 0
for i in range(l):
    a = L[i]
    for j in range(i+1,l):
        b = L[j]
        ab = a + b
        for k in range(j+1,l):
            c = L[k]
            if c >= ab:
                break
            if judge(a, b, c):
                count += 1
                
print(count)

Submission status: Time Limit Exceeded

Solution code:

import itertools
 
N = int(input())

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

ans = 0

for i in itertools.combinations(li, r=3):
    max_i = max(i)
    if max_i < sum(i) - max_i :
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
L = list(map(int,input().split()))
L.sort()
c = 0
for i in range(0,N-2):
	for j in range(i+1,N-1):
		s = L[i] + L[j]
		for k in range(j +1, N):
			if s > L[k]:
				c +=1
			else:
				break
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = tuple(map(int, input().split()))
s = []
for i in range(n - 1):
    for j in range(i + 1, n):
        s.append([l[i] + l[j], i, j])

m = len(s)
ans = (n * (n - 1) * (n - 2)) // 6

for i in range(n):
    for j in range(m):
        if s[j][1] == i or s[j][2] == i:
            continue
        elif l[i] >= s[j][0]:
            ans -= 1
print(ans)

Submission status: Time Limit Exceeded

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

    L = sorted(L, reverse=True)

    ans = 0
    for i in range(N):
        for j in range((i+1), N):
            if L[i]/2 >= L[j]:
                break 
            for k in range((j+1), N):
                if L[i] < (L[j]+L[k]):
                    ans += 1

    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#絶対時間切れ
n = int(input())
l = sorted(map(int, 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 l[i] + l[j] > l[k]:
                c += 1
                
print(c)

Submission status: Time Limit Exceeded

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

score = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):
      a = l_list[i]
      b = l_list[j]
      c = l_list[k]
      if (a + b > c) and (b + c > a) and (c + a > b):
        score += 1
        
print(score)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
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] and L[j] < L[k]+L[i] and L[k] < L[i]+L[j]:
                count += 1
            else:
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = map(int, input().split())
sum = 0
tri = set(itertools.combinations(L, 3))
for t in tri:
    t = sorted(t)
    if(t[0] + t[1] > t[2]):
        sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


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

    max_l = max(L)

    ans = 0

    for a in range(N):

        for b in range(a+1, N):
            if L[a] >= L[b] + max_l:
                continue

            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
                else:
                    break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

def main():
    N = int(input())
    L = [int(i) for i in input().split()]
    L.sort()
    count = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            k = bisect.bisect_left(L, L[i] + L[j])
            k -= 1
            while k != j:
                if L[i] < L[j] + L[k] and L[j] < L[i] + L[k]:
                    count += 1
                k -= 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(i) for i in 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 sys
import itertools

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

L =list(itertools.combinations(L, 3))
cnt =0
for ele in L:
    ele = sorted(ele)
    if(ele[2] < ele[0]+ele[1]):
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n1 = int(input())
d1 = [int(i) for i in input().split()]

d1.sort()

r1 = 0

for i1 in range(n1 - 1):
    for i2 in range(n1 - i1 - 1):
        for i3 in range(n1 - i1 - i2 - 2):
            if d1[i1] < d1[i2 + i1 + 1] + d1[i1 + i2 + i3 + 2]:
                if d1[i2 + i1 + 1] < d1[i1] + d1[i1 + i2 + i3 + 2]:
                    if d1[i1 + i2 + i3 + 2] < d1[i1] + d1[i2 + i1 + 1]:
                        r1 += 1
                    else:
                        break

print(r1)