Problem:


Score : 400 points

Problem Statement

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

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

a < b + c

b < c + a

c < a + b

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

Constraints

All values in input are integers.

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

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

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

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        d = L[j]-L[i]
        s = L[i]+L[j]
        for k in range(j+1, N):
            if d<L[k]:
                if s<=L[k]:
                    break
                else:
                    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def check(a):
    return a[0] < a[1] + a[2] and a[1] < a[0] + a[2] and a[2] < a[0] + a[1]

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# abc143/abc143_d
import sys
from itertools import combinations


def s2nn(s): return [int(c) for c in s.split(' ')]


def ss2nn(ss): return [int(s) for s in list(ss)]


def ss2nnn(ss): return [s2nn(s) for s in list(ss)]


def i2s(): return sys.stdin.readline().rstrip()


def i2n(): return int(i2s())


def i2nn(): return s2nn(i2s())


def ii2ss(n): return [i2s() for _ in range(n)]


def ii2nn(n): return ss2nn(ii2ss(n))


def ii2nnn(n): return ss2nnn(ii2ss(n))


def main():
    N = i2n()
    L = i2nn()
    s = 0
    for a, b, c in combinations(L, 3):
        m = a+b+c
        s += (2*a < m and 2*b < m and 2*c < m)
    print(s)
    return


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect_left as bl
from bisect import bisect_right as br
input = sys.stdin.buffer.readline
N = int(input())
L = list(map(int, input().split()))
L.sort()
dl = []
for i in range(N - 1):
  for j in range(i + 1, N):
    dl.append((L[i] + L[j], i, j, abs(L[i] - L[j])))
dl.sort()
#print(L)
#print(dl)
res = 0
for d in dl:
  ind = bl(L, d[0])
  ind2 = br(L, d[3])
  res += ind - ind2
  if ind2 <= d[1] <= ind:
    res -= 1
  if ind2 <= d[2] <= ind:
    res -= 1
  #print(res, d, ind, ind2)
print(res // 3)

Submission status: Time Limit Exceeded

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

triangles = set()
for i, a in enumerate(l[:-2]):
    for j, b in enumerate(l[i+1:-1], i+1):
        for k, c in enumerate(l[j+1:], j+1):
            if a + b > c and b + c > a and a + c > b:
                triangles.add(tuple(sorted([a, b, c])))

print(len(triangles))

Submission status: Time Limit Exceeded

Solution code:

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


x = 0

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

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

valid = 0
for a, b, c in itertools.combinations(L, 3):
    if a < b + c and b < c + a and c < a + b:
        valid += 1

print(valid)

Submission status: Time Limit Exceeded

Solution code:
a = input()

a = int(a)

b = input().split(' ')

from itertools import combinations

comb = combinations(b, 3)

possible_triangles = 0

for i in list(comb):
    if int(i[0]) >= int(i[1]) + int(i[2]):
        continue
    if int(i[1]) >= int(i[0]) + int(i[2]):
        continue
    if int(i[2]) >= int(i[0]) + int(i[1]):
        continue
    possible_triangles += 1

print(possible_triangles)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    L = list(map(int,input().split()))
    L = sorted(L,reverse=True)
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            for k in range(N-1,j,-1):
                if L[k] + L[j] > L[i]:
                    ans += k-j
                    break
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
cnt = 0
for i in range(2, len(l)):
    for j in range(i):
        for k in range(j+1, i):
            if l[i] < l[j] + l[k]:
                cnt = cnt + (i-k)
                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(N):
    if i<=j:
      continue
    for k in range(N):
      if j<=k:
        continue
        
      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 = [int(i) for i in input().split()]

L_len = len(L)

L.sort(reverse=True)

count = 0
for i in range(L_len - 2):
    for j in range(i + 1, L_len - 1):
        for k in range(j + 1, L_len):
            if L[i] < L[j] + L[k]:
                count += 1
            else:
                break

print(count)

Submission status: Time Limit Exceeded

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

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

cnt = 0
for i in range(n):
  a = l[i]
  for j, b in enumerate(l[i+1:]):
    for c in l[i+j+2:]:
      if (a < b+c) and (b < a+c) and (c <  a+b):
        cnt += 1
        
print(cnt)

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 i in comb:
  if i[0]+i[1]>i[2] and i[1]+i[2]>i[0] and i[2]+i[0]>i[1]:
    count = count+1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

for i in range(2, N):
    for j in range(1, i):
        for k in range(j):
            if L[j] + L[k] > L[i]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if(2*max(l[i],l[j],l[k])<l[i]+l[j]+l[k]):
                ans+=1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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:
N = int(input())
L = list(map(int,input().split()))

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC143D
import sys
import math
import collections
#sys.setrecursionlimit(100000)


n=int(input())

tmp = input().split()
l = list(map(lambda a: int(a), tmp))

sum=0

for i in range(n):
	for j in range(i+1,n):
		tmp1 = l[i]+l[j]
		tmp2 = abs(l[i]-l[j])
		for k in range(j+1,n):
			if((tmp1>l[k])and(tmp2<l[k])):
				sum+=1
print(sum)

Submission status: Time Limit Exceeded

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

total = 0
for i in range(len(L)-2):
    for j in range(i+1, len(L)-1):
        for k in range(j+1, len(L)):
            if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j]:
                total += 1
print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
l_list = list(map(int,input().split()))
ans = 0
for comb in  itertools.combinations(l_list, 3):
    if(comb[0]<comb[1]+comb[2] and comb[1]<comb[2]+comb[0] and comb[2]<comb[1]+comb[0]):
        ans += 1

print(ans)

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 and j+k > i and k+i > j:
        return True
    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())
llist=list(map(int,input().split()))
kazoe=0
for i in range(n-2):
	for j in range(i+1,n-1):
		for k in range(j+1,n):
			sa=llist[i]-llist[j]
			if llist[i]<llist[j]+llist[k] and llist[j]<llist[i]+llist[k] and llist[k]<llist[i]+llist[j]:
				kazoe+=1
print(kazoe)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = set()
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]:
                if l[i] > l[k]-l[j]:
                    ans.add((l[i], l[j], l[k]))
            else:
                break
print(len(ans))

Submission status: Time Limit Exceeded

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

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-2):
    for j in range(i+1,N-1):
        a = L[i]+L[j]
        l = N-j
        b = l-bisect.bisect_left(L[j+1:],a)
        cnt+=l-b
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
num=int(input().rstrip())
numlis=input().rstrip().split(" ")

s=0
for i in range(num):
    for j in range(i+1,num):
        for k in range(j+1,num):
            a=int(numlis[i])
            b=int(numlis[j])
            c=int(numlis[k])
            #print(a,b,c)
            
            
            if(a<b+c)and(b<a+c)and(c<a+b):
                s+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
N = int(input())
edge = list(map(int, input().split()))
edge.sort()
counter = 0

for i in range(len(edge) - 2):
    A = edge[i]
    for k in range(i + 1, len(edge)):
        B = edge[k]
        Cmin = max(A - B, B - A)
        Cmax = A + B
        for j in range(k + 1, len(edge)):
            if Cmin < edge[j] and edge[j] < Cmax:
                counter += 1
            else:
                break
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0

for subset in itertools.combinations(S, 3):
    a = subset[0]
    b = subset[1]
    c = subset[2]
    if a<b+c and b<c+a and c<a+b:

        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from  itertools import combinations

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

res = 0
for a, b, c in combinations(l, 3):
    if all([a<b+c, b<c+a, c<a+b]):
        res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations,combinations_with_replacement

N = int(input())

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

comb_list = list(combinations(L,3))

ans = 0

for i in range(len(comb_list)):

	a, b, c = comb_list[i]
	if (a < b + c) and (b < a + c) and (c < a + b):
		ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

counter = 0

for num_1, i in enumerate(L):
  for num_2, j in enumerate(L):
    if num_1 <= num_2:
      continue
    else:
      for num_3, k in enumerate(L):
        if num_2 <= num_3:
          continue
        else:
          if i+j >k and j+k>i and k+i>j:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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]
            for k in range(j+1,N):
                if l[k] < tmp:
                    ans +=1
                else:
                    break
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
def main():

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

    # print(L)
    ab =[L[0]+L[1]]
    ans = 0
    for i in range(2, N):
        c = L[i]
        j = bisect.bisect_right(ab, c)
        # print(j)
        # print(ab)
        ans += len(ab) - j
        for k in range(i):
            bisect.insort_left(ab, c+L[k])
        # print(ab)
    return ans

if __name__ == '__main__':
    print(main())

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:
  if a<b+c and b<a+c and c<b+a:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

L.sort()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += bisect.bisect_left(L[j+1::], L[i]+L[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

    comb = itertools.combinations(L, 3)

    ans = 0
    for v in comb:
        if v[0] < v[1] + v[2] and v[1] < v[2] + v[0] and v[2] < v[0] + v[1]:
            ans += 1

    print(ans)


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] and l[j]<l[i]+l[k] and l[k]<l[j]+l[i]:
                num = num + 1

print(num)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
lengths = sorted(map(int, input().split(" ")))

print(sum(1 for x, y, z in combinations(lengths, 3) if z < x + y))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import bisect

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

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        insert_index = bisect.bisect_left(l[j+1:N],l[i]+l[j])
        ans+=(insert_index)
            
print(ans)

Submission status: Time Limit Exceeded

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

import bisect

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

    L = sorted(L)

    ans = 0
    for i in range(N-2):
        for j in range(N-1):
            if j > i:
                ans += bisect.bisect_left(L[j+1:], L[i] + L[j]) - bisect.bisect_left(L[j+1:], L[j] - L[i])

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
# index: 0,...,N-1

ans = 0
for i in range(N-2): # i: 0,...,N-3
    for j in range(i+1, N-1): # j: i+1,...,N-2
        for k in range(j+1, N): # k: j+1,...,N-1
            if Ls[j] - Ls[i] < Ls[k] < Ls[i] + Ls[j]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

res = 0
for i in range(n):
    for j in range(i, n):
        if i!=j:
            ab = l[i]+l[j]
            for k in range(j, n):
                if i!=k and j!=k and l[k] < ab:
                    res += 1
                else:
                    continue

print(res)

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] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
        count += 1
      else:
        break
print(count)

Submission status: Time Limit Exceeded

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

sl = sorted(ll,reverse=True)
count=0

for i1 in range(len(sl)-2):
  for i2 in range(i1+1,len(sl)-1):
    for i3 in range(i2+1,len(sl)):
      if sl[i1] < sl[i2] + sl[i3]:        
        count+=1

print(count)

Submission status: Time Limit Exceeded

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

c=0
for i in range(n-2):
	a = L[i]
	for j in range(i+1,n-1,1):
		for k in range(j+1,n,1):
			if j != n and k != n:
				d = abs(L[j]-L[k])
				s = L[j]+L[k]
				if d<a and a<s:
					c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ll=[0]*(l[-1]+1)

for i in l:
    ll[i]+=1
for i in range(1,len(ll)):
    ll[i]+=ll[i-1]

ans=0
import itertools
for i,j in itertools.combinations(l,2):
    if max(i-j,j-i)<i+j-1:
        ans+=ll[min(len(ll)-1,i+j-1)]-ll[min(len(ll)-1,max(i-j,j-i))]
        if max(i-j,j-i)<i<i+j:
            ans-=1
        if max(i-j,j-i)<j<i+j:
            ans-=1
print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

l3s = list(combinations(l,3))
for l3 in l3s:
    if abs(l3[1] - l3[2]) < l3[0] < (l3[1] + l3[2]):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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-2):
    for j in range(i+1,N-1):
        a = L[i]+L[j]
        l = len(L[j+1:])
        b = l-bisect.bisect_left(L[j+1:],a)
        cnt+=l-b
print(cnt)

Submission status: Time Limit Exceeded

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

print(output)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def solve(pair):
    a,b,c=pair[0],pair[1],pair[2]
    if a<b+c and b<a+c and c<a+b:
        return True
    return False
n=int(input())
arr=list(map(int,input().split()))
c=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if solve([arr[i],arr[j],arr[k]]):
                c+=1
print(c)

Submission status: Time Limit Exceeded

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

input = sys.stdin.readline


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

    ans = 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] + L[c] and L[b] < L[c] + L[a] and L[c] < L[a] + L[b]:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        idx = N - 1
        while idx < N:
            if lst[i] + lst[j] > lst[idx]:
                cnt += idx - max(i,j)
                break
            else:
                idx -= 1
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(N):
    for k in range(N):
      if i <= j or j <= k:
        pass
      else:
        if abs(L[i]-L[j]) < L[k] and L[k] < L[i]+L[j]:
          ans += 1
          
          
print(ans)

Submission status: Time Limit Exceeded

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

def resolve():
    n = int(input())
    targets = list(map(int, input().split()))
    targets.sort()
    ans = 0

    for i in range(len(targets)):
        for j in range(i + 1, len(targets)):
            for k in range(j + 1, len(targets)):
                if check(targets[i], targets[j], targets[k]):
                    ans += 1
                else:
                    continue

    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

res = 0
for i in range(n):
    for j in range(i, n):
        if i!=j:
            ab = l[i]+l[j]
            for k in range(j, n):
                if i!=k and j!=k and l[k] < ab:
                    res += 1
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1,n):
            L = [l[i],l[j],l[k]]
            L.sort()
            if abs(L[0]-L[1]) < L[2] < L[0]+L[1]:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
L= sorted(list(map(int, input().split())))
L = np.array(L)

def find_nearest(array, value):
  idx = (np.abs(array-value)).argmin()
  return idx

count = 0
for i in range(N):
  for j in range(i + 1, N):
    x = L[i] + L [j]
    y = find_nearest(L, x)
    #print(y, j)
    if L[y] < x:
      if y - j > 0:
        count += y - j
    else:
      if y - j > 1:
        count += y - j - 1

print(count)

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
n = int(input())
lst = list(map(int,input().split()))
ans = 0
lst.sort()
for i in range(n):
    for j in range(i+1,n):
        b,c = lst[i],lst[j]
        pos = bisect_left(lst,b+c)
        tmp = n - 1 - pos
        for k in range(j+1,pos):
            x,y,z = lst[i],lst[j],lst[k]
            if x+y>z and y+z>x and z+x>y:
                ans += 1  
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left as bl
from bisect import bisect_right as br
n=int(input())
s=sorted(list(map(int,input().split())))
q=0
d=[[""]*(1001)for i in range(1001)]
for i in range(n):
    for j in range(i+1,n):
        x,y=max(s[i],s[j]),min(s[i],s[j])
        if d[x][y]=="":
            c=br(s,x+y-1)-bl(s,x-y+1)-1
            if x-y<y:
                c-=1
            c=max(c,0)
            d[x][y]=c
        q+=c
print(q//3)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
Ls = list(map(int, input().split()))
seq = list(itertools.combinations(Ls, 3))
ans = 0


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


for s in seq:
    a, b, c = s
    if isTriangle(a, b, c):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

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

import itertools
comb = list(itertools.combinations(ll ,3))
  
ans = len(list(filter(is_triangle, comb)))
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(2,n):
  if l[i-2]+l[i-1]>l[i]:
    for j in range(1,i):
      for h in range(j):
        if (l[i]<l[j]+l[h]) and (l[j]<l[i]+l[h]) and (l[h]<l[i]+l[j]):
          count+=1
print(count)

Submission status: Time Limit Exceeded

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

L.sort()
L.reverse()

res = 0

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

print(res)

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):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if(2*max(l[i],l[j],l[k])<l[i]+l[j]+l[k]):
                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):
    for j in range(i+1, N-1):
        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:
from bisect import bisect_left, bisect_right
n = int(input())
ls = sorted(list(map(int, input().split())))
total = 0
for i in range(n):
    for j in range(i+1, n):
        b, c = ls[i], ls[j]
        lower = abs(b-c) + 0.5
        upper = b+c - 0.5
        ii = bisect_left(ls, lower)
        jj = bisect_left(ls, upper)
        cnt = jj - ii
        if i in range(ii, jj):
            cnt -= 1
        if j in range(ii, jj):
            cnt -= 1
        total += cnt
total //= 3

print(total)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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