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 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]
        li = bisect.bisect(L,l)
        ri = bisect.bisect_left(L,r)
        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().strip().split()))
ans = int(0)
for i in range(n-2):
    for k in range(n-1):
        for m in range(n):
            if i < k and k < m:
                if l[i] < l[k] + l[m] and l[k] < l[i] + l[m] and l[m] < l[i] + l[k]:
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
cnt = 0
j =0
while(j<=N-3):
    k = j+1
    l = j+2
    while(k<=N-2):
        if L[j]<(L[k]+L[l]) and L[k]<(L[l]+L[j]) and L[l]<(L[j]+L[k]):
            cnt+=1
        l+=1
        if l==N:
            k+=1
            l=k+1
    j+=1
print(cnt)

Submission status: Time Limit Exceeded

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

L = sorted(L)
counter = 0

for a, c in itertools.combinations(L, 2):
    ai = bisect.bisect_left(L, a)
    ci = bisect.bisect_left(L, c)
    left = abs(a-c)
    right = a+c
    lefti = bisect.bisect_right(L, left)
    righti = bisect.bisect_left(L, right)
    tmpcounter = righti - lefti
    if lefti <= ai <= righti:
      tmpcounter -= 1
    if lefti <= ci <= righti:
      tmpcounter -= 1
    counter += max(0, tmpcounter)

print(counter//3)

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 (0,N-2):
  max = sum(x >= L[i] / 2 for x in L) 
  for j in range (i+1,max):
    n = sum(x > L[i]-L[j] for x in L[j+1:N]) 
    ans = ans + n
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = input().split()
Li = []
for i in L:
  Li.append(int(i))
ret = 0
for i in range(0, len(Li)-2):
  for j in range(i+1,len(Li)-1):
    for k in range(j+1,len(Li)):
      if Li[i]+Li[j] > Li[k] and Li[j]+Li[k] > Li[i] and Li[k]+Li[i] > Li[j]:
        ret += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
#print(l)
ans=0
for a in range(n-2):
    for b in range(a+1,n-1):
        min_c= max(l[b]-l[a]+1,l[b+1])
        max_c= l[a]+l[b]-1
#        print(str(l[a])+","+str(l[b])+" "+str(min_c) + ":" + str(max_c))
        if(min_c <= max_c):
            ans+=bisect.bisect_right(l, max_c) - bisect.bisect_left(l, min_c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
l = nl()

l = sorted(l)[::-1]

ans = 0


for a in range(n):
    fl = 0
    A = l[a]

    for b in range(a+1,n):
        B = l[b]
        if A > B*2:
            break
        for c in range(b+1,n):

            C = l[c]

            if A >= B + C:
                break

            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

li.sort()
mod_li=[[i,num] for i,num in enumerate(li)]

result=0
for i in range(len(li)-2):
  for j in range(i+1,len(li)-1):
    temp_li=[num for num in mod_li[j+1:]]
    while(len(temp_li)>1):
      if temp_li[len(temp_li)//2][1]>=li[i]+li[j]:
        temp_li=temp_li[:len(temp_li)//2]
      else:
        temp_li=temp_li[len(temp_li)//2:]
    if temp_li[0][1]>=li[i]+li[j]:
      result+=temp_li[0][0]-j-1
    else:
      result+=temp_li[0][0]-j
print(result)

Submission status: Time Limit Exceeded

Solution code:

from sys import stdin
import itertools

n = int(stdin.readline().rstrip())
ls = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
for v in itertools.combinations(ls, 3):
    a=int(v[0])
    b=int(v[1])
    c=int(v[2])
    if a<b+c:
        if b<c+a:
            if c<a+b:
                ans += 1

print(int(ans))

Submission status: Time Limit Exceeded

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

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]]
      b_ = li[i]+li[j]>li[k]
      if b_:
        if t not in all_l:
          all_l.append(t)
          count += 1
      else:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lx = list(map(int,input().split()))
lx = sorted(lx)
mm = 0
for c1 in range(n):
    for c2 in range(c1+1, n):
        for c3 in range(c2+1, n):
            a,b,c = lx[c1], lx[c2], lx[c3]
            if a+b <= c:
                ...
            else:
                mm += 1
            #print(a,b,c)
print(mm)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
lst.append(10**10)
total = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        cnt = 0
        k = j+1
        while lst[j]+lst[i] > lst[k]:
            cnt += 1
            k += 1
        total += cnt
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):
   for j in range(i+1,n):
      for k in range(j+1, n):
         # print(l[j]-l[k])
         if (l[i] < l[j] + l[k] and l[i]>abs(l[j]-l[k])):
            s+=1

print(s)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def Triangles(N, Lrand):
    L = sorted(Lrand, reverse=True)
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            if L[i] >= L[j] * 2: break
            for k in range(j+1, N):
                if L[i] >= L[j] + L[k]: break
                cnt += 1
    return cnt

N = int(input())
L = [int(x) for x in input().split()]
print(Triangles(N, L))

Submission status: Time Limit Exceeded

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

total=0

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

for i in range(len(D)):
    for j in range(i+1,len(D)):
        for k in range(j + 1, len(D)):
            if(check(D[i],D[j],D[k])):
                total+=1

print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

    for comb in combs:
        for l in ls:
            if {comb[a], comb[b], l} not in visited:
                visited.add(frozenset({comb[a], comb[b], l}))
                if l != comb[a] and l != comb[b] and abs(comb[a] - comb[b]) < l < comb[a] + comb[b]:
                    count += 1

    print(count)


if __name__ == '__main__':
    d()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

count = 0
for i in range(N):
    c = L[i]
    for a,b in itertools.combinations(L[i+1:],2):

        if a < b+c and b < c+a and c < a+b:
            # print(a,b,c)
            count+=1
print(count)
# L.sort(reverse=True)
# for i in range(N):
#

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    for j in range(n):
        if i > j:
            for k in range(n):
                    if j > k:
                        if (l_list[i] < l_list[j] + l_list[k]) and (l_list[j] < l_list[i] + l_list[k]) and (l_list[k] < l_list[i] + l_list[j]):
                            count += 1
print(count)

Submission status: Time Limit Exceeded

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

'''
N = int(input())
L = sorted(list(map(int,input().split())))
print(L)
s = N*(N-1)*(N-2)//6
for i in range(N-1,1,-1):
    print('i',i)
    for k in range(i-1):
        print('k',k)
        for t in range(k+1,i):
            print('t',t)
            if L[i] < L[k] + L[t]:
                print('break')
                break
            else:
                s -= 1
                print('s',s)
print(s)
'''

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 - 1, 1, -1):
    for j in range(i - 1, 0, -1):
        d = l[i] - l[j]
        cnt = bisect.bisect_right(l[:j], d)
        if j - cnt <= 0:
            break
        ans += j - cnt


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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = sorted(list(map(int, input().split())))
a = 0
for i in range(len(L)-2):
  if L[i] >= L[i+1] + L[i+2]:
    L.pop(i)
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())
l = list(map(int, input().split()))
l = sorted(l)
res = 0
for i in range(n):
    for j in range(i+1, n, 1):
        a = l[i]
        b = l[j]
        ab = a + b
        f = 0
        for k in range(j+1, n, 1):
            if l[k] < ab:
                res += 1
                f = 1
            else:
                break
        if f == 0:
            continue
print(res)

Submission status: Time Limit Exceeded

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

L = sorted(L)

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ab_num = [i, j]
        #print(ab_num)
        for k in range(j+1, N):
            if k not in ab_num:
                if L[ab_num[0]] + L[ab_num[1]] > L[k]:
                    count += 1


print(count)

Submission status: Time Limit Exceeded

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

    count = 0
    for i in range(N):
        for j in range(i+1, N-1):
            a = L[i]
            b = L[j]
            C = list(filter(lambda x: a + b > x, L[j+1:]))
            for c in C:
                if (b < c + a) and (a < b + c):
                    count += 1
    print (count)

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):
    if a < b + c and b < c + a and c < a + b:
        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

cmb_l = list(combinations(L, 3))


print(len(cmb_l))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1,n-1):
    for j in range(i+1,n):
        if i - bisect.bisect_right(l,(l[j]-l[i])) > 0:
            ans += i - bisect.bisect_right(l,(l[j]-l[i]))
print(ans)

Submission status: Time Limit Exceeded

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

ans=0
Le=len(L)
for x,a in enumerate(L):
	for i in range(x+1,Le-1):
		for ii in range(i+1,Le):
			if a<L[i]+L[ii] and L[i]<a+L[ii] and L[ii]<a+L[i]:
				ans+=1

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(int(i) for i in input().split())
list.sort(l_list, reverse=True)
count = 0
for i in range(n):
    a = l_list[i]
    for j in range(i+1, n):
        b = l_list[j]
        for k in range(j+1, n):
            c = l_list[k]
            if a < b + c and b < c + a and c < a + b:
                count += 1
            else:
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
l = nl()

l = sorted(l)[::-1]

ans = 0


for a in range(n):
    fl = 0
    for b in range(a+1,n):
        if a > b*2:
            break
        for c in range(b+1,n):
            A = l[a]
            B = l[b]
            C = l[c]

            if A >= B + C:
                break

            ans += 1

print(ans)

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(len(l)):
    for j in range(i + 1, len(l)):
        ans += sum(1 for x in l[j+1:] if x < l[i] + l[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

x = 0

from itertools import combinations

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
num = []
ans = 0

for i in itertools.permutations(L, r=3):
    i = list(i)
    i.sort()
    if i not in num:
        num.append(i)

for i in range(len(num)):
    if num[i][0] + num[i][1] > num[i][2] and num[i][1] + num[i][2] > num[i][0] and num[i][0] + num[i][2] > num[i][1]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

def D():
    n = input()
    l = map(int,input().split(" "))
    temp = 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]]
    for i in temp:
        i = sorted(list(i),reverse=True)
        if i[0] < i[1]+i[2]:
            count += 1
    print(count)

if __name__ == '__main__':
    D()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,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):
      if 2*max(L[i],L[j],L[k])<sum([L[i],L[j],L[k]]):
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def tri(a,b,c):
    if (a<(b+c) and b<(c+a) and c<(a+b)):
        return True;
    else:
        return False;
N=int(input())
L=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(tri(L[i],L[j],L[k])):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
L = [int(x) for x in input().split()]
L = sorted(L)
num_triangle = 0

for i in range(N-1, 1, -1):
    a = L[i]
    for j in range(i-1, 0, -1):
        b = L[j]
        c = L[j-1]
        if not a < b+c:
            break
#        print(a, b, L[:j], a-b, bisect.bisect_right(L[:j], a-b))
        num_triangle += len(L[:j]) - bisect.bisect_right(L[:j], a-b)

print(num_triangle)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = map(int,input().split())
tmp = list(itertools.combinations(L,3))
ans = 0
for i in range(len(tmp)):
    if tmp[i][0] < (tmp[i][1] + tmp[i][2]):
        if tmp[i][1] < (tmp[i][0] + tmp[i][2]):
            if tmp[i][2] < (tmp[i][0] + tmp[i][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)
# 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 and B < C + A and C < A + B:
                ans += 1
                # print(A,B,C)
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


def solve():
    pattern_cnt = 0

    for pattern in list(itertools.combinations(L, 3)):
        if (pattern[0] < pattern[1] + pattern[2]) and (pattern[2] < pattern[0] + pattern[1]) and  (pattern[1] < pattern[0] + pattern[2]):
            pattern_cnt += 1

    return pattern_cnt


print(solve())

Submission status: Time Limit Exceeded

Solution code:

from sys import stdin
import itertools

n = int(stdin.readline().rstrip())
ls = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
for v in itertools.permutations(ls, 3):
    #print(v)
    a=int(v[0])
    b=int(v[1])
    c=int(v[2])
    if a<b+c:
        if b<c+a:
            if c<a+b:
                ans += 1

print(int(ans/6))

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()
L.sort()
import numpy as np
L = np.array(L)

cnt = 0
for i in range(N):
    a = L[i]
    L_tmp = L[i+1:]
    for j, b in enumerate(L_tmp):
        L_tmp2 = L_tmp[j+1:]
        cnt += np.sum(L_tmp2 < b+a)

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[int(n) for n in input().split()]
memo=[]
ans=0
for i in range(N):
    for j in range(N):
        if not( (i,j) in memo or (j,i) in memo or i==j):
            memo.append((i,j))
            for k in range(N):
                if k != i and k != j:
                    if max(L[i]-L[j],L[j]-L[i])<L[k] and L[k]<L[i]+L[j]:
                        ans +=1
                        
                    
            
print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

L.sort()
#print(L)
cnt = 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 :
                break
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

sum = 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])):
        sum +=1

print("{}".format(sum))

Submission status: Time Limit Exceeded

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

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

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
            else:
                continue
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l = tuple(l)
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:
# -*- coding: utf-8 -*-

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

L.sort()

count = 0

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


print(str(count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
pole_list = [int(item) for item in input().split()]

triangle_list = []

for i, a in enumerate(pole_list):
    for k, b in enumerate(pole_list):
        for m, c in enumerate(pole_list):

            if a < b + c and b < c + a and c < a + b and i != k and k != m and m != i:
                triangle = sorted([i, k, m])
                triangle_list.append(str(triangle[0]) + str(triangle[1]) + str(triangle[2]))
# print(set(triangle_list))
print(len(set(triangle_list)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def is_rectangle(a,b,c):
    if a + b <= c:
      return False
    if b + c <= a:
      return False
    if c + a <= b:
        return False
    else:
        return True

x = [is_rectangle(a,b,c) for a, b, c in itertools.combinations(L, r=3)]


print(sum(x))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
count = 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] or L[b]>=L[c]+L[a] or L[c]>=L[a]+L[b]:
                pass
            else:
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if length[i] + length[j] > length[k]:
                ans += 1
            else:
                break
print(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(len(L)-2):
	a = L[i]
	for j in range(i+1,len(L)-1):
		b = L[j]
		for k in range(j+1,len(L)):
			if a - b < L[k]:
				count += 1
			else:
				break

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import bisect

def read():
    N = int(input().strip())
    L = list(map(int, input().strip().split()))
    return N, L

def solve(N, L):
    L.sort()
    x = 0
    t = [0 for _ in range(N)]

    t[0] = 0
    t[1] = 0
    t[2] = 1 if L[2] < L[0] + L[1] else 0
    for i in range(3, N):
        t[i] = t[i-1]
        for a, b in itertools.combinations(L[:i], 2):
            t[i] += (L[i] < a + b)
    return t[-1]

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
# n, *a = map(int, open(0))
# M, D = map(int, input().split())
L = list(map(int, input().split()))
# S = input()
cnt = 0
import itertools
l = list(itertools.combinations(L, 2))
import numpy as np
ary = np.array(L)
for t in l:
    # if t[0] + t[1] > t[2] and t[1] + t[2] > t[0] and t[0] + t[2] > t[1]:
    cnt += np.count_nonzero(ary >= sum(t))
tot = (N * (N-1) * (N-2)) // 6
print(tot - cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

print(
    sum(
        (
            cs[0] < (cs[1] + cs[2])
            and (cs[1] < cs[2] + cs[0])
            and (cs[2] < cs[0] + cs[1])
        )
        for cs in combinations(Ls, 3)
    )
)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        a,b = L[i],L[j]
        cnt += sum(abs(a-b)< l < a+b for l in L if l != a and l != b)
print(cnt//3)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
    n = ni()
    l = sorted(na(), reverse=True)

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

main()

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)
"""

llist.sort()
for a in range(n-2):
	for b in range(a+1,n-1):
		c=b+1
		while llist[a]+llist[b]>llist[c] :
			c+=1
			if c==n:
				break
		for d in range(b+1,c):
			if llist[b]-llist[a]<llist[d]<llist[a]+llist[b]:
				kazoe+=1
		c=b+2
print(kazoe)