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:
from bisect import bisect_left,bisect_right

n=int(input())
l=sorted(list(map(int,input().split())))
cnt=0
for i in range(n):
    lim=False
    for j in range(i+1,n):
        MIN=abs(l[i]-l[j])
        MAX=l[i]+l[j]
        min_idx=max(bisect_right(l,MIN),j+1)
        if not lim:
            max_idx=bisect_left(l,MAX)
            if max_idx==n:lim=True
        res=max_idx-min_idx
        if min_idx<=i<=max_idx:res-=1
        if min_idx<=j<=max_idx:res-=1
        cnt+=max(res,0)
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:
                continue
            if L[i]+L[j] > L[k] and abs(L[i]-L[j]) < L[k]:
                #print("i: ", i)
               # print("j: ", j)
               # print("k: ", k)
                ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

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


ans = 0
for a in range(N-2):
    for b in range(a+1, N-1):
        for c in range(b+1, N):
            # print(L[a], L[b], L[c])
            if L[a] < L[b]+L[c] and L[b] < L[a]+L[c] and L[c] < L[a]+L[b]:
                ans += 1

print(ans)

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 C(n,r):
    if n < 0 or r < 0 or n < r: 
        return 0
    elif n == 0 or r == 0: 
        return 1
    return C(n-1,r-1)+C(n-1,r)

def main():
    n = ni()
    l = sorted(na())

    j = n - 2
    k = n - 1
    cnt = 0
    dame = []
    for i in range(n - 3, -1, -1):
        try:
            if i in dame or j in dame or k in dame:
                continue
            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 - len(dame) - 1, 2)
                j -= 1
                k -= 1
            else:
                tmp = j
                while True:
                    a = l[i]
                    b = l[j]
                    c = l[k]
                    if a < b + c and b < a + c and c < a + b:
                        break
                    j += 1
                    k += 1
                    tmp = j
                cnt += C(n - tmp - 1 - len(dame), 2)
                dame.append(i)
        except:
            break
    print(cnt)

main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
ans=0
len_L=len(L)
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]:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = sorted(l)

res = {}
comb = list(itertools.combinations(l, 3))
count = 0
for i in range(len(comb)):
    a = comb[i][0]
    b = comb[i][1]
    c = comb[i][2]
    if '{}{}{}'.format(a, b, c) in res:
        count += 1
        continue
    if a + b <= c:
        continue
    elif a + c <= b:
        continue
    elif b + c <= a:
        continue
    else:
        count += 1
        res['{}{}{}'.format(a, b, c)] = 'Good'

print(count)

Submission status: Time Limit Exceeded

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

triangle = 0

c = []
for i in range(len(L)):
  for j in range(i + 1, len(L)):
    for k in range(j + 1, len(L)):
      c.append([L[i], L[j], L[k]])

for i in range(len(c)):
    if (c[i][0] < c[i][1] + c[i][2]
            and c[i][1] < c[i][0] + c[i][2]
            and c[i][2] < c[i][1] + c[i][0]):
        triangle += 1

print(triangle)

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]
        for k in range(j+1,N):
            c = L[k]
            if a < b+c:
                sum = sum + 1
            else:
                break

print sum

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[23]:


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


# In[27]:


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


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:

import bisect 

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

l_list.sort()


cnt = 0

for a in range(N):
    for b in range(N):
        if a >= b:
            continue

        i = bisect.bisect_left(l_list[b+1:], (l_list[a] + l_list[b]))
        #print(l_list[b+1:], l_list[a] + l_list[b], i)
        cnt = cnt + i
        #print("!")
        #if i != len(a):
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = str(input())
c = b.split(" ")
ans = 0
for i in range(a):
  for j in range(a):
    if j<=i:continue
    for k in range(a):
      if k<=i or k<=j:continue
      if (int(c[i]) < (int(c[j])+int(c[k]))) and (int(c[j]) < (int(c[i])+int(c[k]))) and (int(c[k]) < (int(c[i])+int(c[j]))):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().strip().split()))
l.reverse()
ans = int(0)
for i in range(n-2):
    for k in range(n-2):
        for m in range(n-2):
            if i < k + 1 and k < m + 1:
                x = abs(l[k+1]-l[m+2])
                if x < l[i] < l[k+1] + l[m+2]:
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split())) 
tk = list(itertools.combinations(A, 3))
count = 0
 
for i in range(len(tk)):
    test = tk[i]
    if (test[0] < test[1] + test[2] )and(test[1] < test[2] + test[0]) and (test[2] < test[0] + test[1]):
        count += 1
        
print(count)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    d = sorted(list(map(int, input().split())))[::-1]
    ans = 0
    for i in range(n-2):
        d1 = d[i]
        if d[i+2] + d[i+1] > d[i]:
          ans += len([1 for j in range(i+1, n-1) for k in range(j+1, n) if d[k] + d[j] > d1])
    print(ans)
  
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

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

x = 0

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
count=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if l[i]>=l[j]+l[j+1]:
      break
    for h in range(j+1,n):
      if l[i]>=l[j]+l[h]:
        break
      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:
import itertools

N = int(input())
L = list(map(int,input().split()))
def all_check(target):
    if check(target,0,1,2)+check(target,1,2,0)+check(target,2,0,1) == 3:
        return 1
def check(target,i,j,k):
    if target[i] < target[j]+target[k]:
        return 1
    return 0
counts = [1 for v in itertools.combinations(L,3) if all_check(v) == 1]
print(len(counts))

Submission status: Time Limit Exceeded

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

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

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

    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
ls = sorted(map(int, input().split()))

count = 0
# 1辺
for i in range(n - 2):
    # 2辺
    for j in range(i + 1, n - 1):
        border = ls[i] + ls[j]
        # 3辺
        for k in range(j + 1, n):
            if ls[k] >= border:
                break

            count += 1

print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N - 2):
    a = L[i]
    j, k = i + 1, i + 2

    while j != N - 1:
        if k == N:
            j += 1
            k = j + 1
            continue

        b, c = L[j], L[k]
        if b - c >= a:
            if k - j != 1:
                j += 1
            else:
                k += 1
            continue
        if b + c <= a:
            j += 1
            k = j + 1
            continue

        ans += 1
        k += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
 
cnt = 0
for i in range(N-2):
  A = L[i]
  break_number = i+2
  if not i == 0:
    break_number = break_first
  for j in range(i+1,N-1):
    B = L[j]
    for k in range(break_number,N):
      if L[k] >= A + B:
        cnt += k - j - 1
        break_number = k
        if j == i+2:
          break_first = k
        break
      if k == N-1:
        cnt += N - 1 - j
        break_number = k
        if j == i+2:
          break_first = k
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[int(_) for _ in input().split()]
L.sort(reverse=True)
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]]
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
 
N = int(input())
L = [int(v) for v in sys.stdin.readline().split()]

print(len([0 for a, b, c in itertools.combinations(L, 3) if a + b > c and b + c > a and a + c > b]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        min_range = abs(L[i] - L[j])
        max_range = L[i] + L[j]
        if max_range - min_range <= 1:
            continue
        # print(L[j+1:])
        # print((min_range < L[j+1:]) & (L[j+1:] < max_range))
        ans += np.count_nonzero((min_range < L[j+1:]) & (L[j+1:] < max_range))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split(" ")))
l.sort()
l.reverse()
cnt = 0 
for i in range(0,n-2):
    flag = False
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        if i == j:
            continue
        for k in range(j+1,n):
            if i == k and j == k:
                continue
            c = l[k]
            if a >= b + c:
                flag=True
                break
            if a < b + c and b < a + c and c < a + b:
                cnt+=1
            else:
                flag=True
                break
        if flag:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
L = list(map(int, inputs[1].split()))

sort_L = sorted(L)
ans = 0
for i in range(n-2):
    a = sort_L[i]
    for j in range(i+1, n-1):
        b = sort_L[j]
        d, e = b-a, a+b
        for k in range(j+1, n):
            c = sort_L[k]
            if d < c:
                if c < e:
                    ans += 1
                else:
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations 
input = sys.stdin.readline

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

l.sort()
cnt = 0

for n,i in enumerate(l):
    for m,j in enumerate(l[n+1:],n+1):
        lst=[]
        lst = list([c for c in set(l[m+1:]) if c<=i+j-1])
        cnt += len(lst)
       
print(cnt)

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 - 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[j] < L[i] + L[k]:
                    count += 1
            else:
                break
        continue
    continue


print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
l = list(map(int,input().split()))
co = []
ol = sorted(l)
nl = sorted(l,reverse=True)
for i in range(1,n):
    for j in range(1,n):
        if i<j:
            co.append(nl[i]+nl[j])
nco = list(reversed(co))
sk = 0
g = 0
for i in range(2,n):
    a = ol[i]
    x = nco[:(i)*(i-1)//2]
    ind = bisect.bisect(x,a)
    g += len(x)-ind
print(g)

Submission status: Time Limit Exceeded

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

ans=0

temp=[] #長辺とそれ以外の辺との長さの差を記録しておく

for i in range(2,n): #各長辺について調べる。

  maetonosa=l[i]-l[i-1]
  #今調べてる項の1つ前の項を含む組み合わせについて、
  #調べてる項との差を新たにtempに挿入
  for j in temp[:]:
    if j>maetonosa:
      ans+=1
      j-=maetonosa
    else:
      temp.remove(j)

  for j in range(i-1):
    temp2=l[i-1]+l[i-2-j] #1つ前の項と、(順番に小さくしてく)l[i-2-j]との和
    if temp2>l[i]:#temp2が長辺より大きいか調べる
      ans+=1 #大きいなら答えを1足す
      temp.append(temp2-l[i])
    else:
      break #それ以降を調べる必要がないためjについてのfor文を終了

print(ans)

Submission status: Time Limit Exceeded

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

L = sorted(L)
ans = 0
H = {}
for i in range(N-1):
    for j in range(i+1, N-1):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(h[1]+1, N):
#        if h[0] == j or h[1] == j: continue
        if v > L[j]:
            ans += 1
        else: break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import heapq

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

N = int(input())
L = list(map(int, input().split()))
# L.sort(reverse=True)
L_sort = heapsort(L)
# print (L)
answer = 0
for i in itertools.combinations(L_sort, 3):
    # print(i)
    if i[2] < i[0] + i[1]:
        answer += 1
print(answer)

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

Submission status: Time Limit Exceeded

Solution code:
#D
n = int(input())
lb = list(map(int,input().split()))
###
defaultans = int(n*(n-1)*(n-2)/6)
###
lb.sort()
cnt = defaultans
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a, b, c = lb[i], lb[j], lb[k]
            if c >= a+b:
                cnt -= n - k 
                break
print(cnt)

Submission status: Time Limit Exceeded

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

res = 0
for i in range(N-2):
  for j in range(N-i-2):
    bc = L[j+i+1] - L[i]
    ca = L[j+i+1] + L[i]

    for k in range(N-i-j-2):
      if bc < L[i+j+k+2] < ca:
        res += 1
      else:
      	break
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools                     
                                     
N = int(input())                                   
d = sorted(map(int, input().split())) 
cnt = 0 
                                               
for x in itertools.combinations(d, 3):
    if (x[0] + x[1]) > x[2] and (x[0] + x[2]) > x[1] and (x[2] + x[1]) > x[0]:                                                    
        cnt += 1                       
print(cnt)

Submission status: Time Limit Exceeded

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

import itertools
l = list(itertools.combinations(L, 3))

a = 0
n = 0

for x in range(len(l)):
  if max(l[n]) < sum(l[n]) - max(l[n]):
    a += 1
    n += 1
  else:
    n += 1
    
print(a)

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
        if int(L_sort[j]) + int(L_sort[k]) <= int(L_sort[i]):
            break
        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())
l = sorted(list(map(int, input().split())))

from bisect import bisect_left, bisect_right

cnt = 0
for i in range(N):
    a = l[i]
    for j in range(i, N):
        if i == j:
            continue
        b = l[j]
        l2 = l[:i] + l[i+1:j] + l[j+1:]
        start = bisect_right(l2, b-a)
        end = bisect_left(l2, a+b)
        cnt += len(l2[start:end])
print(cnt//3)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
L.sort()
tot = 0
for _ in range(N - 2):
    A = L.pop()
    for j in range(len(L) - 1, 0, -1):
        B = L[j]
        for i in range(j - 1, -1, -1):
            if A < B + L[i]:
                tot += 1
            else:
                break
print(tot)

Submission status: Time Limit Exceeded

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

L = sorted(L)
ans = 0
H = {}
for i in range(N-1):
    for j in range(i+1, N-1):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(h[1]+1, N):
#        if h[0] == j or h[1] == j: continue
        if h[1]>=j: continue
        if v > L[j]:
            ans += 1
        else: break

print(ans)

Submission status: Time Limit Exceeded

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

l = list(l)
for i in range(n):
	l[i] = int(l[i])
l.sort()
count = 0
#a<b+c, a>b-c, a>c-b
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]:
				count += 1
			else:
				break

print(count)

Submission status: Time Limit Exceeded

Solution code:

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

x = 0


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

L = np.array(sorted(L, reverse=True))

ans = 0

for n in range(0,N-2):
    if L[n] > 2* L[n+1]:
        pass
    else:
        for o in range(n+1,N-1):
            ans += np.sum(L[o+1:]>L[n]+-L[o])
                
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sticks = sorted([int(s) for s in input().split()])
point = 0
 
for i in range(n-2):
  if sticks[i]*2 >= sticks[-1]:
    break
  else:
    for j in range(n - i- 2):
      a = sticks[i] + sticks[i+j+1]
      for k in range(1,n):
        if sticks[-k] >= a:
          point+=1
        else:
          break
      
    
print(int(n*(n-1)*(n-2)/6)-point)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
cnt = 0
 
for i in range(n-2):
    for j in range(i+1,n-1):
        cnt += np.count_nonzero(np.array(l[j+1:])>l[i]-l[j])
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0
L.sort(reverse=True)

for i in range(N-2):
    if L[i] > L[i+1] + L[i+2]:
        continue
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] + L[j] > L[k] and L[i] + L[k] > L[j] and 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(reverse=True)
ans = 0
for i in range(n-2):
    tmp = 0
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a, b, c = L[i], L[j], L[k]
            if a < b + c and b < a + c and c < a + b:
                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()])
L = np.sort(L)

result = 0

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

print(result)

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(2,n):
    ff=list(range(1,i))
    ff.reverse()
    for j in ff:
        if  l[j]*2<=l[i]:
            break
    for j in range(1, i):
        for k in range(0,j):
            if l[i]<l[j]+l[k]:
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
hsh=[0]*2001
jdg=[[[] for i in range(1001)] for j in range(1001)]
l=list(map(int,input().split()))
for i in range(n):
    hsh[l[i]]=1;
l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(abs(l[i]-l[j])+1,l[i]+l[j]):
            nums=[l[i],l[j],k]
            nums.sort()
            flg=0
            tmp=0
            #print(jdg[nums[0]][nums[1]])
            while(tmp<len(jdg[nums[0]][nums[1]])):
                if jdg[nums[0]][nums[1]][tmp]==nums[2]:
                    flg=1
                    #print("!!"+str(jdg[nums[0]][nums[1]][tmp])+" "+str(nums[2]))
                    break
                tmp+=1
            #print(str(k)+":["+str(hsh[k])+"]",end=" ")
            if hsh[k]==1 and k!=l[i] and k!=l[j] and flg==0:
                #print("THROUGH at "+str(l[i])+" "+str(l[j])+" "+str(k),end="##")
                ans+=1
                jdg[nums[0]][nums[1]].append(nums[2])
print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(N):
  for j in range(i+1, N):
    climit = ll[i] + ll[j]
    for k in range(j+1, N):
      if ll[k] >= climit:
        break
      if is_triangle(ll[i], ll[j], ll[k]):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import numpy as np
input = sys.stdin.readline


def main():
    n = int(input())
    l = np.array(list(map(int, input().split())))
    l = np.sort(l)

    result = 0
    # print(l)
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            target = l[j + 1:]
            count = np.count_nonzero(target < (l[i] + l[j]))
            # print(l[i], l[j], target, count)
            result += count

    print(result)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l_list = list(map(int,input().split()))
import numpy as np

l_np = np.array(l_list)

import itertools
comb_list = list(itertools.combinations(np.sort(l_np),3))
count = 0
for i in range(len(comb_list)):
    if comb_list[i][0] + comb_list[i][1] + comb_list[i][2] > comb_list[i][2] * 2:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n = int(input())
    l = 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)
    
    
if __name__ == '__main__':
    solve()

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
            else:
                l = N-1
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

num = input()
stickLengths = list(map(int, input().split()))
counter = 0

combinations = itertools.combinations(stickLengths, 3)

for v in combinations:
    if v[0] < v[1] + v[2]:
        if v[1] < v[2] + v[0]:
            if v[2] < v[0] + v[1]:
                counter += 1
            else:
                continue
        else:
            continue
    else:
        continue

print(counter)

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

  c-=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
#a,b = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
#print(li)
num = 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] and li[i]<li[j]+li[k] and li[i]+li[k]>li[j]:
                num += 1
                #print(li[i],li[j],li[k])
print(num)

Submission status: Time Limit Exceeded

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

# print(N)
# print(L)

# print(range(N))
# print(range(1, N))
# print(range(2, N))

count = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if not(L[i] < L[j] + L[k]):
                continue
            if not(L[j] < L[i] + L[k]):
                continue
            if not(L[k] < L[i] + L[j]):
                continue
            # print('{}, {}, {}'.format(i, j, k))
            count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

L.sort(reverse=True)

List = deque()
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(len(List)):
        if List[j] > L[i]:
            Sum += 1

    for j in range(N-2-i):
        List.popleft()

print(Sum)

Submission status: Time Limit Exceeded

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