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())
ls = [int(x) for x in input().split()]
ts = set()

ls.sort()
ls.reverse()
 
for i in range(0, n -2):
	a = ls[i]
	for j in range(i + 1, n - 1):
		b = ls[j]
		c = ls[j + 1]
		
		if a + b <= c or a + c <= b or b + c <= a:
			break
		
		ts.add((a, b, c))
		
		for k in range(j + 2, n):
			c = ls[k]
		
			if a + b <= c or a + c <= b or b + c <= a:
				break
		
			ts.add((a, b, c))
		
print(len(ts))

Submission status: Time Limit Exceeded

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

result = 0

for aIndex,a in enumerate(L):
    for bIndex,b in enumerate(L[aIndex+1:]):
        for c in L[aIndex+bIndex+2:]:
            if a<b+c and b<a+c and c<a+b:
                result+=1
            else:
                break

print(result)

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

Submission status: Time Limit Exceeded

Solution code:
import math
import bisect
import copy

n = int(input())

list1 = list(map(int,input().split()))
list1.sort()
cout = 0
m,k = 0,0
for i in range(n-2):
	o = list1.pop(0)
	list1_c = copy.deepcopy(list1) #ここでjのためのdeepcopyを更新
	for j in range(len(list1)):
		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

print(cout)

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)

#print(L)
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if L[i] >= L[j] * 2:
            break
        for k in range(j+1, N):
            #print(L[i], L[j], L[k])
            if L[i] >= L[j] + L[k]:
                break
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

triangles =[]
ans =0


for v in itertools.combinations(bou, 3):
    if (v[0]<v[1]+v[2])and(v[1]<v[0]+v[2])and(v[2]<v[1]+v[0]):
        ans+=1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
ls = sorted(map(int, input().split()))

count = 0
# 1辺
for i in range(n - 2):
    # 2辺
    for j in range(i + 1, n - 1):
        border = ls[i] + ls[j]

        if ls[-1] < border:
            count += n - 1 - j
            continue

        # 3辺
        for k in range(j + 1, n):
            if ls[k] >= border:
                break

            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
rl = sorted(l, reverse=True)
co = 0


for a in range(n-2):
    for b in range(a+1,n-1):
        for i,v in enumerate(rl[:n-b]):
            if l[a]+l[b] > v:
                co += n-b-(i+1)
                break
            


print(co)

Submission status: Time Limit Exceeded

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

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


def chker(slist):
    slist.sort(reverse=True)
    a = list(itertools.combinations(slist, 3))
    a = [item for item in a if item[0] < item[1] + item[2]]
    print(len(a))


chker(llist)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import heapq
import sys
readline = sys.stdin.readline
# readlines = sys.stdin.readlines
N = int(readline())
#ls = list(map(int, readline().split()))
ls = list(map(lambda x: int(x) * (-1), readline().split()))
#ls *= 100
#N *= 100
heapq.heapify(ls)
ans = 0
# n_comb = N * (N-1) * (N-2) / 6

import copy
copy_ls = copy.deepcopy(ls)
for i in range(N):
    max1 = -(heapq.heappop(ls))
    copy_ls1 = copy.deepcopy(ls)
    #print(ls)
    for j in range(N-i-1):
      # print(j, ls)
      max2 = -(heapq.heappop(ls))
      for _ in range(N-i-j-2):
        max3 = -(heapq.heappop(ls))
        if (max1 < max2 + max3):
          #print(max1, max2, max3)
          ans += 1
        else:
          # print('break')
          ls = copy.deepcopy(copy_ls1)
          heapq.heappop(ls)
          break
      ls = copy.deepcopy(copy_ls1)
      heapq.heappop(ls)
      copy_ls1 = copy.deepcopy(ls)
    
    # print('loop end')    
    ls = copy.deepcopy(copy_ls)
    heapq.heappop(ls)
    copy_ls = copy.deepcopy(ls)

print(ans)

Submission status: Time Limit Exceeded

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


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


for i in range(n):
    for j in range(i+1, n):
        a = Ls[i]
        b = Ls[j]
        M = [Ls[m] for m in range(j+1, n)]
        if M:
            if a - b >= max(M) or b - a >= max(M) or min(M) >= a + b:
                continue
        for k in range(j+1, n):
            if check(a, b, Ls[k]):
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# n = int(input())
n = int(input())
# s = list(input())
# a,b,c = map(int, input().split())
l = list(map(int, input().split()))

ans = 0

for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      # print(i,j,k)
      a = l[i]
      b = l[j]
      c = l[k]
      if a < b+c and b < c + a and c < a+b:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
n = int(raw_input())
li = map(int, raw_input().split())
li.sort(reverse=False)

count = 0

for i in xrange(n):
    for j in xrange(i+1,n):
        for k in xrange(j+1,n):
            if li[i] < li[j] + li[k] and li[j] < li[i] + li[k] and li[k] < li[i] + li[j]:
                count +=1
            else:
                break
print count

Submission status: Time Limit Exceeded

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

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]*2:
      break
    else:
      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:
import sys

N = int(sys.stdin.readline())
L = tuple([int(x) for x in sys.stdin.readline().split()])

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 L[i] + L[j] <= L[k] or L[j] + L[k] <= L[i] or L[k] + L[i] <= L[j]:
                pass
            else:
                answer += 1

print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
import bisect
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        x = bisect.bisect_left(l[j+1:],l[i]+l[j])
        ans += x
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect



def find_num(lst, num):
    insert_index = bisect.bisect_left(lst, num)
    return insert_index


n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        cnt += find_num(lst=l[j+1:], num=l[i] + l[j])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

import numpy as np

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


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


print(
    (
        ((Ls[:, 1] + Ls[:, 2] - Ls[:, 0]) > 0)
        & ((Ls[:, 0] + Ls[:, 1] - Ls[:, 2]) > 0)
        & ((Ls[:, 2] + Ls[:, 0] - Ls[:, 1]) > 0)
    ).sum()
)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import timeit

def main():
    N = int(input())
    L = sorted([int(x) for x in input().split()])
    ans = 0
    for i , length in enumerate(L):
        # lengthの長さの棒を1本使う
        # 残り2本の差がlength未満 = 三角形ができる
        if length <= 1:
            continue
        elif i > N - 2:
            break
        for a, b in itertools.combinations(L[i+1:], 2):
            if abs(a - b) < length:
                ans += 1
    print(ans)

if __name__ == "__main__":
    # print(timeit.timeit(lambda: main(), number=1))
    main()

Submission status: Time Limit Exceeded

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


def main():
    n = int(input())
    l = np.array(list(map(int, input().split())))
    l = np.sort(l)

    result = 0
    # print(l)
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            target = l[j + 1:]
            count = sum(1 for x in target if x < (l[i] + l[j]))
            # count = np.count_nonzero(target < (l[i] + l[j]))
            # print(l[i], l[j], target, count)
            result += count

    print(result)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
L = sorted(map(int, input().split()))
# print(L)
# L = [1, 2, 3, 4]
# N = len(L)
S = 0
for i in range(N):
    a = L[i]
    for k in range(i - 1):
        c = L[k]
        j = bisect.bisect_left(L, a - c - 1)
        j = max(k + 1, j)
        while True:
            if a < L[j] + c:
                break
            j += 1
        if j >= i:
            continue
        # print(k, j, i)
        S += i - j

print(S)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(n-2):
  for j in range(1,n-i-1):
    tmp = a[i] + a[i+j]
    k=1
    while i+j+k<n and a[i+j+k] < tmp:
      k += 1
      sum += 1

print(sum)

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-2):  
    a = length[i]
    for j in range(i+1,n-1):
        b = length[j]
        if i >= j:
            continue
        else:
            c_candidates = length[j+1:]
            max_bar = bisect.bisect_left(c_candidates,a+b)
            ans += max_bar
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] < h[j] + h[k] and h[j] < h[i] + h[k] and h[k] < h[j] + h[i]:
                    x = x + 1
    return x
print(triangle(n,h))

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n = int(input())
    l = sorted(map(int, input().split()))
    m = [1 if l[k]<l[i]+l[j] else 0 for i in range(n) for j in range(i+1,n) for k in range(j+1,n)]
    print(sum(m))
    
    
if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = list(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):
			if ls[i] < ls[j] + ls[k] and ls[j] < ls[k] + ls[i] and ls[k] < ls[i] + ls[j]:
				count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


bokus = []
for _ in range(N):
    bokus.append([0] * N)
    
for i in range(N-1):
    for j in range(i+1, N):
        bokus[i][j] = int(L[i]) + int(L[j])
# print(bokus)

kouho = []
for i in range(N):
    li = int(L[i])
    for j in range(N-1):
        if i == j:
            continue

        for k in range(len(bokus[j])):
            if bokus[j][k] == 0:
                continue

            if li < bokus[j][k]:
                kouho.append(sorted([i, j, k]))
# print(kouho)
count = 0
while len(kouho) > 0:
    tmp = kouho[0]
    if kouho.count(tmp) == 3:
        count += 1
    kouho.remove(tmp)
# print(kouho.most_common(3))
print(count)

Submission status: Time Limit Exceeded

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

cnt=0

L=sorted(L0)

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[a]+L[b]:
                  cnt+=1
            else:
                break
            
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if li[k] >= li[i] + li[j]:
                continue
            elif li[j] >= li[k] + li[i]:
                continue
            elif li[i] >= li[j] + li[k]:
                continue
            else:
                total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def main():
    _ = int(input())
    L = list(map(int, input().split()))

    comb = itertools.combinations(L, 3)

    ans = 0
    dp = []
    for v in comb:
        if dp.__contains__(sum(v)):
            ans += 1
        elif v[0] < v[1] + v[2] and v[1] < v[2] + v[0] and v[2] < v[0] + v[1]:
            ans += 1
            dp.append(sum(v))

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

L.sort()

num_triangles = 0
for i in range(0, N - 2): # 0, 1, ..., N - 3
    for j in range(i + 1, N - 1): # i+1, i+2, ..., N-2
        num_triangles += bisect.bisect_left(L[j + 1:N], L[i] + L[j])

print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:

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

counter=0

for i in l_list:
	for j in l_list:
		for k in l_list:
			if (i<j<k)&(i<j+k)&(j<i+k)&(k<i+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,reverse = True)
for i in range(n-2):
  i_over = False
  for j in range(i+1,n-1):
    for k in range(j + 1,n):
      if l[i] >= l[j]+l[k]:
        break
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

L.sort()

sum = 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 c >= a+b:
                break
#            print "a,b,c = ", a,b,c                                                                                                                     
            sum = sum + 1

print sum

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
ans=0
len_L=len(L)
for i in range(len_L):
    a=L[i] 
    for j in range(i+1,len_L):
        b=L[j]
        for k in range(j+1,len_L):
            c=L[k]
            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()))
S=0
L.sort()
C=list(itertools.combinations(L,3))
for i in range(len(C)):
    if C[i][0]+C[i][1]>C[i][2]:
        S+=1
print(S)

Submission status: Time Limit Exceeded

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

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

l.sort()

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

if ans<0:
    ans=0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
cnt = 0
j=0
k=1
l=2
while(j<=N-3):
    if L[j]<(L[k]+L[l]) and L[k]<(L[l]+L[j]) and L[l]<(L[j]+L[k]):
        cnt+=1
    l+=1
    if k!=N-1 and l==N:
        k+=1
        l=k+1
    if k==N-1:
        j+=1
        k=j+1
        l=k+1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
L_dat = list(map(int,input().split()))
L_n = np.array(L_dat)
L = np.sort(L_n)
 
cnt = 0
for i in range(N-2):
  A = L[i]
  break_number = i+2
  if not i == 0:
    break_number = break_first
  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
        if j == i+2:
          break_first = k
        break
      if k == N-1:
        cnt += N - 1 - j
        break_number = k
        if j == i+2:
          break_first = k
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l_l.sort()
#print(l_l)

count=0
for i in range(n):
  for j in range(i+1,n):
    for k in range (j+1,n):
      #print(l_l[i],l_l[j],l_l[k])
      if(l_l[i]+l_l[j]<=l_l[k]):
        #print(l_l[i],l_l[j],l_l[k])
        count +=1
      #else:
        #break
      
print(int(n*(n-1)*(n-2)/6-count))

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 i in range(len(list(itertools.combinations(l_list, 3)))):
for set_tri in list(itertools.combinations(l_list, 3)):
#    print(set_tri)
    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())
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 k == n-1:
                if sl[i]+sl[j] > sl[k]:
                    cnt += k-j
            elif sl[i]+sl[j] > sl[k]:
                continue
            else:
                cnt += k-j-1
                break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
N = int(input())
L = list(map(int, input().split()))
sinL = deepcopy(L)
# ans = 0
ansList = []
for x in range(N):
    L = deepcopy(sinL)
    a = L.pop(x) # ★
#     print("a={}".format(a))
    lengthOfL1 = len(L) # 注意 実際の-1
    
    for y in range(lengthOfL1):
#         print(L)
        b = L.pop(y) # ★ 後で挿入しないと！！！
        lengthOfL2 = len(L)
        # a+b を超えないやつを全部切る。
        wa = a + b
        L_censored = [i for i in L if i < wa]
#         print(L_censored)
        if len(L_censored) == 0:
            pass
        else:
            lengthOfL2 = len(L_censored)

            for c in L_censored:
                if b+c <= a:
                    pass
                else:
                    if c+a <= b:
                        pass
                    else:
                        #ans += 1
                        ansList.append([a,b,c])
#                         print(ansList)
        L.insert(y, b)
# print("ahoo")
# print(ansList)
sortedAnsList = map(sorted, ansList)
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
print(len(get_unique_list(sortedAnsList)))

Submission status: Time Limit Exceeded

Solution code:
def calc(a, b, c):
  if abs(b-c) < a and a < b+c:
    return 1
  return 0

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):
      conter += calc(l[i],l[j],l[k])
print(conter)

Submission status: Time Limit Exceeded

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

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

a = 0
n = 0

for x in range(len(l)):
  m = max(l[n])
  if m < sum(l[n]) - m:
    a += 1
    n += 1
  else:
    n += 1
    
print(a)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

result = 0
for i in itertools.combinations((data), r=3):
  diff0 = i[0] - (i[1] + i[2])
  diff1 = i[1] - (i[0] + i[2])
  diff2 = i[2] - (i[0] + i[1])
  if diff0 < 0 and diff1 < 0 and diff2 < 0:
    result += 1

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ln = list(sorted(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 ln[i] >= ln[j] + ln[k]:
                continue
            if ln[j] >= ln[k] + ln[i]:
                continue
            if ln[k] >= ln[i] + ln[j]:
                continue
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=raw_input()
LN=raw_input().split()

n = int(N)
ln = [int(i) for i in LN]

c = [[x, y, z] for x in range(n) for y in range(n) for z in range(n) if x > y and y > z]

r = []
for i in c:
    x, y, z = i
    a = ln[x]
    b = ln[y]
    c = ln[z]
    if not a < b + c:
        continue
    if not b < c + a:
        continue
    if not c < a + b:
        continue
    r.append(i)

print len(r)

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
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		elif listl[j]+listl[j+1]<=listl[i]:
			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:
# -*- coding: utf-8 -*-

if __name__ == "__main__":

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

	c = N * (N-1) * (N-2) // 6

	count = 0
	for i in range(0, N):
		for j in range(i + 1, N):
			for k in range(N - 1, j, -1):
				if L[i] + L[j] > L[k]:
					break
				count += 1
	
	print(c - count)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
L = list(map(int,input().split()))
B = []
s = 0
for i in range(N-2):
    for k in range(i+1,N-1):
        for _ in range(k+1,N):
            if L[i]-L[k]<L[_] and L[k]-L[i]<L[_] and L[_]<L[i]+L[k]:
                s = (L[i]+L[k]+L[_])/2
                B.append(math.sqrt(s*(s-L[i])*(s-L[k])*(s-L[_])))
k = set(B)
k = list(k)
print(len(k))

Submission status: Time Limit Exceeded

Solution code:
import itertools
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):
#      #print(str(i) + str(j) + str(k))
#      if L[i] < L[j] + L[k] and abs(L[j] - L[k]) < L[i]:
#        ans += 1
#print(ans)
comb = list(itertools.combinations(L, 3))
comb = list(map(list, comb))
for i in range(len(comb)):
  if comb[i][0] < comb[i][1] + comb[i][2] and abs(comb[i][1] - comb[i][2]) < comb[i][0]:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

result = 0

for i in range(N):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[k] < (L[i]+L[j]) and L[k] > (L[j]-L[i]):
        result += 1
      else:
        break
    #tmp = L[j+1::]
    #print(tmp)
    #result += np.sum(x<(L[i]+L[j]) and x>(L[j]-L[i]) for x in tmp)
    #print(result)

print(result)

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):
    m = 0
    for n in range(3):
        if int(triangle[0 - n]) >= int(triangle[1 - n]) + int(triangle[2 - n]):
            m = 1
            break
    if m == 0:
        triangle_num += 1
print(triangle_num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations
import bisect
import math
import numpy as np
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
count_ls = np.zeros(2*10**3, dtype=np.int)
for combi in combinations(l_ls, 2):
    count_ls[combi[0] + combi[1]:] += 1
    #bisect.insort_left(_sum_ls, combi[0] + combi[1])
len_sum_ls = len(_sum_ls)
for l in l_ls:
    #ind = bisect.bisect_right(_sum_ls, l)
    ind = count_ls[l]
    cnt += ind
print(int(math.factorial(n) / math.factorial(3) / math.factorial(n-3)) - cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l = list(map(int,input().split()))	
l.sort()
ans=0
if l[0]+l[1]>l[n-1]:
    print((n*(n-1)*(n-2))//6)
    exit()
else:
    for i in range(n-2):
        for j in range(n-i-2):
            j+=i+1
            if l[i]+l[j]>l[n-1]:
                ans+=((n-j-1)*(n-j))//2
                break
            for k in range(n-j-1):
                k+=j+1
                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.sort()
cnt = 0

# print(l)

for i in range(n):
	a = l[i]
	for j in range(i+1, n):
		b = l[j]
		# print("a,b:",a,b)
		c1 = -1
		c2 = -1
		for k in range(j+1, n):
			if b-a < l[k]:
				c1 = k
				break
		# print("c1:",c1)
		if c1 == -1: break
		for k in range(n-1, c1-1, -1):
			if b+a > l[k]:
				c2 = k
				break
		# print("c2:",c2)
		if c2 == -1: continue
		cnt += c2-c1+1
		# print("cnt:",cnt)

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import heapq

n = int(input())
l = list(map(int,input().split()))
l = list(map(lambda x: x * (-1), l))
heapq.heapify(l)

ans = 0
while len(l) >= 3:
    mx = heapq.heappop(l) * (-1)
    for i in range(len(l)-1):
        for j in range(len(l))[i+1:]:
            if mx < (l[i] + l[j]) * (-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):
    L1 = L[i]
    for j in range(i+1, N):
        L2 = L[j]
        sumL = L1 + L2
        for k in range(j+1, N):
                if L[k] < sumL:
                    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)
count = 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]:
                count += 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-2):
    for j in reversed(range(i+2,n)):
        gap = l[i]-l[j]
        if l[j-1] > gap:
            ans += (j-i)*(j-i-1)//2
            break
        elif l[i+1] < gap:
            break
        else:
            for k in reversed(range(i+1,j)):
                if l[k] > gap:
                    ans += k-i
                    break
 
print(ans)