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 sys
from itertools import combinations
import bisect
import math
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 combi in combinations(l_ls, 2):
    bisect.insort_left(_sum_ls, combi[0] + combi[1])
len_sum_ls = len(_sum_ls)
for _sum in _sum_ls:
    ind = bisect.bisect_left(l_ls, _sum)
    cnt += n - ind
print(int(math.factorial(n) / math.factorial(3) / math.factorial(n-3)) - cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy
count = int(input())
sticks = list(map(int, input().split()))

ans = 0
for i, s1 in enumerate(sticks):
  if i == len(sticks)-1:
    break
  sticks2 = copy.deepcopy(sticks)[i+1:]
  for j, s2 in enumerate(sticks2):
    if j == len(sticks2)-1:
      break
    sticks3 = copy.deepcopy(sticks2)[j+1:]
    for k, s3 in enumerate(sticks3):
      if s1 + s2 > s3 and s1 + s3 > s2 and s2 + s3 > s1:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''
import copy
import numpy as np
def main():
    N = int(input())
    L = list(map(int, input().split()))

    count = 0
    L = np.array(L)
    for i in range(N):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            _L = copy.copy(L[j+1:])
            C = _L[(_L < a + b)]
            res = C[C > abs(a - b)]
            count += len(res)
    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = []
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[j] < L[k]+L[i] and L[k] < L[i]+L[j]:
                ans.append(0)
print(len(ans))

Submission status: Time Limit Exceeded

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

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

answer = 0

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

a_count = 0
for a in rod:
    b_count = 0
    for b in rod:
        if (a_count != b_count) and (a_count < b_count):
            c_count = 0
            for c in rod:
                if (a_count != c_count) and (b_count != c_count) and (b_count < c_count):
                    #print(str(a) + ":" + str(b) + ":" + str(c))
                    if check(a,b,c):
                        #print("true")
                        answer += 1
                c_count += 1
        b_count += 1
    a_count += 1

print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

def tri_able(x, y, z):
    if x+y > z and y+z > x and z+x > y:
        return True
    else:
        return False

answer = 0

for i in range(len(L)-2):
    for j in range(i+1, len(L)-1):
        for k in range(j+1,len(L)):
            answer += int(tri_able(L[i], L[j], L[k]))
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
l = list(map(int, input().split()))
t = list(itertools.combinations(l,3))
count =0
for i in t:
    a,b,c = i
    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())
L=list(map(int,input().split()))
L.sort()
 
count=0
list.sort(L, reverse=True)
 
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]:
                count += 1
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(N-2):
  candidate = L[i+1:]
  candidate_array = np.array(candidate)
  ans += sum([np.count_nonzero((candidate_array[k+1:]<L[i]+l)&(candidate_array[k+1:]>abs(l-L[i]))) for k,l in enumerate(candidate)])

print(ans)

Submission status: Time Limit Exceeded

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

import itertools

def check(c):
  if max(c) >= sum(c) -max(c) :return 0
  return 1

ans = sum([check(c) for c in list(itertools.combinations(L,3))])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, *x = map(int, open(0).read().split())
y = sorted(x)[::-1]
cnt = 0
for i in range(n - 2):
    a = y[i]
    for j in range(i + 1, n - 1):
        b = y[j]
        c = j + 1
        while c < n and a < b + y[c]:
            cnt += 1
            c += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

cnt = 0
for i in range(0, len(L)-2):
    l1 = L[i]
    rest = L[i+1:]
    for i2 in range(0, len(rest)-1):
        l2 = rest[i2]
        rest2 = rest[i2+1:]
        cnt += sum(rest2 > l1 - l2)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

l = len(L)

count = 0
for i in range(l):
    a = L[i]
    for j in range(i+1,l):
        b = L[j]
        count += bisect.bisect_left(L[j+1:l],a+b)

print(count)

Submission status: Time Limit Exceeded

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

from collections import defaultdict

d = defaultdict(int)

for i in range(n):
    d[s[i]]+= 1

r = 0
key = sorted(list(d.keys()))
ng = len(key)
for i in range(ng)[::-1]:
    ki = key[i]
    for j in range(i+1)[::-1]:
        kj = key[j]
        if kj <= ki / 2:
            continue
        for k in range(j+1)[::-1]:
            ti = 0
            kk = key[k]
            if kj + kk <= ki:
                break
            if ki != kj and kj != kk and ki != kk:
                ti = d[ki] * d[kj] * d[kk]
            elif ki == kj and kj == kk:
                if d[ki] < 3:
                    continue
                else:
                    ti = d[ki] * (d[ki]-1) * (d[ki]-2) // 6
            elif ki == kj:
                if d[ki] < 2:
                    continue
                else:
                    ti = d[ki] * (d[ki]-1) * d[kk] // 2
            elif kj == kk:
                if d[kk] < 2:
                    continue
                else:
                    ti = d[j] * (d[kj]-1) * d[ki] // 2
            elif ki == kk:
                if d[ki] < 2:
                    continue
                else:
                    ti = d[ki] * (d[ki]-1) * d[kj] // 2
            r+=ti
print(r)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
pre_a = -1
for i in range(N-1,1,-1):
    tmp = 0
    a = l[i]
    lm = a//2
    for j in range(i-1,0,-1):
        b = l[j]
        if b<=lm:
            continue
        a_b = a+b
        for k in range(j):
            c = l[k]
            if (b+c>a):
                tmp += j-k
                break
    cnt += tmp
    pre_a = a
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

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

num_pattern = 0

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

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

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

			if c < a + b:
				num_pattern += 1

print(num_pattern)

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

print(int(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

result = 0

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n=int(input())
lists=list(map(int,input().split()))
listss=sorted(lists)
count=0
for i in range(n):
    for j in range(n):
        if i!=j:
            index1= bisect.bisect_left(listss, abs(listss[j]-listss[i])+1)
            index2=bisect.bisect_right(listss,listss[i]+listss[j]-1)
            count+=(index2-index1)
            x=abs(listss[j]-listss[i])
            if  x+1<=listss[i]:
                count-=1
            if x+1<=listss[j]:
                count-=1
print(count//6)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

L.sort()
c=N-1
ans=0
while c>1:
  for i,a in enumerate(L[:c]):
    for b in L[i+1:c]:
      if L[c]<a+b:
        ans+=1
  c-=1
print(ans)

Submission status: Time Limit Exceeded

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

l.sort()
ans = 0

for i in range(len(l)-1):
    for j in range(i+1, len(l)):
        x = 0
        y = 0
        if l[i] - l[j] > 0:
            start = l[i] - l[j]
        else:
            start = l[j] - l[i]
        end = l[i] + l[j]

        for k in range(j+1, len(l)):
            if l[k] > start:
                x = k
                break
        for m in range(len(l)-1, j, -1):
            if l[m] < end:
                y = m
                break

        if x != 0 and y != 0:
            ans += y-x+1
print(ans)

Submission status: Time Limit Exceeded

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

# a<b<c -> c<a+b

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

Submission status: Time Limit Exceeded

Solution code:
def sol():
    n=int(input())
    l=[int(i) for i in input().split()]
    l.sort()
    ans=chk=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]:
                    break
                elif l[k]<l[i]+l[j] and l[i]<l[j]+l[k] and l[j]<l[i]+l[k]:
                    ans+=1
    print(ans)

if __name__=="__main__":
    sol()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():

	args = sys.argv
	N = int(input())
	L = list(map(int, input().split()))
	L.sort()
	C = 0
	for i in range(0, N-2):
		next_fg = False
		for j in range(i+1, N-1):
			for k in range(j+1, N):
				
				if  L[k] < L[i] + L[j]:
					C = C + 1
				else:
					k = N
	print(C)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

i = 0
j = len(ls) - 1
k = j - 1
res = []

while i < len(ls) - 1:
    while i < j:
        while i < k:
            if ls[j] - ls[i] < ls[k]:
                res.append((ls[i], ls[j], ls[k]))
                k -= 1
            else:
                break
        j -= 1
        k = j - 1
    i += 1
    j = len(ls) - 1
    k = j - 1
print(len(res))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def canMake(a, b, c):
	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 = list(map(int, input().split()))

import itertools

def check(c):
  print
  if max(c) >= sum(c) -max(c) :return 0
  return 1

ans = sum([check(c) for c in list(itertools.combinations(L,3))])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
'''
n,m,c = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
from math import ceil
from collections import defaultdict ,Counter
'''
import sys
input=sys.stdin.readline
n = int(input())
a = sorted(list(map(int,input().split())))
'''
a1 = 0
a2 = 1
res = 0
t = 2
while a1 < n and a2 < n and t < n:
    while a2 < n and t < n:
        if a[a1] + a[a2] > a[t]:
            res+=1
            t+=1
        else:
            a2+=1
            t = a2 + 1
    a1+=1
    a2 = a1+1
    t = a2 + 1

print(res)
'''

res = 0
for i in range(n):
    for j in range(i+1,n):
        yy = a[i]+a[j]
        for k in range(j+1,n):
            if yy > a[k]:res+=1
            else:
                break
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int, input().split()))
L.sort()
L.reverse()
ans = 0
pre = 0
for i in range(n):
    for j in range(i+1, n):
        flag = True
        for k in range(j+1, n):
            if L[i] >= L[j] + L[k]:
                ans += max(0, k - (j + 1))
                flag = False
                break
        if flag:
            ans += n - (j + 1)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

seq = list(itertools.combinations(L, 3))
num = len(seq)

for i in range(num):
    a = seq[i][0]
    b = seq[i][1]
    c = seq[i][2]
    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())
t=list(map(int,input().split()))
t.sort()
T=0
for i in range(n-2):
  a=t[i]
  for j in range(n-i-1):
    b=t[i+j+1]
    for k in range(n-i-j-2):
      c=t[i+j+k+2]
      if c<a+b:
        T+=1
print(T)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
cmlist = input().split(' ')
count = 0
for i in range(0, num):
  for j in range(i+1, num):
    for k in range(j+1, num):      
      if int(cmlist[i])<int(cmlist[j])+int(cmlist[k]):
        if int(cmlist[j])<int(cmlist[i])+int(cmlist[k]):
          if int(cmlist[k])<int(cmlist[i])+int(cmlist[j]):
            count+=1

print(count)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = sorted(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]):
        result += 1
      else:
        break
        

print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools


def input():
    return sys.stdin.readline()[:-1]


n = int(input())
L = list(map(int, input().split()))
triangle = 0
comb = list(itertools.combinations(L, 3))
for i in range(len(comb)):
    a = comb[i][0]
    b = comb[i][1]
    c = comb[i][2]
    if (a < b + c) and (b < c + a) and (c < a + b):
        triangle += 1
print(triangle)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
ans = 0
import itertools
L.sort(reverse=True)
for i in range(N-2):
  s = L[0]
  L.remove(L[0])
  for c in itertools.combinations(L, 2):
    if sum(c) > s:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

def main():
    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):
            tmp = L[i] + L[j]
            insert_index = bisect.bisect_left(L[j+1:], tmp)
            #print(insert_index)
            ans += insert_index

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def is_triangle(a, b, c):
    x = a - b
    y = a + b

    if x < c and -x < c and c < y:
        return True
    else:
        return False

def combinations(iterable, r):
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    ret = tuple(pool[i] for i in indices)
    if is_triangle(ret[0], ret[1], ret[2]):
        yield ret
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        ret2 = tuple(pool[i] for i in indices)
        if is_triangle(ret2[0], ret2[1], ret2[2]):
            yield ret2
print(len(list(combinations(L, 3))))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = list(map(int, input().split(' ')))
nums.sort(reverse=True)
ans = 0
for i in range(N-2):
    for j in range(i+1, N):
        for l in range(j+1, N):
            if nums[i] < nums[j]+nums[l]:
                ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0

d = []

for i in range(n):
	for j in range(i+1,n):
		index = bisect.bisect_left(l,l[i]+l[j])
		for k in range(i+1,index):
			if k == j:
				continue
			if l[j] < l[k] + l[i]:
				if j < k:
					if [i,j,k] not in d:
						d.append([i,j,k])
						ans += 1
				else:
					if [i,k,j] not in d:
						d.append([i,k,j])
						ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

p = list(itertools.combinations(l,3))

ans = 0
for i in p:
    if i[0] >= i[1] + i[2]:
        pass
    elif i[1] >= i[0] + i[2]:
        pass
    elif i[2] >= i[0] + i[1]:
        pass
    else:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = 0

for i in itertools.combinations(L, 3):
  if i[0] < i[1] + i[2]:
    if i[1] < i[0] + i[2]:
      if i[2] < i[1] + i[0]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
res = 0
for i in range(N-2):
    if L[i] < L[i+1] + L[i+2]:
        comb_list = itertools.combinations(L[i+1:], 2)
        res +=  sum([L[i] < (comb[0] + comb[1]) for comb in comb_list])
    else: continue
print(res)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import copy
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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




N=one_int()
L=many_int()

L=sorted(L)

sankaku_dict={}
search_end={}
for i in range(len(L)-1):
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        temp = str(L[i]) +","+ str(L[j])
        if temp in search_end:
            continue

        high=L[j]
        low=L[i]

        Lcopy = copy.deepcopy(L)
        Lcopy.remove(high)
        Lcopy.remove(low)
        Lcopy = sorted(Lcopy)

        #下限を取得    
        under_index = bisect.bisect_right(Lcopy,high-low)
        #上限を取得
        high_index = bisect.bisect_left(Lcopy,high+low)
        for va in Lcopy[under_index:high_index]:
            temp = sorted([high,low, va])
            temp = (temp[0]*10**8) + (temp[1]*10**4) + temp[2]
            sankaku_dict[temp]=1

# len(sankaku_dict)
print(len(sankaku_dict.keys()))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
counter=0
for t in range(1,N-1):
  for i in range(0,t):
    for p in range(t+1,N):
      if L[i]<L[t]+L[p] and L[p]<L[i]+L[t] and L[t]<L[i]+L[p]:
        counter+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
ans=0
for n in range(N-2):
  for k in range(n+1,N-1):
    if L[n]<L[k]*2:
      for l in range(k+1,N):
        if L[n]<L[k]+L[l]:
          ans+=1
        else:
          break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

stick_number = int(input())
sticks = list(map(int, input().split()))

## print(stick_number)
## print(sticks)
result = 0

i1 = list(itertools.combinations(sticks, 3))
for j in i1:
  if abs(j[1] - j[2]) < j[0] < j[1] + j[2]:
    result += 1
    
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l= list(map(int, input().split()))
a=0
list.sort(l, reverse=True)
for i in range(n-2):
    ten = l[0]
    l.pop(0)
    #print(ten,"/",l)
    se=0
    for j in range(len(l)-1):
        for k in range(j+1,len(l)):
            if ten < l[j] + l[k] and l[j] < ten + l[k] and l[k] < l[j] + ten:
                #print("a++ : ",ten,"/",l[j],"/",l[k])
                a+=1
                if(k == j+1 and se != 0):
                    a += se -k
            else:
                se = k
                break
print(a)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = set()
for i in range(N - 1):
    for j in range(i + 1, N):
        l = abs(L[i] - L[j])
        r = L[i] + L[j]

        if l < L[i]:
            li = bisect.bisect(L, l, hi=i)
        else:
            li = bisect.bisect(L, l, lo=i, hi=j)

        ri = bisect.bisect_left(L, r, lo=j)
        for k in range(li, ri):
            if k == i or k == j: continue
            if k < i:
                ans.add((L[k], L[i], L[j]))
            elif k < j:
                ans.add((L[i], L[k], L[j]))
            else:
                ans.add((L[i], L[j], L[k]))

print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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(len(L)-1):
  for j in range(i+1,len(L)):
    left=bisect.bisect_left(L, L[i]+L[j])
    right=bisect.bisect_right(L, L[j]-L[i])
    if left > j:
      ans+=left-j-1
 # break
print(ans)

Submission status: Time Limit Exceeded

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

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list = input().split()
L = [int(n) for n in list]
L.sort()
sum = 0
import itertools
for v in itertools.combinations(L, 3):
  a = v[2]
  b = v[1]
  c = v[0]
  if (a<b+c) & (b<c+a) :
    sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

import numpy as np

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


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


print(
    len(
        np.where(
            (Ls[:, 0] < Ls[:, 1] + Ls[:, 2])
            & (Ls[:, 1] < Ls[:, 2] + Ls[:, 0])
            & (Ls[:, 2] < Ls[:, 0] + Ls[:, 1])
        )[0]
    )
)

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

        c = 0
        start = j
        end = N
        while start != end-1:
            k = (end + start)/2
            c = L[k]
            if  c > a-b:
                start = k
            else:
                end = k

        if start == end-1:
            sum = sum + (start-j)

print sum

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
t=0
for i in range(N-2):
    for j in range(i+1,N-1):
        if L[i]<L[j]+L[N-1]:
            t+=N-1-j
        elif L[i]>=L[j]+L[j+1]:
            t+=0
        else:
            c=int((2*N-2-j)/2)
            while L[i]>L[j]+L[c] or L[i]<L[j]+L[c+1]:
                if L[i]<=L[j]+L[c]:
                    c=int((c+N-1-j)/2)
                elif L[i]>=L[j]+L[c+1]:
                    c=int((N-1+c)/2)
                print('c')
            t+=N-1-c

print(t)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

triangles =[]
ans =0


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

ans = len(set(triangles))
print(ans)