Problem:


Score : 400 points

Problem Statement

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

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

a < b + c

b < c + a

c < a + b

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

Constraints

All values in input are integers.

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

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

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

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
Lmat = input().split()
Lmatint = []
for i in range(len(Lmat)):
    Lmatint.append(int(Lmat[i]))
#全パターン選ぶ
allpatern = list(itertools.combinations(range(N), 3))
sum = 0
def iftriangle(first,second,third):
    if Lmatint[first]>=Lmatint[second]+Lmatint[third]:
        return 0
    elif Lmatint[second]>=Lmatint[first]+Lmatint[third]:
        return 0
    elif Lmatint[third]>=Lmatint[first]+Lmatint[second]:
        return 0
    else:
        return 1
for patern in allpatern:
    first = patern[0]
    second = patern[1]
    third = patern[2]
    sum += iftriangle(first,second,third)
print(sum)

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)
    res = [i 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]]
    print(len(res))

if __name__ == '__main__':
    D()

Submission status: Time Limit Exceeded

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

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 = l[:]
  l_woab.remove(a)
  l_woab.remove(b)
  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()))
cnt = n * (n - 1) * (n - 2) / 6
jud = []

for i in range(n):
    for j in range(n):
        if i > j:
            jud.append(L[i] + L[j])

for m in range(n):
    for p in range(len(jud)):
        if L[m] >= jud[p]:
            cnt -= 1

if cnt < 0:
    print(0)
else:
    print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list = input().split()
L = [int(n) for n in list]
L.sort()
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) :
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

tmp = 0
for i in range(N):
    for j in range(N-i-1):
        j = j + i + 1
        for k in range(N-j-1):
            k = k + j + 1

            if L[i] < L[j] + L[k]:
                if L[j] < L[i] + L[k]:
                    if L[k] < L[i] + L[j]:
                        tmp = tmp + 1

print(tmp)

Submission status: Time Limit Exceeded

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

ans = 0
L_list.sort(reverse=True)
b_end = N - 1
c_end = N
for i in range(N - 2):
    for j in range(i + 1, b_end):
        for k in range(j + 1, c_end):
            if L_list[i] < L_list[j] + L_list[k]:
                if L_list[j] < L_list[i] + L_list[k]:
                    ans += 1
                else:
                    b_end = k
                    c_end = k + 1
                    break
            else:
                b_end = k
                c_end = k + 1
                break
    b_end = N - 1
    c_end = N

print(ans)

Submission status: Time Limit Exceeded

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

l.sort()

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

            else:
                break

print(output)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
cnt=0
for i in range(N-1,1,-1):
    for j in range(i-1,0,-1):
        b = bisect.bisect_right(L[:j],L[i]-L[j])
        cnt+=j-b
print(cnt)

Submission status: Time Limit Exceeded

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

i=0
j=0
k=0
ta=0
rb=0
tc=0
cnt=0
for i in range(0,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]:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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)):
    a = data[i]
    b = data[j]
	# flag = (a < b + c) and (b < c + a) and (c < a + b)
    count += len([c for c in data[j+1:] if (a < b + c) and (b < c + a) and (c < a + b)])

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

n = int(input())
L = list(map(int, readline().split()))
cnt = 0

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

for l in ls:
    if l[0] < l[1]+l[2] and l[1] < l[2]+l[0] and l[2] < l[0]+l[1]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,*l=map(int,open(0).read().split())
l.sort()
a=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[k]>=l[i]+l[j]:
                break
            if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
                a+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

N = int(input())
L = np.sort(np.array(list(map(int, input().split(" ")))))[::-1]

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

Submission status: Time Limit Exceeded

Solution code:
def main() :
	n = int(input())
	s = list(map(int, input().split()))

	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(s[i] < s[j] + s[k] and s[j] < s[i] + s[k] and s[k] < s[i] + s[j]) :
					ans = ans + 1

	print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

res = list(itertools.combinations(A, 3))

ans = 0
for i in range(len(res)):
  if max(res[i])*2 < sum(res[i]):
    ans += 1
    
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import heapq
import itertools
#import math
#import numpy as np
#import sys

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
#print(L)
C = itertools.combinations(list(range(0,N-1)), 2)
ans = 0
i = 1
for c in C :
    #print(c)
    while True :
        #print(L[c[1] + i])
        if L[c[0]] + L[c[1]] > L[c[1] + i] :
            ans += 1
            i += 1
        else :
            i = 1
            break

        if c[1] + i > N - 1:
            i = 1
            break
print(ans)


#a = [(x, y, z) for (x, y, z) in itertools.combinations(L, 3) if ((x+y) > z) and ((x+z) > y) and ((y+z) > x)]
#print(len(a))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l = [int(i) for i in input().split()]
check = [False for i in range(n)]
ans = 0
for x in itertools.combinations(l,3):
    if(x[0] >= x[1]+x[2]): continue
    if(x[1] >= x[0]+x[2]): continue
    if(x[2] >= x[0]+x[1]): continue
    ans += 1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l[n+1:]):
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//3)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-1, -1, -1):
    max_l = l[i]
    for j in range(i-1, -1, -1):
        next_l = l[j]
        ans += j - bisect.bisect_left(l[:j], (max_l-next_l+0.01))
print(ans)

Submission status: Time Limit Exceeded

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

count = 0

for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if arr[a]<arr[b]+arr[c] and arr[b]<arr[c]+arr[a] and arr[c]<arr[a]+arr[b]:
                count +=1
            else:
                break

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=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 l[k]<l[i]+l[j]:
        ans+=1
      else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

li.sort()

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      for c, cc in enumerate(li[a+1+b+1:]):
        if aa + bb <= cc:
          break
        if aa < bb + cc and bb < cc + aa and cc < aa + bb:
          ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
hoge = input().split()
L = []
for i in range(N):
  L.append(int(hoge[i]))
  
sums = 0
for i in range(N-2):
  a = L[i]
  for j in range(i+1,N-1):
    b = L[j]
    sums += len([i for i in L[j+1:] if i > abs(a - b) and i < (a + b)])

print(sums)

Submission status: Time Limit Exceeded

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

L.sort()
count = 0

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

Submission status: Time Limit Exceeded

Solution code:

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

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

print(sum(x))

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

Submission status: Time Limit Exceeded

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

num = [False] * (3001)
for i in range(N):
    num[L[i]] = True

L.sort(reverse=True)

ans = 0
for a in range(N):
    for b in range(a+1,N):
        l = L[a]-L[b]
        r = min(L[a]+L[b],L[b])
        ans += sum(num[l+1:r])
        # print(l,r,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

l = sorted(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)):
            if l[i3] >= l[i1] + l[i2]:
                break

            sum += 1


print(sum)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# ABC143 D

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

res = 0
for a in range(n - 2):
    for b in range(a + 1, n - 1):
        for c in range(b + 1, n):
            if(l[a] < l[b] + l[c] and
            l[b] < l[a] + l[c] and
            l[c] < l[a] + l[b]):
                res += 1
print(res)

Submission status: Time Limit Exceeded

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

ans=0
for x,a in enumerate(L):
	for y,b in enumerate(L):
		for z,c in enumerate(L):
			if x==y or y==z or x==z:
				continue
			if a<b+c and b<c+a and c<a+b:
				ans+=1

print(int(ans/6))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
bou_list = list(map(int, input().split()))
triangle_list = list(itertools.combinations(bou_list,3))
def triangle_check(a, b, c):
    if a >= b + c:
        return False
    if b >= a + c:
        return False
    if c >= a + b:
        return False
    return True

total = 0
for i in triangle_list:
    a, b, c = i
    if triangle_check(a, b, c):
        total += 1

print(total)

Submission status: Time Limit Exceeded

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

A=sorted(A)
import numpy as np
A=np.array(A)
#print(A)
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
      elif a+b<=c:
        break
            
print(count)

Submission status: Time Limit Exceeded

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

count = 0
li.sort(reverse=True)
for i in range(len(li)):
    for j in range(i, len(li)):
        if i==j:
            continue
        for k in range(j, len(li)):
            if i==k or j==k:
                continue
            if li[i] > (li[j] + li[k]):
                break
            a = li[i]
            b = li[j]
            c = li[k]
            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(raw_input())
L = map(int, raw_input().split())

L.sort(reverse=True)

sum = 0

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

    for j in range(i+1,N):
        b = L[j]
        if 2*b < a:
            break

        for k in range(j+1,N):
            c = L[k]
            if a < b+c:
                sum = sum + 1
            else:
                break

print sum

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
l_list = list(map(int, input().split()))
count = 0
for i, li in enumerate(l_list):
    for j, lj in enumerate(l_list[i+1:], i+1):
        for lk in l_list[j+1:]:
            if (li < lj + lk and lj < lk + li and lk < li + lj):
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
stick = sorted(list(map(int, input().split())), reverse=True)
combi = itertools.combinations(stick, 3)
ans = 0
lst = []
flag = False
for a,b,c in combi:
  if flag and a in lst:
    continue
  else:
    flag = False
  if a < b+c and b < c+a and c < a+b:
    ans += 1
  else:
    flag = True
    lst.append(a)
print(ans)

Submission status: Time Limit Exceeded

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

def is_build(a, b, c):
    return (a<b+c)and(b<a+c)and(c<a+b)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = sorted(LIST())

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        l1 = max(L[i], L[j])
        l2 = min(L[i], L[j])
        k = j+1
        kk = 0
        while k < N:
            if L[k] > (l1 - l2):
                kk = k
                break
            k += 1
        m = N-1
        mm = 0
        while m >= k:
            if L[m] < (l1 + l2):
                mm = m
                break
            m -= 1
        if kk != 0 and mm != 0:
            count += (m - k + 1)


        # for ll in L[j+1:]:
        #     if ll > (l1 - l2) and ll < (l1 + l2):
        #         count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

c = list(combinations(a,3))
ans=0
for i in range(len(c)):
    #print(c[i][0],c[i][1],c[i][2])
    
    if c[i][0] < c[i][1]+c[i][2] and c[i][1] < c[i][0]+c[i][2] and c[i][2] < c[i][1]+c[i][0]:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

    ans = set()
    edges.sort()
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            for c in range(b + 1, N):
                if edges[a] < edges[b] + edges[c] and edges[b] < edges[c] + edges[a] and edges[c] < edges[a] + edges[b]:
                    ans.add((a, b, c))
    print(len(ans))


if __name__ == "__main__":
    main()

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(max(i,j)+1,N):
                if sort_L[i] + sort_L[j] > sort_L[k]:
                    cnt += 1
                else:
                    break

    print(cnt)

    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from itertools import permutations

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

count = 0
for pars in list(combinations(L, 3)):
    for bars in list(permutations(list(pars), 3)):
        if bars[0] < bars[1] + bars[2]:
            if abs(bars[1] - bars[2]) < bars[0]:
                count += 1
                break
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L_list=[int(thing) for thing in input().split()]
L_list.sort(reverse=True)

ret=0
for i in range(N):
    n=L_list[i]
    for j in range(i+1,N):
        k=L_list[j]
        for h in range(j+1,N):
            l=L_list[h]
            if l>n-k:
                ret=ret+1
            else:
                break
print(ret)

Submission status: Time Limit Exceeded

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


def tri_judge(i, j, k):
    if i+j > k:
        if j+k > i:
            if k+i > j:
                return True
            else:
                return False
        else:
            return False
    else:
        return False


for i in range(n):
    for j in range(i+1, n):
        if length[i]/2 > length[j]:
            break
        else:
            for k in range(j+1, n):
                if tri_judge(length[i], length[j], length[k]):
                    ans += 1
                else:
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in 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 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(map(int,input().split()))
L = sorted(L,reverse=True)
total = 0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if L[j] + L[k] > L[i]:
                total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
L = read_ints()

from itertools import combinations
cnt = 0
for a, b, c in combinations(L, 3):
    if (a < b + c) and (b < c + a) and (c < a + b):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a=[]
b=int(input())
for x in input().split(" "):
    a.append(int(x))

a.sort()
    
i=0
j=0
k=0
n=0

while i<b:
    j=i+1
    while j<b:
        k=j+1
        while k<b:
            if a[i]+a[j]<=a[k]:
                break
            k+=1
        n+=(b-k)
        j+=1
    i+=1
print(int(b*(b-1)*(b-2)/6-n))

Submission status: Time Limit Exceeded

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

a = list(itertools.combinations(l,3))
v = 0
for c in a:
  if not c[0] < c[1]+c[2]:
    continue
  if not c[1] < c[2]+c[0]:
    continue
  if not c[2] < c[0]+c[1]:
    continue
  v += 1
print(v)

Submission status: Time Limit Exceeded

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

lines.sort()
count = 0

for i in reversed(range(2,n)):
    for j in reversed(range(1,i)):        
        for k in reversed(range(j)):
            if lines[i] >= lines[j] + lines[k]:
                break
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

l.sort(reverse=True)
#print(l)

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

print(ans)

Submission status: Time Limit Exceeded

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

def ta(li):
  b1 = li[0] < li[1]+li[2]
  b2 = li[1] < li[2]+li[0]
  b3 = li[2] < li[0]+li[1]
  if b1:
    if b2:
      if b3:
        return li
  return -1

all_l = []
count = 0
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      t = [li[i], li[j], li[k]]
      r = ta(t)
      if r!=-1 and r not in all_l:
        all_l.append(r)
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
lengths = [int(i) for i in input().split()]
combinations = list(itertools.combinations(lengths,3))
count = 0
for i in range(len(combinations)):
    a = combinations[i][0]
    b = combinations[i][1]
    c = combinations[i][2]
    if abs(a-b) < c and c < a+b:
        count += 1
print(count)

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-2) for y in range(x+1,a-1) for z in range(y+1,a) if (b[x]<b[y]+b[z] and b[y]<b[x]+b[z] and b[z]<b[x]+b[y]))))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
inputData = input().split()
L = [int(x) for x in inputData]
L.sort()
ans = 0
for a in range(0, N):
    for b in range(a+1, N):
        for c in range(b+1, N):
            if L[c] < L[a] + L[b]:
                    ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations


def input(): return sys.stdin.readline().strip()


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

    ans = 0

    for i, j in combinations(range(N-1), 2):
        for k in range(j+1, N):
            a, b, c = L[i], L[j], L[k]
            if abs(b-c) < a < b+c:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ln = [int(i) for i in input().split()]
ans = 0
for j in range(n):
    for k in range(n - 1):
        for l in range(n):
            if j == k == l or j >= k or k >= l:
                continue
            else:
                if ln[j] < (
                    ln[k] +
                    ln[l]) and ln[k] < (
                    ln[j] +
                    ln[l]) and ln[l] < (
                    ln[k] +
                        ln[j]):
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

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 - 2):
    for j in range(n - i - 2):
        k = [idx for idx,val in enumerate(l) if val<(l[i] + l[i + j + 1])]
        count += len(k) - i - j - 2
print(int(count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb = list(itertools.combinations(l, 3))
count = 0
for i in range(len(comb)):
    a = comb[i][0]
    b = comb[i][1]
    c = comb[i][2]
    if a + b <= c:
        continue
    elif a + c <= b:
        continue
    elif b + c <= a:
        continue
    else:
        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 1 if i < j + k and j < i + k and k < i + j else 0


i = 0
j = 1
k = 2

while i < n:
    while j < n:
        while k < n:
            res += is_triangle(d[i],d[j],d[k])
            k += 1
        j += 1
        k = j + 1
    i += 1
    j = i + 1
    k = j + 1


print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
L_list = [int(x) for x in input().split()]
L_list.sort()


result = 0
comb = itertools.combinations(L_list, 3)
for triangle in comb:
    if triangle[2] < triangle[0] + triangle[1]:
        result += 1

print(result)