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())
lb = list(map(int,input().split()))
###
defaultans = int(n*(n-1)*(n-2)/6)
###
lb.sort()
cnt = defaultans
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a, b, c = lb[i], lb[j], lb[k]
            if a >=b+c or b >= c+a or c >= a+b:
                cnt -= n - k 
                break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())  # N本の棒
L = sorted(map(int, input().split()))  # i本目の棒の長さはLi


count = 0
for i1, x in enumerate(L):
    a = x

    for i2, y in enumerate(L):
        if i2 > i1:
            b = y
        else:
            continue

        for i3, z in enumerate(L):
            if i3 > i2 and i3 > i1:
                c = z

                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 = sorted(list(map(int, input().split())))
answer = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        lij = l[i] + l[j]
        for k in range(j + 1, n):
            if l[k] < lij:
               answer += 1
            else:
               break
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
l=list(map(int,input().split()))
l.sort()
# print(l)
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        left=bisect.bisect_left(l,l[i]+l[j])
        right=bisect.bisect_right(l,(l[i]+l[j]+1)//2)
        # print(left)
        # print(right)
        # print()
        cnt=left-(j+1)
        if left<=j+1:
            # print(99)
            continue
        # if right<j+2:
        #     cnt-=j+2-right
        if cnt>=0:
            ans+=cnt
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as C


N = int(input())
Ls = [i for i in map(int, input().split())]

count = 0
for a, b, c in C(Ls, 3):
  if a < b + c and b < c + a and c < a + b:
    count += 1
    
print(count)

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

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i, a in enumerate(ll):
  for j, b in enumerate(ll[i+1:]):
    climit = a + b
    for k, c in enumerate(ll[i+j+2:]):
      if c >= (climit):
        break
      if is_triangle(a, b, c):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
L = [int(i) for i in input().split()]
L.sort(reverse=True)
ans = 0
P = []
for i in range(N-1):
    for j in range(i+1,N):
        P.append(L[i]+L[j])
now = 0
ans = 0
for i in range(N-2):
    now += N - (i + 1)
    A = P[now:]
    A.sort()
    index = bisect.bisect_left(A,L[i]+0.1)
    ans += (len(A) - index)
print(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-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        for s in range(N-1, j, -1):
            c = L[s]
            if L[s]<L[i]+L[j]:
                cnt += s - j
                break
print(cnt)

Submission status: Time Limit Exceeded

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

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
                flag=True
        if flag:
            break
    if flag:
            break

print(ans)

Submission status: Time Limit Exceeded

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

l.sort()

temp = 0
count = 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]:
        count += 1
      else:
        break;
print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

def solve(N: int, L: "List[int]"):
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            s_ab = L[i] + L[j]
            n_L = L[j+1:]
            n_L.append(s_ab)
            n_L = sorted(n_L)
            cnt += n_L.index(s_ab)
    print(cnt)


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = sorted([int(next(tokens)) for _ in range(N)]) # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

A=sorted(A)
#print(A)
count=0
flag=False
for i in range(n-2):
  a=A[i]
  for j in range(i+1,n-1):
    b=A[j]
    for k in range(j+1,n):
      c=A[k]
      if a+b>c:# and b+c>a and a+c>b:
        count+=1
        if k==n-1 and n-1-j>=2:
          flag=True
      elif a+b<=c:
        break
    if flag:
      flag=False
      count+=comb(n-1-j,2)#(n-1-j)C2
      break
print(count)

Submission status: Time Limit Exceeded

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

a = list(itertools.combinations(l,3))
ans =0
for i in range(0,len(a)):
    max_num_index = a[i].index(max(a[i]))
    if max_num_index == 0:
        if a[i][0] >= a[i][1] + a[i][2]:
            continue
    if max_num_index == 1:
        if a[i][1] >= a[i][0] + a[i][2]:
            continue
    if max_num_index == 2:
        if a[i][2] >= a[i][0] + a[i][1]:
            continue
    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 i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if calc(l[i],l[j],l[k]) and calc(l[k],l[i],l[j]) and calc(l[j],l[i],l[k]):
        conter += 1
print(conter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L= list(map(int,input().split()))
ret=0
for i,l in enumerate(L):
  for j,m in enumerate(L[i+1:]):
    for k,n in enumerate(L[i+j+2:]):
      #print(l,m,n)
      if n>abs(l-m) and n<(l+m):
	      ret+=1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

comb = list(combinations(l, 3))

ans = 0
for i in comb:
    a = i[0]
    b = i[1]
    c = i[2]
    if (a < b + c) and (b < c + a) and (c < a + b):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = 0
for c in comb:
    if c[0] + c[1] - c[2] > 0:
        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())))

l = np.sort(l)[::-1]

cnt = 0
for a in range(n):
    for b in range(a + 1, n):
        for c in range(b + 1, n):
            if l[a] < (l[b] + l[c]) and l[b] < (l[a] + l[c]) and l[c] < (l[a] + l[b]):
                cnt += 1
            else:
                break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def check(target):
    if target[0] < target[1]+target[2] and target[1] < target[2]+target[0] and target[2] < target[0]+target[1]:
        return 1
    return 0
counts = 0
for v in itertools.combinations(L,3):
    if check(v) == 1:
        counts += 1
print(counts)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

count = 0

for i in list:
  if i[0] < i[1] + i[2]:
    if i[1] < i[0] + i[2]:
      if i[2] < i[1] + i[0]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    for j in range(i + 1, n):
        x, y = ls[i], ls[j]
        tri_xy = [k for k in ls[j + 1:] if k < x + y]
        count += len(tri_xy)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split(" ")))
l.sort()
l.reverse()
cnt = 0 
flag = False
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if i == j:
            continue
        for k in range(j+1,n):
            if i == k and j == k:
                continue
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                cnt+=1
            else:
                flag=True
                break
print(cnt)

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)
ind = 0
for l in l_ls:
    while ind < len_sum_ls:
        if _sum_ls[ind] <= l:
            ind += 1
        else:
            cnt += ind
            break
print(int(math.factorial(n) / math.factorial(3) / math.factorial(n-3)) - cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

L.sort(reverse=True)

List = deque()
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

    for j in range(N-2-i):
        List.popleft()

print(Sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def f(ary):
  if len(ary) < 3:
    return 0
  
  a = ary[0]
  s = 0
  for (b, c) in itertools.combinations(ary[1:], 2):
    b, c = sorted([b, c])
    if a < b + c and b < c + a and c < a + b:
      s += 1
  
  return s

s = 0
for i in range(N):
  s += f(L[i:])

print(s)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
length = list(map(lambda x:int(x), input().split()))
length.sort()
ans = 0
for i in range(n):  
    a = length[i]
    for j in range(i+1,n):
        b = length[j]
        if i >= j:
            continue
        else:
            c_candidates = length[j+1:]
            min_bar = bisect.bisect_right(c_candidates,b-a)
            max_bar = bisect.bisect_left(c_candidates,a+b)
            ans += max_bar - min_bar
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())
L = list(int(x) for x in sys.stdin.readline().split())

def tri_able(x, y, z):
    if x+y > z and y+z > x and z+x > y:
        return True
    else:
        return False

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1,n-1):
    for j in range(i+1,n):
        if l[j] - l[i] >= l[i-1]:
            break
        else:
            ans += i - bisect.bisect_right(l[:i-1],(l[j]-l[i]))
print(ans)

Submission status: Time Limit Exceeded

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

listl.sort(reverse=True)

#print(listl)
ans=0
"""if n==3:
	if listl[0]>=listl[1]+listl[2]:
		ans=0
	else:
		ans=1
else:"""
for i in range(n-2):
	for j in range(i+1,n-1):
		for k in range(j+1,n):
		#	print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
ans = 0
L.sort(reverse = True)
try:
    while L[0] >= L[1]  + L[2]:
        del L[0]
except:
    pass
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 bisect import bisect_left, bisect_right


def count(i, j):
    l1, l2 = L[i], L[j]
    low = l2 - l1
    high = l2 + l1
    arr = L[j + 1:]
    start = bisect_right(arr, low)
    end = bisect_left(arr, high)
    return end - start


if __name__ == '__main__':
    input()
    L = [int(x) for x in input().split()]
    L.sort()
    total = 0
    for i in range(len(L)):
        for j in range(i + 1, len(L)):
            total += count(i, j)
    print(total)

Submission status: Time Limit Exceeded

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

ans = round(n*(n-1)*(n-2)/6)

l.sort()

for i in range(n):
    for j in range(n):
        if i<=j:
            break
        for k in range(n):
            if l[i]+l[j]<=l[n-k-1]:
                ans-=1
            else:
                break

if ans<0:
    ans=0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
count = 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[i + j + 1] <= L[i + j + k + 2]:
                pass
            elif L[i + j + 1] + L[i + j + k + 2] <= L[i]:
                pass
            elif L[i + j + k + 2] + L[i] <= L[i + j + 1]:
                pass
            else:
                count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = input().split()
S = 0

for i in range(N):
    L[i] = int(L[i])

L.reverse()

for i in range(N):
    for j in range(i+1 , N):
        for k in range(i+1 , j):
            if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j]:
                S += 1


print(S)

Submission status: Time Limit Exceeded

Solution code:
def calc(N, L):
    L.sort()
    r = 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
                else:
                    r += 1
    return r


N = int(input())
L = [int(s) for s in input().split()]
print(calc(N, L))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=list(map(int,input().split(" ")))
L.sort(reverse=True)
ans=0
for i in range(n-2):
	for s in range(i+1,n-1):
		for j in range(s+1,n):
			if  L[i]+L[s]>L[j]:
				if L[i]-L[s]<L[j]:
					ans+=1
			else:
				break

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans=0
for i in range(N-2):
	for j in range(i+1,N-1):
		p = A[i]+A[j]
		ans += bisect.bisect_left(A[j+1:],p)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split(" ")))
count = 0
l_list = [0, 0, 0]
for i in range(n-2):
    for j in range(n-i-2):
        j = j + i + 1
        for k in range(n-j-1):
            k = k + j + 1
            l_list[0] = l[i]
            l_list[1] = l[j]
            l_list[2] = l[k]
            l_list.sort()
            count += int((l_list[0] + l_list[1]) > l_list[2])
print(count)

Submission status: Time Limit Exceeded

Solution code:
def add(x, y):
  if dp_list[x][y] == 0:
    dp_list[x][y] = lists[x] + lists[y]
  return dp_list[x][y]


N = int(input())
lists = list(map(lambda x: int(x), input().split()))
dp_list = [[0 for i in range(N)] for j in range(N)]
count = 0

for a in range(len(lists)):
  if(a + 1) >= len(lists):
    break
  for b in range(a + 1, len(lists)):
    if(b + 1) >= len(lists):
      break
    for c in range(b + 1, len(lists)):
      if add(a, b) > lists[c] and add(b, c) > lists[a] and add(a, c) > lists[b]:
        count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

comb = combinations(l, 3)

sum = 0
for value in comb:
    if value[0] < value[1] + value[2] and value[1] < value[0] + value[2] and value[2] < value[0] + value[1]:
        sum += 1

print(sum)

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):
      inf=abs(L[l]-L[k])
      sup=L[l]+L[k]
      if inf<L[j]<sup:
        count=count+1
print(count)

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

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:]):
    for k,n in enumerate(L[i+j+2:]):
      #print(l,m,n)
      if n>abs(l-m) and n<(l+m):
	      ret+=1
print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l = list(l)
for i in range(n):
	l[i] = int(l[i])

count = 0
memo =[0,0,0]*100
#a<b+c, a>b-c, a>c-b
for a in range(n):
	for b in range(a+1,n):
		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
				memo += a,b,c


print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n=int(input())
l_list=list(map(int,input().split()))
l=np.array(l_list)
counter=0

for i in range(n):
	for j in range(n):
		for k in range(n):
			if i<j<k:
				if (l[i]<l[j]+l[k])&(l[j]<l[i]+l[k])&(l[k]<l[i]+l[j]):
					counter+=1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split(" ")))
count = 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[i]+l[j]:
        break
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

c = 0
for i in range(0,n-2):
    for j in range(i+1, n-1):
        ab = l[i]+l[j]
        for k in range(j+1, n):
            if(ab>l[k]):
                c+=1
            else:
                break
print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = map(int, input())
L_list = list(map(int, input().split()))
sum = 0
#L_list = [3 4 2 1]なら[3,4,2],[3,4,1],[3,2,1],[4,2,1]の4通り
L_combinations = list(itertools.combinations(L_list,3))
for L_combination in L_combinations:
    if L_combination[0] < L_combination[1] + L_combination[2] and L_combination[1] < L_combination[2] + L_combination[0] and L_combination[2] < L_combination[0] + L_combination[1]:
        sum += 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
count = 0
max_val = 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])) and (L[j] < (L[k]+L[i])) and (L[k] < (L[i]+L[j])):
				count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted(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<a+c and c<a+b:
                cnt+=1
            else:
                break
print(cnt)

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

Submission status: Time Limit Exceeded

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

_n = int(input())
llist = [item for item in map(int, input().split())]


def chker(slist):
    slist.sort()
    cnt = 0
    while len(slist) > 2:
        s0 = slist[0]
        tlist = slist[1:]
        while len(tlist) > 1:
            s1 = tlist[0]
            tlist = tlist[1:]
            for item in tlist:
                if item >= s0 + s1:
                    break

                cnt += 1

        slist = slist[1:]

    print(cnt)


chker(llist)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
while (l[-1]>l[-2]+l[-3]) and (len(l)>3):
	del l[-1]
n=len(l)
ans=0
i=0
while i<n-2:
	j=i+1
	while j<n-1:
		k=j+1
		while k<n:
			if l[k]<l[i]+l[j]:
				ans=ans+1
			else:
				k=n
			k=k+1
		j=j+1
	i=i+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
l =sorted(L)
t = 0
for i in range(N-2):
  for k in range(i+1,N-1):
    for m in range(k+1, N):
      if l[m] < l[k] + l[i]:
        t += 1
      else:
        break
print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
length = list(map(int, input().split()))
length = tuple(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
print(count)

Submission status: Time Limit Exceeded

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

result = 0

for index_1, a in enumerate(l):
  l_2 = l[index_1 + 1:]
  for index_2, b in enumerate(l_2):
    l_3 = l_2[index_2 + 1:]
    for c in (l_3):
      if a < (b + c) and b < (a + c) and c < (a + b):
        result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted([int(x) for x in input().split()])
#print(l)
ans = 0

for a in range(n):
    for b in range(a+1, n):
        for c in range(b+1, n):
            if l[c]<l[a]+l[b]:
                ans += 1
                #print(a,b,c)
                continue
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

for i in l:
    isOk=True
    a,b,c=i
    if a+b>c and a+c>b and c+b>a:
        result+=1

print(result)

Submission status: Time Limit Exceeded

Solution code:
# D TLE
import itertools
import bisect

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

L.sort()
value = 0

for i, j in itertools.combinations(range(len(L)-1), 2):
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=index

print(value)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import math
N=int(input())
l1=list(map(int,input().split()))
max_n=max(l1)
l2=tuple(combinations(l1,2))
l3=[sum(i) for i in l2 if sum(i)<=max_n]
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=comb(N,3)
for i in l3:
  for j in l1:
    if i<=j:
      ans-=1
print(ans)

Submission status: Time Limit Exceeded

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

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
        if flag:
            break
    if flag:
            break

print(ans)

Submission status: Time Limit Exceeded

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

count = 0
            
for i in range(le-1):
  for k in range(i+1,le-1):
    a,b =L[i],L[k]
    L_temp = L[k+1:]
    count = count + sum([1 for x in L_temp if a+b>x and a+x>b and b+x>a])
    
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

L.sort()

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        temp=L[i]+L[j]
        for k in range(N):
            f=True
            if k!=i and k!=j:
                if temp<=L[k]:
                    break
                elif L[j]+L[k]<=L[i]:
                    f=False
                elif L[k]+L[i]<=L[j]:
                    f=False
                if f:
                    ans+=1


print(ans//3)

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
llist=list(map(int,input().split()))
kazoe=0

llist.sort()
for a in range(n-2):
	for b in range(a+1,n-1):
		c=b+1
		sa=llist[b]-llist[a]
		while llist[a]+llist[b]>llist[c] :
			c+=1
			if c==n:
				break
		kazoe+=c-1-b
		c=b+2
print(kazoe)

Submission status: Time Limit Exceeded

Solution code:

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

x = 0


for i in range(len(L)):   
    for j in range(i+1, len(L)):
        for k in range(j+1, len(L)):
            if (abs(L[i]-L[j]) < L[k]) and (L[k] < (L[i]+L[j])):
                x += 1
            else:
                break
print(x)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
total = (N*(N-1)*(N-2))//6

L.sort(reverse=True)

times = 0

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

print(total - times)

Submission status: Time Limit Exceeded

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


for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        for k in range(j+1, n):
            c = l[k]
            if a<b+c and b<a+c and c<b+a:
                num = num + 1

print(num)

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = list(map(int, input().split()))
l.sort(reverse=True)
s = 0
for i in range(len(l)-2):
  longest = l[i]
  if l[i+1] + l[i+2] > longest:
    for j in range(i + 1, len(l)-1):
      second = l[j]
      for k in range(j+1, len(l)):
        third = l[k]
        if second + third > longest:
          s += 1
        else:
          break
print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for ai in range(N):
  for bi in range(ai+1,N):
    for ci in range(bi+1,N):
      if L[ci] < L[ai] + L[bi]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = input()
l_list = [int(i) for i in input().split()]

sum = 0
ll = list(itertools.combinations(l_list, 3))
for set_tri in list(itertools.combinations(l_list, 3)):
    a, b, c = [int(i) for i in set_tri]

    if (a >= b+c):
        continue

    if (b >= a+c):
        continue

    if (c >= a+b):
        continue

    sum = sum + 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
# 1 2 3 4
ans = 0
for a in range(N - 2):
    for b in range(a + 1, N - 1):
        for c in range(b + 1, N):
            if nums[a] + nums[b] > nums[c]:
                ans += 1
            else:
                break
print(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 = N*(N-1)*(N-2)/6
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 b+c > a:
        count += 1
print(count)