Problem:


Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#print(N)
#print(l_list)

cnt = 0
for a in range(N):
    for b in range(N):
        if a >= b:
            continue
        for c in range(N):
            if b >= c:
                continue
            #print(a, b, c)
            if l_list[a] < (l_list[b] + l_list[c]) and \
                l_list[b] < (l_list[c] + l_list[a]) and \
                l_list[c] < (l_list[a] + l_list[b]):
                cnt = cnt + 1
            #if not a == b or b == c or c == a:

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdout
import bisect
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
l = inl()
acc = 0
l.sort()
for i in range(n-2):
  a = l[i]
  for j in range(i+1,n-1):
    b = l[j]
    e = bisect.bisect_left(l,a+b)
    ddprint("a {} b {} i {} j {} e {}".format(a,b,i,j,e))
    acc += e-j-1
print(acc)

Submission status: Time Limit Exceeded

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

ans = 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):
            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:
def check(a,b,c):
    if a < b+c:
        if b < a+c:
            if c < a+b:
                return 1
    return 0

N = int(input())
l = input()
l = list(map(int,l.split()))
#all_list = list()
all_num = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            all_num += check(l[i],l[j],l[k])
            #if check(l[i],l[j],l[k]) == 1:
                #all_list.append([l[i],l[j],l[k]].sort)
#print(len(all_list))
print(all_num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
for i, l1 in enumerate(L):
    a = l1
    for k, l2 in enumerate(L[i+1:]):
        b = l2
        num = i + k + 2
        if num >= n:
            continue
        while L[num] < a + b:
            c = L[num]
            if a < b + c and b < a + c and c < b + a:
                count += 1
            num += 1
            if num == n:
                break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
import itertools 
combi = itertools.combinations(L, 3)
wa = 0
for c in combi:
    if(c[0] < c[1] + c[2] and c[0] > abs(c[1] - c[2])):
        wa +=1
print(wa)

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
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def check(a):
    if sum(a) > 2 * sum(a):
        return False
    else:
        return a[0] < a[1] + a[2] and a[1] < a[0] + a[2] and a[2] < a[0] + a[1]

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

# print(sum([1 if check(comb) else 0 for comb in itertools.combinations(L, 3)]))

ans = 0
for comb in itertools.combinations(L, 3):
    ans += 1 if check(comb) else 0

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

Submission status: Time Limit Exceeded

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

#print(l)
co=0
for i in range(n-2):
    c=l[i]
    x=0
    for j in range(i+1,n-1):
        b=l[j]
        for k in range(j+1,n):
            a=l[k]
            if c<(a+b):
                co+=1
            else:
                if k==j+1:
                    x=1
                break
        if x==1:
            break

print(co)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

def D():
    n = input()
    l = list(map(int,input().split(" ")))
    temp = list(itertools.combinations(l,3))
    count = 0
    #print(temp)
    for i in temp:
        if i[0] < i[1]+i[2] and i[1] < i[0]+i[2] and i[2] < i[0]+i[1]:
            count += 1
    print(count)

if __name__ == '__main__':
    D()

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import*
from itertools import*
n,*L=map(int,open(0).read().split())
L.sort()
ans=0
for x,y in combinations(L,2):
	low=abs(x-y)
	high=x+y
	ans+=bisect_left(L,high)-bisect(L,low)
	if low<x<high:
		ans-=1
	if low<y<high:
		ans-=1
print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
l=sorted(list(map(int,input().split())),reverse=True)
ans,tmp=0,0
ls=[sum(i) for i in list(itertools.combinations(l,2))]
for i in range(n-2):
    tmp+=n-1-i
    ans+=sum([j>l[i] for j in ls])-tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

#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

print(out)

Submission status: Time Limit Exceeded

Solution code:

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


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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = input()
lengths = map(int, input().split())

len_combs = list(itertools.combinations(lengths, 3))
res = sum([a < b + c and b < c + a and c < a + b for a, b, c in len_combs])

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
stick = list(map(int, input().split()))
combi = itertools.combinations(stick, 3)
ans = [1 for a,b,c in combi if a < b+c and b < c+a and c < a+b]
print(len(ans))

Submission status: Time Limit Exceeded

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

L.sort()
diff_L=[]

for i in range(1,N-1):
    diff=[]
    for j in range(i+1,N):
        diff.append(L[j]-L[i])
    diff_L.append(diff)
    
total=0
for i in range(N-2):
    for j in range(i,N-2):
        for elem in diff_L[j]:
            if elem < L[i]:
                total += 1
            else:
                break
print(total)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()

    ans = 0
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            A = L[i]
            B = L[j]

            minC = max(A - B, B - A)
            maxC = A + B

            left = bisect_right(L, minC)
            right = bisect_left(L, maxC)

            ans += right - left

            if left <= i < right:
                ans -= 1
            if left <= j < right:
                ans -= 1

    print(ans // 6)


sol()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
l = list(map(int, input().split()))
answer = 0
for a, b, c in combinations(l, 3):
    if a < b + c and b < a + c and c < a + b:
        answer += 1
print(answer)

Submission status: Time Limit Exceeded

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

input = sys.stdin.readline


def main():
    N = int(input())
    L = list(map(int, input().split()))
    min_l = min(L)

    ans = 0

    for a in range(N):

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

            for c in range(b+1, N):
                if L[a] < L[b] + L[c] and L[b] < L[c] + L[a] and L[c] < L[a] + L[b]:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
""" nC3 のすべての組み合わせに対して、三角形が成立するかを調べると、O(n^3)で計算量がだめ
ソートしてから、maxの辺を固定する
他の２つのへんをfor loop *２で回すが、a >= b + c になった段階でbreakする
この時の計算量はo(n^3)だけど半分くらいに減るはず。
これでTLEするか試す
"""
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    for k in range(j-1,-1,-1):
      ans += 1
      if l[i] >= l[j] + l[k]:
        ans -= 1
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
array = list(map(int, input().split()))
count = 0
array.sort(reverse = True)
for a in range(n):
    A = array[a]
    for b in range(a+1,n):
        B = array[b]
        for c in range(b+1,n):
            C = array[c]
            if A - B - C < 0:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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


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

    ans = 0
    for i, a in enumerate(l_list):
        for j, b in enumerate(l_list[i+1:]):
            for k, c in enumerate(l_list[i+1+j+1:]):
                # if i == j or j == k or k == i:
                #     continue
                if is_ok(a, b, c):
                    ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            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:
import itertools

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

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

res = [ 0 for a, b, c in combi_list if a < b + c and b < c + a and c < a + b]

print(len(res))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
L  = sorted(LI())
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        ret += bisect_left(L[j + 1:], L[i] + L[j]) - bisect_right(L[j + 1:], abs(L[i] - L[j]))
        a = L[j + 1:]


print(ret)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = 0
paris = list(itertools.combinations(L[1:], 2))
for i, a in enumerate(L[:-2]):
    count += sum([(a < b + c) * (b < c + a) * (c < a + b) for b, c in paris])
    del paris[:(N-i-2)]
print(count)

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):
    a = Ls[i]
    for j in range(i+1, n):
        b = Ls[j]
        for k in range(j+1, n):
            c = Ls[k]
            if check(a, b, c):
                cnt += 1


print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for a in range(N-2):
    for b in range(a + 1, N-1):
        for c in range(b + 1, N):
            if (abs(d[a]-d[b]) < d[c]) and (d[c] < d[a] + d[b]):
                num += 1

print(num)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

from itertools import combinations
lin = list(combinations(li, 3))

point = 0
for i in range(len(lin)):
    if lin[i][0] < (lin[i][1] + lin[i][2]) and lin[i][1] < (lin[i][2] + lin[i][0]) and lin[i][2] < (lin[i][1] + lin[i][0]):
        point += 1
print(point)

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)

ans = 0
for a in range(N):
    flgb = True
    for b in range(a+1,N):
        flgc = True
        for c in range(N-1,b,-1):
            if L[c]+L[a] <= L[b]:
                flgb = False
                break
            if L[a]+L[b] <= L[c]:
                flgc = False
                break
            if (L[a] < L[b] + L[c]) and (L[b] < L[a] + L[c]):
                ans += 1
        if not flgb: break
        if not flgc: break
    if not flgb: break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

xx = itertools.combinations(L, 3)
cnt = 0
for x in xx:
    if x[0] < x[1] + x[2] and \
       x[1] < x[2] + x[0] and \
       x[2] < x[0] + x[1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
temp_sum = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        
        # print(temp_sum)
        for k in range(j+1,n):
            if l_list[k] < l_list[i] + l_list[j]:
                temp_sum += 1
            else:
                break


print(temp_sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
l = list(map(int, input().split()))
l.sort()
total = 0
result = 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[i] + l[j]:
                result +=1
            total += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
def isTriangle(x,y,z):
    return x+y>z and x+z > y and y+z >x


n = int(input())

l = [int(x) for x in input().split()]

ans = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if isTriangle(l[i],l[j],l[k]):
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=list(map(int,input().split()))
count=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      if d[k]<d[i]+d[j] and d[k]!=d[i] and d[i]!=d[j] and d[j]!=d[k] and d[j]<d[i]+d[k] and d[i]<d[k]+d[j]:
        count+=1
print(int(count/6))

Submission status: Time Limit Exceeded

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

li.sort()

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


def d():
    _ = int(input())
    ls = list(map(int, input().split()))
    combs = list(itertools.combinations(ls, 3))
    count = 0
    a = 0
    b = 1
    c = 2

    for comb in combs:
        if comb[a] < comb[b] + comb[c] and comb[b] < comb[c] + comb[a] and comb[c] < comb[a] + comb[b]:
            count += 1
    print(count)


if __name__ == '__main__':
    d()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
Ls = map(int, input().split())
seq = itertools.combinations(Ls, 3)
ans = 0
for s in seq:
    a, b, c = s
    if a < b + c and b < a + c and c < a + b:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

L.sort()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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

    ret = (a < (b + c)) and (b < (c + a)) and (c < (a + b))
    if ret:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


def check(a):
    if sum(a) > 2 * sum(a):
        return False
    else:
        return a[0] < a[1] + a[2] and a[1] < a[0] + a[2] and a[2] < a[0] + a[1]

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

print(sum([1 if check(comb) else 0 for comb in itertools.combinations(L, 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+2,N):
    C = L[j]
    for k in range(i+1,j):
      if L[k] > C - A:
        
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sticks = [int(s) for s in input().split()]
point = 0
for i in range(n-2):
  for j in range(n - i-1):
    for k in range(n - i - j -2):
      a=sticks[i]
      b=sticks[i+j+1]
      c=sticks[i+j+k+2]
      box = sorted([a,b,c])
      if box[2] < box[0]+box[1]:
        point+=1
print(point)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
numbers = [int(i) for i in input().split()]
count = 0
for x in range(n):
    for y in range(x+1,n):
        for z in range(y+1,n):
            a = numbers[x]
            b = numbers[y]
            c = numbers[z]
            if max([a,b,c])<sum([a,b,c])/2:
                count+=1
print(count)

Submission status: Time Limit Exceeded

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


ans=0
for com in list(itertools.combinations(l,3)):
    if com[0]+com[1]>com[2] and com[2]+com[1]>com[0] and com[2]+com[0]>com[1]:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

ans=0

for n in range(0,N-2):
    for o in range(n+1, N-1):
        for p in range(o+1, N):
            if (L[n] < L[o] + L[p]) and (L[o] < L[p] + L[n]) and (L[p] < L[n] + L[o]):
                ans += 1
                
print(int(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
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 i in range(1,n-1):
    base = l_dict[i]
    next_base = l_dict[i+1]
    for l in l_ls[:i]:
        bisect.insort_left(_sum_ls, l + base)
    for _sum in _sum_ls[::-1]:
        if next_base < _sum:
            cnt += 1
        else:
            break
print(cnt)

Submission status: Time Limit Exceeded

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

_ = input()
rods = list(map(int,input().split()))

num = 0
import itertools
for a,b,c in itertools.combinations(rods, 3):
	if is_triangle(a,b,c):
		num += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        a = L[i]+L[j]
        ind = bisect.bisect_left(L[j+1:],a)
        cnt += ind
print(cnt)

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 = list(map(int, input().split()))
    index = np.argsort(l)

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

    print(result)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
L = list(map(int,input().split()))
L.sort()
ans =0
for i in range(n):
  for j in range(i+1,n):
    L_ = L[j+1:]
    ans += bisect.bisect_left(L_,L[i]+L[j])-bisect.bisect_right(L_,abs(L[i]-L[j]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    list = [int(i) for i in input().split()]
    list.sort(reverse=True)
    ans = 0
    for i in range(n):
        li = list[i]
        if i > n-1:
            break
        for j in range(n):
            lj=list[j]
            if j>i:
                if j > n:
                    break
                for k in range(n):
                    lk = list[k]
                    if k > j:
                        if li < lj+ lk:
                            ans = ans +1
                        else:
                            break
    print(ans)

Submission status: Time Limit Exceeded

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

Ls = sorted(Ls)
cnt = 0
for i in range(N):
    l1 = Ls[i]
    for j in range(i+1, N):
        l2 = Ls[j]
        cnt += len([l for l in Ls[j+1:] if l <(l1+l2)])
print(cnt)

Submission status: Time Limit Exceeded

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

L.sort()
#print(L)

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1:]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        for k, c in enumerate(L[j+1:]):
            if abs(a-b) < c and c < a+b:
                ans += 1
            if c >= a+b:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
ls = map(int, input().split())
cnt = len(list(filter(lambda x: x[0] < x[1] + x[2] and x[1] < x[2] + x[0] and x[2] < x[0] + x[1], combinations(ls, 3))))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def check(a,b,c):
    if a < b+c:
        if b < a+c:
            if c < a+b:
                return 1
    return 0

N = int(input())
l = input()
l = list(map(int,l.split()))
all_list = list()
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if check(l[i],l[j],l[k]) == 1:
                all_list.append([l[i],l[j],l[k]].sort)
print(len(all_list))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in list(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(i)
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import sys

#input = sys.stdin.readline



def main():
#    h,w,a,b = map(int, input().split())
    n=int(input())
    l=list(map(int,input().split()))
    l=sorted(l,reverse=True)
    count=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            for m in range(j+1,n):
                if l[m]>abs(l[i]-l[j]):
                    count+=1
                else:
                    break

    print(count)






if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as co
from sys import stdin
n=int(input())
l=[int(x) for x in stdin.readline().rstrip().split()]
print(len([1 for a,s,d in co(l, 3) if abs(a-s)<d<a+s]))

Submission status: Time Limit Exceeded

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

S1 = set()
for i in range(N):
    a = L[i]
    for j in range(i):
        b = L[j]
        for k in range(j):
            c = L[k]
            if a < b + c:
                S1.add(tuple(sorted((i, j, k))))
S2 = set()
for i in range(N):
    b = L[i]
    for j in range(i):
        c = L[j]
        for k in range(j):
            a = L[k]
            if b < c + a:
                S2.add(tuple(sorted((i, j, k))))
S3 = set()
for i in range(N):
    c = L[i]
    for j in range(i):
        a = L[j]
        for k in range(j):
            b = L[k]
            if c < a + b:
                S3.add(tuple(sorted((i, j, k))))
print(len(S1.intersection(S2).intersection(S3)))

Submission status: Time Limit Exceeded

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

Lsorted = sorted(L)
ret = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      a = Lsorted[i]
      b = Lsorted[j]
      c = Lsorted[k]
      if c >= (a + b):
        break
      if b >= (a + c):
        break
      if a >= (b + c):
        break
      
      ret += 1

print(ret)

Submission status: Time Limit Exceeded

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