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:
import numpy as np

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

L = np.array(sorted(L, reverse=True))

ans = 0

for n in range(0,N-2):
    for o in range(n+1,N-1):
        ans += np.sum(L[o+1:]>L[n]+-L[o])
                
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N=int(input())
ll=list(map(int,input().split()))
ll.sort()
ans=0
for i in range(N):
    for j in range(i+1,N):
        delta=bisect_left(ll,ll[i]+ll[j],lo=j)-j-1
        if delta>0:
            ans+=delta
        #print(i,j,delta)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

num = input()
stickLengths = list(map(int, input().split()))
counter = 0

combinations = itertools.combinations(stickLengths, 3)

for v in combinations:
    if v[0] < v[1] + v[2]:
        if v[1] < v[0] + v[2]:
            if v[2] < v[1] + v[0]:
                counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

l.sort()

cand_n = 0

for a, b, c in itertools.combinations(l, 3):
    if c >= a + b or b >= a + b or c >= a + b:
        continue
    else:
        cand_n += 1

print(cand_n)

Submission status: Time Limit Exceeded

Solution code:
N = map(int, input())
data = 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通り
def listExcludedIndices(data, indices=[]):
  return [x for i, x in enumerate(data) if i not in indices]

L_combinations = []

for i in range(len(data)):
  for j in range(i, len(data) - 1):
    for k in range(j, len(data) - 2):
      jData = listExcludedIndices(data, [i])
      kData = listExcludedIndices(jData, [j])
      L_combinations.append([data[i], jData[j], kData[k]])

# print(L_combinations)
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:
import numpy as np

n = int(input())
l = list(map(int, input().split()))
count = 0
for i in range(n - 2):
    for j in range(i + 1 , n - 1):
        l_np = np.array(l[j + 1:n])
        count += np.count_nonzero((l_np > abs(l[i] - l[j])) & (l_np < l[i] + l[j]))
print(count)

'''
print("")
print("i=" +str(i)+ ", j=" + str(j))
print("l[i]=" + str(l[i]) + ", l[j]" + str(l[j]))
print("差 = " + str(abs(l[i] - l[j])) + ", 和 = " + str(l[i] + l[j]))
print("計算対象 = " + str(l_np))
print("個数 = " + str(np.count_nonzero((l_np > abs(l[i] - l[j])) & (l_np < l[i] + l[j]))))
'''

Submission status: Time Limit Exceeded

Solution code:
def count_sort(arr):
    max_num = max(arr)
    min_num = min(arr)
    count = [0] * (max_num - min_num + 1)
    for ele in arr:
        count[ele - min_num] += 1

    return [ele for ele, cnt in enumerate(count, start=min_num) for __ in range(cnt)]


n = int(input())
L = list(map(int, input().split()))
L = count_sort(L)
count = 0
for i, l1 in enumerate(L):
    for k, l2 in enumerate(L[i+1:]):
        num = i + k + 2
        for l3 in L[num:]:
            if l1 + l2 < l3:
                break
            if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l2 + l1:
                count += 1
            else:
                break

print(count)

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):
        ll = [x for x in l[b+1:] if x<l[a]+l[b]]
        #print(l[a], l[b], ll)
        ans += len(ll)
        """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 numpy as np

##################################################################
def main():
    Input = [input() for i in range(2)]
    N = int(Input[0])
    L = list(map(int,Input[1].split()))
    L.sort()
    L = np.array(L)
    ans = 0
    for i1 in range(0,N-2):
        a = L[i1]
        for i2 in range(i1+1,N-1):
            b = L[i2]
            ans += sum(L[i2+1:N]<a+b)
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for idx in range(2,N):
  if L[idx] < L[idx-1] + L[idx-2]:
    for cmb in combinations(L[:idx],2):
      if L[idx] < sum(cmb): ans += 1
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]
  break_number = i+2
  for j in range(i+1,N-1):
    B = L[j]
    for k in range(break_number,N):
      if L[k] >= A + B:
        cnt += k - j - 1
        break_number = k
        break
      if k == N-1:
        cnt += N - 1 - j
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
# n, *a = map(int, open(0))
# M, D = map(int, input().split())
L = list(map(int, input().split()))
# S = input()
cnt = 0
import itertools
import numpy as np
l = list(itertools.combinations(L, 2))
l2 = []
for t in l:
    l2.append(sum(t))
ary = np.array(l2)
# ary = np.array(L)
for i in L:
    # if t[0] + t[1] > t[2] and t[1] + t[2] > t[0] and t[0] + t[2] > t[1]:
    cnt += np.count_nonzero(ary <= i)
tot = (N * (N-1) * (N-2)) // 6
print(tot - cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
def input():
    return sys.stdin.readline()[:-1]
# input
_ = int(input()) 
bars = list(map(int, input().split()))

count = 0
for i in itertools.combinations(bars, 3):
    if max(i) * 2 < sum(i):
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
import bisect
import copy
#int型として読み込む
n = int(input())


#同じくint型でリスト化する
list1 = list(map(int,input().split()))
list1.sort()
cout = 0
m,k = 0,0
while True:
	if m == n-2:
		break
	o = list1.pop(0)
	list1_c = copy.deepcopy(list1) #ここでjのためのdeepcopyを更新
	while True:
		if k == len(list1):
			break
		p = list1_c.pop(0)

		a = abs(o-p) +1
		b = o+p -1 #<= ではなく<条件に揃える

		c = bisect.bisect_left(list1_c,a)
		d = bisect.bisect_right(list1_c,b)

		if c < d:
			cout += d-c
		k+=1

		
		#list1.insert(j,p)
	#list1.insert(i,o)
	k = 0
	m += 1

print(cout)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

'''
N = int(input())
L = sorted(list(map(int,input().split())))
print(L)
s = N*(N-1)*(N-2)//6
for i in range(N-1,1,-1):
    print('i',i)
    for k in range(i-1):
        print('k',k)
        for t in range(k+1,i):
            print('t',t)
            if L[i] < L[k] + L[t]:
                print('break')
                break
            else:
                s -= 1
                print('s',s)
print(s)
'''

Submission status: Time Limit Exceeded

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

L_sort = sorted(L, reverse=True)
c = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        k = j + 1
        if int(L_sort[j]) + int(L_sort[k]) <= int(L_sort[i]):
            continue
        while k <= N - 1 and int(L_sort[j]) + int(L_sort[k]) > int(L_sort[i]):
            c += 1
            k += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A=int(input())
L=input().split(' ')
L = [int(s) for s in L]

flag = 0
comb = A*(A-1)*(A-2)/6

for i in range(A):
    for j in range(i+1,A):
        for k in range(j+1,A):
            if i!=j and j!=k and i!=k and L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
                flag += 1
print(flag)

Submission status: Time Limit Exceeded

Solution code:
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:
def main():
    N = int(input())
    edges = [int(i) for i in input().split()]

    ans = set()
    for i, a in enumerate(edges):
        for j, b in enumerate(edges[i+1:]):
            for k, c in enumerate(edges[i+j+2:]):
                if a < b + c and b < c + a and c < a + b:
                    ans.add((a, b, c))
    print(len(ans))


if __name__ == "__main__":
    main()

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):
		if listl[j]<=(listl[i]/2):
			break
		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:
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]:
                if L[i] + L[j] > L[-1]:
                    result += N - k
                    break;
                result += 1
            else:
                break

print(result)

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

Submission status: Time Limit Exceeded

Solution code:
S_rod_count = input()
rod_count = int(S_rod_count)

S_rod = input().split(" ")
rod = [int(n) for n in S_rod]

answer = 0

def check(x,y,z):
    return (x < y + z) and (y < x + z) and (z < x + y)

a_count = 0
for a in rod:
    b_count = 0
    for b in rod:
        if (a_count < b_count):
            c_count = 0
            for c in rod:
                if (b_count < c_count):
                    if check(a,b,c):
                        answer += 1
                c_count += 1
        b_count += 1
    a_count += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = map(int, input().split())
SL = sorted(list(L))
A = [0] * (10 ** 3 + 10)

for i in SL:
    A[i] = True
for i in range(len(A)):
    if A[i] == True:
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]

# print(A[4-1] - A[2])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            # print(i, j, k)
            a = SL[i]
            b = SL[j]
            c = SL[k]
            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=list(map(int,input().split()))

L.sort()
tss=[]
for i in range(N-2):
    for j in range(1,N-i):
        tss.append(L[i]+L[i+j])

num=[]
for i in range(1,N-1):
    for j in range(i,N):
        num.append(j)
        
ans=0
for i in range(len(tss)):
    for j in range(num[i]+1,N):
        if tss[i]>L[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    number_of_bars = int(input())
    bar_list = list(map(int,input().split()))
    print(len(traiangle_maker(bar_list))//3)


def traiangle_maker(bar_list):
    bar_list.sort(reverse=True)
    result_list = []
    for i in range(len(bar_list)):
        for j in range(len(bar_list)):
            if i == j or bar_list[i] < bar_list[j]:
                continue
            minimum_length = bar_list[i] - bar_list[j]
            max_length = bar_list[i] + bar_list[j]
            for k in bar_list:
                if k > minimum_length and k < max_length and k != bar_list[i] and k != bar_list[j]:
                    traiangle = [bar_list[i],bar_list[j],k]
                    result_list.append(traiangle)

    return result_list


main()

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
#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


print(count)

Submission status: Time Limit Exceeded

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

n = int(input())
length = list(map(int, input().split()))
collect = collections.Counter(length)
sticks = list(collect.items())
sticks.sort()
m = len(sticks)
ans = 0

if m == 1:
    ans += sticks[0][1]*(sticks[0][1]-1)*(sticks[0][1]-2)//6

elif m == 2:
    ans += sticks[0][1]*(sticks[0][1]-1)*(sticks[0][1]-2)//6
    ans += sticks[1][1]*(sticks[1][1]-1)*(sticks[1][1]-2)//6
    ans += sticks[0][1]*sticks[1][1]*(sticks[1][1]-1)//2

    if sticks[0][0]*2 > sticks[1][0]:
        ans += sticks[1][1]*sticks[0][1]*(sticks[0][1]-1)//2

else:
    for i in range(m-2):
        sum_2 = 0
        cmb_2 = 0

        if sticks[i][1] > 2:
            ans += sticks[i][1]*(sticks[i][1]-1)*(sticks[i][1]-2)//6

        if sticks[i][1] > 1:
            sum_2 = sticks[i][0]*2
            cmb_2 = sticks[i][1]*(sticks[i][1]-1)//2
            for k in range(i+1, m):
                if sticks[k][0] < sum_2:
                    ans += sticks[k][1]
                else:
                    break
        for j in range(i+1, m-1):
            sum_2 = sticks[i][0]+sticks[j][0]
            cmb_2 = sticks[i][1]*sticks[j][1]
            if sticks[j][1] > 1:
                ans += cmb_2*(sticks[j][1]-1)//2
            for k in range(j+1, m):
                if sticks[k][0] < sum_2:
                    ans += sticks[k][1]
                else:
                    break

print(ans)

Submission status: Time Limit Exceeded

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

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)
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 numpy as np

n = int(input())

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

res = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        npl = np.array(L[j+1:])
        res += len(npl[npl<L[i]+L[j]])

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools



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

L.sort()

ans = 0

for c_i in range(2, N):
    a_i = 0
    while L[c_i] >= L[a_i] + L[c_i - 1] and a_i < c_i - 1:
        a_i += 1
    
    ans += sum([1 if L[comb[0]] + L[comb[1]] > L[c_i] else 0 for comb in itertools.combinations(range(a_i, c_i), 2)])

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(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]) and L[j]<(L[i]+L[k]) and L[k]<(L[i]+L[j]):
        C += 1
        
print(C)

Submission status: Time Limit Exceeded

Solution code:
#from collections import Counter

import numpy as np

n = int(input())
nums = np.zeros(2001, dtype=int)

ls = map(int, input().split(" "))
#ls = Counter(map(int, ls))
#vals = ls.keys()
ls = sorted(ls)
for l in ls:
    nums[l] += 1

vals = [val for val in range(2001) if nums[val] >= 1]
#print(vals)

cumsum = np.cumsum(nums)

#print(cumsum)
##ls = list(ls)
#ls = np.asarray(ls)
#out = 0
#for i in range(n-1):
#    a = ls[i]
#    for j in range(i+1, n-1):
#        b = ls[j]
#        cur_ls = ls[j+1:]
#        #print(cur_ls, a+b)
#        cur_num = (cur_ls < a+b).sum()
#        out += cur_num

out = 0

a_counts = np.zeros(2001, dtype=int)
for i in range(n-1):
    a = ls[i]
    b_counts = np.zeros(2001, dtype=int)
    a_counts[a] += 1
    for j in range(i+1, n-1):
        b = ls[j]
        b_counts[b] += 1
        if a < b:
            b_count = b_counts[b]
            #print("flag1")
        else:
            assert a == b
            b_count = a_counts[a] + b_counts[b]
            #print("flag2")

        # c > b
        cur_num = max(cumsum[a+b-1] - cumsum[b], 0)
        # c = b
        #print(a, b, nums[b], b_count)
        cur_num += (nums[b] - b_count)

        #print(ls[i], ls[j], cur_num)
        out += cur_num


print(out)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

import bisect
ans = 0
for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        if j!=N-1:
            new_L = L[:i]+L[i+1:j]+L[j+1:]
        else:
            new_L = L[:i]+L[i+1:j]
        t1 = bisect.bisect_right(new_L,a+b-1)
        t2 = bisect.bisect_right(new_L,a-b)
        t3 = bisect.bisect_right(new_L,b-a)
        
        t4 = max(t2,t3)

        if t1!=t4:
            ans += t1-t4
        
ans = ans // 3
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

triangle = 0
b = list((itertools.combinations(L, 3)))
c = list((itertools.combinations(L, 3)))

for i in range(len(c)):
    if (c[i][0] < c[i][1] + c[i][2]
            and c[i][1] < c[i][0] + c[i][2]
            and c[i][2] < c[i][1] + c[i][0]):
        triangle += 1

print(triangle)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
L = list(map(int,input().split()))
L.sort(reverse=True)
count = 0
target = list(itertools.combinations(L,3))

for i in target:
	a = i[0]
	b = i[1]
	c = 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 math
def quick_sort(arr):
	""" クイックソート 
	"""
	if len(arr) < 2:
		# 1. 走査する配列長が0か１の場合戻る。
		return arr

	# 2. 走査する範囲の中央の要素をピボットとして選ぶ。
	pivot = math.floor(len(arr)/2)
	pivot_height = arr[pivot]
	left, right = 0, len(arr) - 1

	while(left < right):
		# 3. ピボットと比べ、大きい要素は左へ小さい要素は右へ交換する。
		while(arr[left] < pivot_height):
			# 左側の基準値より大きい位置まで移動
			left += 1
		while(arr[right] > pivot_height):
			# 右側の基準値より小さい位置まで移動
			right -= 1

		if (left < right):
			# leftがrightを超えていない場合、leftとrightを交換
			arr[left], arr[right] = arr[right], arr[left]
		else:
			break
	# 4. 左右２つに配列を分割してこの関数を再帰的に繰り返す。
	arr[:left] = quick_sort(arr[:left])      # ピボットの左側をクイックソート
	arr[left+1:] = quick_sort(arr[left+1:])  # ピボットの右側をクイックソート
	return arr

arr = list(range(10))
src = [7, 2, 5, 3, 1, 6, 9, 4, 8, 0]
N=int(input())
src = list(map( int,input().split()))
#print(src)
  # 

src = quick_sort(src)
#print(dst)
  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
total=0
for L in range(2,N):
  for M in range(1,L):
    for S in range(M):
      if src[S]+src[M]>src[L]:
        total+=1
#        print(src[S],src[M],src[L])
print(total)

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(0,n-2):
    a=L[i]
    bclist=[]
    for j in range(i+1,n):
        bclist.append(L[j])
    m=len(bclist)
    for k in range(0,m-1):
        b=bclist[k]
        totab=a+b
        for p in range(0,m-k-1):
            if bclist[m-p-1] < totab:
                cnt += m-k-p-1
                break
print(cnt)

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)
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=comb(N,3)
for i,j in combinations(l1,2):
  for k in l1:
    if i+j<=k:
      ans-=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    ln = sorted(list(map(int, args[1].split())))

    s = 0
    for i in range(n):
        for j in range(i+1, n):
            for k in range(n-1, j, -1):
                if (
                    (ln[i] < ln[j] + ln[k]) and
                    (ln[j] < ln[i] + ln[k]) and
                    (ln[k] < ln[i] + ln[j])
                ):
                    s += 1

    return str(s)


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
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[c]+L[a]) and L[c] < (L[a]+L[b]):
                    cnt += 1
print(cnt)

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()))
# 昇順ソート
lists.sort()
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]:
        count += 1
      else:
        break
#      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 sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()

from itertools import combinations

lin = list(combinations(li, 3))

point = 0
ima = lin[0][0]
for i in range(len(lin)):
    if lin[i][0] == ima:
        if lin[i][2] < lin[i][0] + lin[i][1]:
            point += 1
        else:
            continue
    else:
        ima = lin[i][0]
        if lin[i][2] < lin[i][1] + lin[i][0]:
            point += 1

print(point)

Submission status: Time Limit Exceeded

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

num_pattern = 0

for stick_1 in range(N):
	a = sticks[stick_1]

	for stick_2 in range(stick_1 + 1, N):
		b = sticks[stick_2]

		for stick_3 in range(stick_2 + 1, N):
			c = sticks[stick_3]

			if c < a + b:
				num_pattern += 1
			else:
				break

print(num_pattern)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int,input().split()))
import itertools
lst = list(itertools.combinations(l,3))
cnt = 0
for i in range(len(lst)):
    if lst[i][0]+lst[i][1] > lst[i][2] and lst[i][1]+lst[i][2] > lst[i][0] and lst[i][0]+lst[i][2] > lst[i][1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = input().split()
sum = 0
tri = itertools.combinations(L, 3)
for t in tri:
    a, b, c = map(int, t)
    if(a + b > c and b + c > a and c + a > b):
        sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted(list(map(lambda x: int(x)*2,input().split())))
s = 0
for i in range(2,N):
  for j in range(1,i):
    X = L[i]-L[j]+1
    l = 0
    r = j-1
    if L[0] > X:
      s += j
      continue
    if L[j-1] < X:
      continue
    while (r-l)>1:
      e = int((l+r)/2)
      print(e)
      if L[e] < X:
        l = e
      else:
        r = e
    s += (j-r)
print(s)

Submission status: Time Limit Exceeded

Solution code:
n, *l = map(int, open(0).read().split())
sl = sorted(l,reverse=True)
#print(sl)
ans = 0
for i in range (n):
  for j in range (i+1,n):
    if sl[i]-sl[j] < sl[j]:
      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 = list(map(int, input().split(" ")))
L.sort() #小さい順
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 j + k <= i:
            continue
          else:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
count = 0
l.sort(reverse=True)
for i in range(n-2):
  for j in range(i+1,n-1):
    tmp = [k for k, x in enumerate(l[(j+1):]) if x > l[i]-l[j]]
    if len(tmp) != 0:
      count += tmp[-1]+1
print(count)

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):
            if l[i] < l[j] + l[k]:
                ans += 1
            else:
                break

print(ans)

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 L[i] < L[j]*2:
            rest = L[i] - L[j]
            L.append(rest)
            L = sorted(L, reverse=True)
            x = L.index(rest)
            total = total + (x-j-1)
            L.remove(rest)
        else:
            break
print(total)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = list(map(int , input().split()))
c = combinations(s ,3)
ans = 0
for i in c:
    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()))

L.sort()

ans = 0

for i in range(N):
  for j in range(i+1, N):
    for k in range(N-1, j, -1):
      if(L[i]+L[j]> L[k]):
        ans += k - (j)
        break
      # else:
      #   break

print(ans)

Submission status: Time Limit Exceeded

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