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:
def isTriangle(x,y,z):
    return x+y>z 

n = int(input())

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

#print(l)
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:
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()))
    l_list.sort()

    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 is_ok(a, b, c):
                    ans += 1
                else:
                    break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(map(int,input().split()))
counter = 0
for i in range(N):
  for j in range(N-1-i):
    for k in range(N -2 -i -j):
      a = S[i]
      b = S[i+j+1]
      c = S[i+j+k+2]
      if (a + b > c) and (c > abs(a - b)) and (a + b > c):
        counter += 1
    
print(counter)

Submission status: Time Limit Exceeded

Solution code:

if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))

    l = sorted(l, reverse=True)

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

    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it 
 
n = input()
l = list(map(int, input().split()))
 
l.sort()
 
triangles = set()
for a, b, c in it.combinations(l, 3):
    if a + b > c and b + c > a and a + c > b:
        triangles.add((a, b, c))
 
print(len(triangles))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[int(i) for i in 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(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 = list(map(int,input().split()))
L_list = sorted(L_list,reverse=True)
#print(L_list)
result =0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L_list[i] < L_list[j] + L_list[k] and \
                    L_list[j] < L_list[k] + L_list[i] and \
                    L_list[k] < L_list[i] + L_list[j]:
                #print(i,j,k)
                result += 1
            elif L_list[i] >= L_list[j] + L_list[k] or \
                    L_list[j] >= L_list[k] + L_list[i]:
                    break
print(result)

Submission status: Time Limit Exceeded

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

from itertools import combinations


p = list(combinations(ls, 3))

result = 0
for a, b, c in p:
    if a < (b+c) and b < (c+a) and c < (a+b):
        result += 1

print(result)

Submission status: Time Limit Exceeded

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


from itertools import combinations

ans = 0
for a, b, c in combinations(L,3):
    # print(a, b, c)
    if a<b+c and b<a+c and c<a+b:
        ans += 1
        # print(a, b, c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
for r in range(n-1,-1,-1):
  m = r
  for l in range(n):
    if l == m and m + 1 < r:
      m += 1
    while True:
      if a[l] + a[m-1] > a[r] and l < m-1:
        m -= 1
      else:
        break
    if l < m < r:
      ans += r - m
      #print(l,m,r)
print(ans)

Submission status: Time Limit Exceeded

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

#print(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 ((L[i] < L[j]+L[k]) and (L[k] < L[i]+L[j]) and (L[j] < L[k]+L[i])):
        cnt += 1
        #print(L[i],L[j],L[k])
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):
    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:
n = int(input())
l = list(map(int , input().split()))
ans = 0
for i in range(0, 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_list = sorted([int(x) for x in input().split()])
cnt = 0
for i in range(N-2):
    if (L_list[i] == 1): continue
    for j in range(i+1, N-1):
        if (L_list[j] == 1): continue
        for k in range(j+1, N):
            a, b, c = L_list[i], L_list[j], L_list[k]
            if (c < a+b):
                cnt += 1
            else:
                break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ln = [int(n) for n in input().split()]

def check(a,b,c):
    if (a<b+c) and (b<c+a) and (c<a+b):
        return True
    else:
        return False
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if check(Ln[i],Ln[j],Ln[k]):
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N= int(input())


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


from itertools import combinations

c = combinations(d, 3)
ans = 0
for x in c:
    if x[0] < x[1]+x[2] and x[1] < x[0]+x[2] and x[2] < x[1]+x[0]:
        ans += 1
print(ans)

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 abs(com[1]-com[2])<com[0]<com[1]+com[2]:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = list(map(int, input().split()))
l_combination = list(itertools.combinations(l, 3))

answer_sum = 0

for i in l_combination:
    if i[0] < i[1] + i[2]:
        if i[1] < i[0] + i[2]:
            if i[2] < i[0] + i[1]:
                answer_sum += 1

print(answer_sum)

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):
        s = L[i] + L[j]
        if s <= L[j+1]:
            continue
        for k in range(j+1, N):
            if L[i] + L[k] > L[j] and L[j] + L[k] > L[i] and L[i] + L[j] > L[k]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list = input().split()
L = [int(n) for n in list]
sum = 0
for i in range(N):
  for j in range(N):
    if (j != i) & (i > j):
      for k in range(N):
        if (k != i) & (k != j) & (j > k):
          a = L[i]
          b = L[j]
          c = L[k]
          if (a<b+c) & (b<c+a) & (c<a+b):
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L.sort()
	sum = 0
	for c in range(N - 1, 1, -1):
		for b in range(c - 1, 0, -1):
			for a in range(b - 1, -1, -1):
				if L[a] + L[b] > L[c]:
					sum += 1
				else:
					break
	print(sum)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

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

sum = 0
for i1 in range(len(l)):
    for i2 in range(i1+1, len(l)):
        for i3 in range(i2 + 1, len(l)):
            s = sorted([l[i1], l[i2], l[i3]])
            if s[0] + s[1] > s[-1]:
                sum += 1

print(sum)

Submission status: Time Limit Exceeded

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

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

    cond1 = a < (b + c)
    if not cond1:
        continue
    cond2 = b < (c + a)
    if not cond2:
        continue
    cond3 = c < (a + b)
    if not cond3:
        continue

    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

def check_triangle(i, j, k):
    if i < j + k:
        if j < k + i:
            if k < j + i:
                return True
    return False

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


n = int(input())
ls = sorted(read_i(), reverse=True)
res = 0
for i, x in enumerate(ls):
    for j, y in enumerate(ls[i + 1:], i + 1):
        if 2 * y < x:
            break
        res += n - j - 1 - bisect.bisect(ls[j + 1:][::-1], x - y)
print(res)

Submission status: Time Limit Exceeded

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

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

print(result)

Submission status: Time Limit Exceeded

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

l.sort()
cnt = 0
import itertools
import bisect
for a, b in itertools.combinations(l, r=2):
  l_woab = list(set(l) - set([a, b]))
  l_woab.sort()

  if False:
    print(a, b, end=' : ')
    print(l_woab)
    print(bisect.bisect_left(l_woab, a + b ), bisect.bisect_left(l_woab, b))
  
  cnt += max(bisect.bisect_left(l_woab, a + b ) -
             bisect.bisect_left(l_woab, b), 0)

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

l.sort()
count = 0

for i in range(n) :
    for j in range(1, n - i) :
        for k in range(1, n - i - j) :
            if l[i] + l[i + j] > l[i + j + k] :
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(N - 2):
    # print(i)
    for j in range(i + 1, N - 1):
        # print("\t" + str(j))
        for k in range(j + 1, N):

            if int(L[i]) < int(L[j]) + int(L[k]):
                if int(L[j]) < int(L[i]) + int(L[k]):
                    if int(L[k]) < int(L[j]) + int(L[i]):
                        count += 1
            # print("\t\t"+str(k))

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
import numpy as np
A = np.array(list(map(int,input().split())))
count=0

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

Submission status: Time Limit Exceeded

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


print(temp_sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tmp = input()
L = [int(x.strip()) for x in tmp.split(' ')]
L.sort()
count = 0
for i in range (0, N-2):
    p1 = L[i]
    for j in range(i+1, N-1):
        p2 = L[j]
        wa = p1 + p2
        for k in range(j+1, N):
            if wa > L[k]:
                count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import itertools
# 周長は三角形のうちの最大長の2倍よりも大きい

def solve(N: int, L: "List[int]"):
    # N = 5
    # L = [1,2,2,3,4]
    L.sort()
    answer = 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]:
                    answer += 1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

print(num)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def aaa(l):
    x=0
    a=l[0]
    b=l[1]
    c=l[2]
    if a+b>c:
        if b+c>a:
            if c+a>b:
                x=1
    return x
ans=0
for l in list(itertools.combinations(L, 3)):
    ans+=aaa(list(l))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

def f(L):
    n = len(L)
    L.sort()
    count = 0
    # a=3 b=4 c=2, c < a + b => 2 < 3+4
    # a < b + c   =>  a - b < c  =>  c > a - b
    # b < c + a   =>  b - a < c  =>  c > b - a
    # c < a + b
    for i in range(n):
        for j in range(i + 1, n):
            a, b = L[i], L[j]
            start = bisect.bisect_left(L, max(a-b, b-a))
            end = bisect.bisect_left(L, a + b)
            for k in range(start, end):
                assert L[k] < a + b
                assert L[k] > a - b
#                assert L[k] > b - a
                if k != i and k != j and L[k] < a + b:
                    # other two checks
                    if L[k] < a + b and a < b + L[k] and b < L[k] + a:
                        count += 1
    return count // 3

assert f([3, 4, 2, 1]) == 1
assert f([1, 1000, 1]) == 0
assert f([218, 786, 704, 233, 645, 728, 389]) == 23

_N = input()
L = list(map(int, input().split()))
ans = f(L)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = [int(i) for i in input().split()]
print((int)(sum(1 for x in range(a) for y in range(a) for z in range(a) if x!=y and y!=z and x!=z and (b[x]<b[y]+b[z] and b[y]<b[x]+b[z] and b[z]<b[x]+b[y]))/6))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int,input().split()))
L_copy = L[:]

sum = 0
for i in range(N):
  for j in range(N):
    if i != j:
      L_copy = L[:]
      a = L_copy[i]
      b = L_copy[j]
      if a > b:
        #print(a, b)
        L_copy.remove(L[i])
        L_copy.remove(L[j])
        for k in range(len(L_copy)):
          if L_copy[k] > (a - b) and L_copy[k] < (a + b):
            sum += 1
print(int(sum/3))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    L = list(map(int, input().split()))
    sort_L = sorted(L)
    cnt = 0
    for i in range(N):
        for j in range(i+1,N):
            if i == j:
                continue
            for k in range(N-1,max(i,j),-1):
                if sort_L[i] + sort_L[j] > sort_L[k]:
                    cnt += 1

    print(cnt)

    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

x = 0

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = [int(elem) for elem in input().split()]
ls = sorted(ls)

res = 0
for i, elem in enumerate(ls[:-2]):
    for j, elem1 in enumerate(ls[i+1:]):
        for k, elem2 in enumerate(ls[i+j+2:]):
            if elem2 < (elem + elem1):
                res += 1
            else:
                break
print(res)

Submission status: Time Limit Exceeded

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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 sarch(l, left, right, target):
    global ans
    mid = right + left
    mid //= 2
    # print(left, right, target, ans)
    if right - left <= 1:
        if l[right] >= target:
            return right
        if l[left] >= target:
            return left
        else:
            return 0
    if target < l[mid]:
        # print(2)
        return sarch(l, mid, right, target)
    if target == l[mid]:
        return mid
    if l[mid] < target:
        # print(1)
        return sarch(l, left, mid, target)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l = l[::-1]
# print(l)
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        tmp = l[i] - l[j] + 1
        tmp = sarch(l, j + 1, n - 1, tmp)
        # print(tmp, j)
        if tmp > j:
            ans += (tmp - j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
Llist  =[int(i) for i in input().split()]
comblist = list(itertools.combinations(Llist,3))
ct=0
for comb in comblist:
    a = comb[0]
    b = comb[1]
    c = comb[2]
    if a<b+c and b<c+a and c<a+b:
        ct+=1
print(ct)

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from itertools import permutations, combinations,combinations_with_replacement,product
from fractions import Fraction as frac
import bisect
import heapq

import logging
logging.basicConfig(level=logging.DEBUG)

import sys
#input = sys.stdin.readline().rstrip

setrecursionlimit(1000000)

MOD = 10**9+7
INF = float('inf')

def main():
    N=int(input())
    L=[int(x) for x in input().split()]

    C=combinations(L,3)
    ans=0
    for c in C:
        if c[0]<c[1]+c[2] and c[1] < c[2]+c[0] and c[2]<c[0]+c[1]:
            ans+=1
    print(ans)
main()

Submission status: Time Limit Exceeded

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

res = 0

for i in range(N-2):
    L1 = L[i+1:]
    for j in range(len(L1)-1):
        L2 = L1[j+1:]
        for k in range(len(L2)):
            sum = L[i] + L1[j] + L2[k]
            if (sum > 2*L[i]) & (sum > 2*L1[j]) & (sum > 2*L2[k]):
                res += 1

print(res)

Submission status: Time Limit Exceeded

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

answer=0
for i in range(N-2):
  index_c=i+2
  for j in range(i+1,N-1):
    for k in range(index_c,N):
      if L[i]+L[j]<=L[k]:
        #print(i,j,k-1,k-j-1)
        answer+=k-j-1
        index_c=k-1
        break
    else:
      #print(i,j,N-1,N-j-1)
      answer+=N-j-1
      index_c=N-1
        
print(answer)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N = int(input())
L = list(map(int, input().split()))
ans = 0
  
for i, j, k in product(L, L, L):
  if i <= j or j <= k:
    pass
  elif abs(i-j) < k and k < i+j:
    ans += 1
          
          
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0 #n*(n-1)*(n-2) // 6
for i in range(n):
    for j in range(i+1,n):
        if l[i]+l[j] > min(l[j:]):
            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]:
                    #print(l[i],l[j],l[k])
                    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
N = input()
l_list = list(map(int,input().split()))
ans = 0
 
for v in itertools.combinations(l_list, 3):
  v = sorted(v,reverse=True)
  max_len = v[0]
  lens = v[1:]
  if max_len < sum(lens):
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for a in range(n):
    for b in range(a+1, n):
        for c in range(b+1, n):
            #print(a, b, c)
            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)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
d_list = list(map(int, input().split()))
c_d_list = list(itertools.combinations(d_list, 3))
count = 0
for i in c_d_list:
    a = i[0]
    b = i[1]
    c = i[2]
    if a < b + c:
        if b < a + c:
            if c < a + b:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=0
import itertools
v = itertools.combinations(l,3)
for a,b,c in v:
  m=max(a,b,c)
  s=a+b+c
  if m*2<s:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
L = [int(n) for n in input().split()]
C = 0


for l in  list(itertools.combinations(L, 3)):
    # print(l)
    a = l[0]
    b = l[1]
    c = l[2]

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


print(C)

Submission status: Time Limit Exceeded

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	
	n = int(input())
	arr = sorted(map(int, input().split()))
	
	ans = 0
	for i in range(2, n):
		for j in range(i - 1):
			l = j
			r = i
			while r - l != 1:
				if arr[l + r >> 1] + arr[j] > arr[i]:
					r = l + r >> 1
				else:
					l = l + r >> 1
			ans += i - r
	
	print(ans)
	
	return 0

main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
length = len(l)
l.sort()

for i in range(length-2):
    for j in range(i+1,length-1):
        for k in reversed(range(j+1,length)):
            if(l[k]<l[i]+l[j]):
                ans += k-j
                break
print(ans)

Submission status: Time Limit Exceeded

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

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 a < b + c and b < c + a and c < a + b:
				num_pattern += 1

print(num_pattern)

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):
  for j in range(i+1,n):
    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 itertools

def test():
    n = int(input())
    l = list(map(int,input().split()))
    ans = 0
    for a,b,c in itertools.combinations(l,3):
        if a+b>c and a+c>b and b+c>a:
            ans += 1
    print(ans)


if __name__ == "__main__":
    test()

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()))
    l_list.sort()

    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
                else:
                    break
    print(ans)


if __name__ == '__main__':
    main()

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):
  a = L[i]
  for j in range(i+1,N-1):
    b = L[j]
    if b*2 < a: break
    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:
n = int(input())
l = list(map(int, input().split()))

l.sort()
l.reverse()
c = 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]:
                c += 1
            else:
                break

print(c)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

L = sorted(L)
# print(L)

ans = 0

# all_end = False
# next_a = False
# for a in range(N):
#     if all_end:
#         break
#     for b in range(a+1, N):
#         if next_a:
#             next_a = False
#             break
#         for c in range(N-1, b, -1):
#             print("{} {} {} / ans: {}".format(L[a], L[b], L[c], ans))
#             if L[a] + L[b] > L[c]:
#                 ans += 1
#             else:
#                 if c == N-1:
#                     next_a = True
#                     if b == a+1:
#                         all_end = True
#                 break

all_end = False
next_a = False
for a in range(N):
    # if all_end:
    #     break
    for b in range(a+1, N):
        if next_a:
            next_a = False
            break
        for c in range(b+1, N):
            # print("{} {} {} / ans: {}".format(L[a], L[b], L[c], ans))
            if L[a] + L[b] > L[c]:
                ans += 1
            else:
                # if c == b+1:
                #     next_a = True
                #     if b == a+1:
                #         all_end = True
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

if __name__ == "__main__":	
	N = int(input())
	L = sorted([int(e) for e in input().split()])

	res = 0

	for i in range(0, N):
		for j in range(i + 1, N):
			for k in range(j + 1, N):
				if L[i] + L[j] < L[k]:
					break
				if canMake(L[i], L[j], L[k]):
					res += 1
	
	print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=sorted([int(i)for i in input().split()])
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]:
                sum+=1
            else:
                break
print(sum)

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)):
    lin[i] = list(lin[i])
    lin[i].sort()
    if lin[i][2] < lin[i][0] + lin[i][1]:
        point += 1
print(point)

Submission status: Time Limit Exceeded

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


count=0

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(lambda x: int(x), input().split()))

res = 0


def is_triangle(i, j, k):
    return i < j + k and j < i + k and k < i + j


for i in range(n):
    for j in range(n):
        for k in range(n):
            if i != j and j != k and i != k and is_triangle(d[i],d[j],d[k]):
                res += 1

print(res // 6)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int, input().split()))
L.sort()
L = L[::-1]

ans = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for h in range(j + 1, n):
            if L[i] < L[j] + L[h]:
                ans += 1

print(ans)