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:
### D - Triangles ###

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

L.sort()

from itertools import combinations

cb = combinations(L, 2)
cb = list(map(lambda x: sorted(x, reverse=True), cb))
# print(cb)

rslt = 0
m = 100

if N-2 < m:
    m = N-2

for i in cb:
    set_L = L.copy()
    set_L.remove(i[0])
    set_L.remove(i[1])
    split_list = [set_L[i:i+m] for i in range(0, len(set_L), m)]

    for j in split_list:
        if i[0]-i[1]<j[0] and i[1]>=j[0]:
            if i[0]-i[1]<j[-1] and i[1]>=j[-1]:
                # 上界fit, 下界fit
                rslt = rslt + len(j)
            else:
                for k in j:
                    if i[0]-i[1]<k and i[1]>=k:
                        rslt = rslt + 1
                        #print(i, k)
        else:
            if i[0]-i[1]<j[-1] and i[1]>=j[-1]:
                for k in j:
                    if i[0]-i[1]<k and i[1]>=k:
                        rslt = rslt + 1
                        #print(i, k)
            else:
                # 上界fitしない, 下界しない
                None

print(rslt)

Submission status: Time Limit Exceeded

Solution code:
### D - Triangles ###

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

L.sort()

from itertools import combinations

cb = combinations(L, 2)
cb = list(map(lambda x: sorted(x, reverse=True), cb))
# print(cb)

rslt = 0
m = 7

for i in cb:
    set_L = L.copy()
    set_L.remove(i[0])
    set_L.remove(i[1])
    split_list = [set_L[i:i+m] for i in range(0, len(set_L), m)]

    for j in split_list:
        if i[0]-i[1]<j[0] and i[1]>=j[0]:
            if i[0]-i[1]<j[-1] and i[1]>=j[-1]:
                # 上界fit, 下界fit
                rslt = rslt + len(j)
            else:
                for k in j:
                    if i[0]-i[1]<k and i[1]>=k:
                        rslt = rslt + 1
                        #print(i, k)
        else:
            if i[0]-i[1]<j[-1] and i[1]>=j[-1]:
                for k in j:
                    if i[0]-i[1]<k and i[1]>=k:
                        rslt = rslt + 1
                        #print(i, k)
            else:
                # 上界fitしない, 下界しない
                None

print(rslt)

Submission status: Time Limit Exceeded

Solution code:
### D - Triangles ###

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

L.sort()

from itertools import combinations

cb = combinations(L, 2)
cb = list(map(lambda x: sorted(x, reverse=True), cb))
# print(cb)

rslt = 0

for i in cb:
    set_L = L.copy()
    set_L.remove(i[0])
    set_L.remove(i[1])
    split_list = [set_L[i:i+3] for i in range(0, len(set_L), 3)]

    for j in split_list:
        if i[0]-i[1]<j[0] and i[1]>=j[0]:
            if i[0]-i[1]<j[-1] and i[1]>=j[-1]:
                # 上界fit, 下界fit
                rslt = rslt + len(j)
            else:
                for k in j:
                    if i[0]-i[1]<k and i[1]>=k:
                        rslt = rslt + 1
                        #print(i, k)
        else:
            if i[0]-i[1]<j[-1] and i[1]>=j[-1]:
                for k in j:
                    if i[0]-i[1]<k and i[1]>=k:
                        rslt = rslt + 1
                        #print(i, k)
            else:
                # 上界fitしない, 下界しない
                None

print(rslt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted(list(map(int, input().split())))
res = 0
for i in range(len(l)-2):
    for j in range(i+1, len(l)-1):
        #res += len([x for x in l[j+1:] if x < l[i]+l[j]])
        lst = l[j+1:]
        while lst:
            low, high = 0, len(lst)-1
            mid = (low + high)//2
            if lst[mid] < l[i]+l[j]:
                res += mid+1
                lst = lst[mid+1:]
            else:
                lst = lst[:mid]
print(res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
L = np.array(list(map(int, input().split())))
L = np.sort(L)[::-1]
n = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        C = L[j+1:]
        l,r = 0,len(C)
        n_loop = np.floor(np.log2(len(C))).astype(np.int)+1
        while True:
            c = int((l+r)/2)
            if a<b+C[c]:
                l = c+1
            else:
                r = c
            #print(l,r)
            if l == r:
                break
        n += r
        #print(a,b,r,n)
        
print(n)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
L = np.array(list(map(int, input().split())))
L = np.sort(L)[::-1]
n = 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]:
                n += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools as it

N = int(input())
L = np.array(list(map(int, input().split())))
n = 0
for s in it.combinations(L, 3):
    a,b,c = s
    if a<b+c and b<c+a and c<a+b:
        n += 1
print(n)

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):
            if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j]:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from multiprocessing import Pool

### D - Triangles ###
 
N = int(input())
L = list(map(int, input().split()))
 
from itertools import combinations
 
cb = combinations(L, 3)
 
def my_def(x):
    if x[1] + x[2] > x[0]:
        if x[0] + x[2] > x[1]:
            if x[0] + x[1] > x[2]:
                return(1)
    return(0)
 
print(sum(list(map(my_def, cb))))

Submission status: Time Limit Exceeded

Solution code:
### D - Triangles ###
 
N = int(input())
L = list(map(int, input().split()))
 
from itertools import combinations
 
cb = combinations(L, 3)
 
def my_def(x):
    if x[1] + x[2] > x[0]:
        if x[0] + x[2] > x[1]:
            if x[0] + x[1] > x[2]:
                return(1)
    return(0)
 
print(sum(list(map(my_def, cb))))

Submission status: Time Limit Exceeded

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

t=0
c=0
for i in range(N):
    for j in range(i+1,N):
        t=A[i]+A[j]
        for k in range(j+1,N):
            if((max(A[i],A[j],A[k])*2)<(t+A[k])):
                c+=1
            else:
                break
print(c)

Submission status: Time Limit Exceeded

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

t=0
c=0
for i in range(N):
    for j in range(i+1,N):
        t=A[i]+A[j]
        for k in range(j+1,N):
            if((max(A[i],A[j],A[k])*2)<(t+A[k])):
                c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
Ls = np.sort(list(map(int, input().split())))
count = 0
for i in range(N-2):
    a = Ls[i]
    for k in range(N-i-2):
        ab = a + Ls[i+1:N-1-k]
        c = Ls[N-k-1]
        count = count + np.count_nonzero(ab - c > 0)
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


counter = 0
for i, l1 in enumerate(ls):
    j = i+1
    for l2 in ls[i+1:]:
        for l3 in ls[j+1:]:
            if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l2 + l1:
                counter += 1
        j += 1

print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
### D - Triangles ###

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

from itertools import combinations

cb = combinations(L, 3)

def my_def(x):
    if x[1] + x[2] > x[0]:
        if x[0] + x[2] > x[1]:
            if x[0] + x[1] > x[2]:
                return(1)
    return(0)

print(sum(list(map(my_def, cb))))

Submission status: Time Limit Exceeded

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

from itertools import combinations

cb = combinations(L, 3)

def my_def(x):
    #cb.sort
    if x[1] + x[2] > x[0]:
        if x[0] + x[2] > x[1]:
            if x[0] + x[1] > x[2]:
                return(True)
    return(False)

print(sum(list(map(my_def, cb))))

Submission status: Time Limit Exceeded

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

from itertools import combinations

cb = list(combinations(L, 3))

def my_def(x):
    if x[0] + x[1] > x[2]:
        if x[1] + x[2] > x[0]:
            if x[0] + x[2] > x[1]:
                return(True)
    return(False)

print(sum(list(map(my_def, cb))))

Submission status: Time Limit Exceeded

Solution code:
### D - Triangles ###

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

# N = 7
# L = [218, 786, 704, 233, 645, 728, 389]

from itertools import combinations

cb = list(combinations(L, 3))

my_lambda = lambda x : x[0] + x[1] > x[2] and x[1] + x[2] > x[0] and x[0] + x[2] > x[1]

print(sum(list(map(my_lambda, cb))))

Submission status: Time Limit Exceeded

Solution code:
### D - Triangles ###

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

from itertools import combinations

cb = list(combinations(L, 3))

my_lambda = lambda i : cb[i][0] + cb[i][1] > cb[i][2] and cb[i][1] + cb[i][2] > cb[i][0] and cb[i][0] + cb[i][2] > cb[i][1]

print(sum(list(map(my_lambda, range(0, len(cb))))))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    t = 0
    for ai, a in enumerate(L):
        hi = ai + 1
        for bi, b in enumerate(L[ai + 1:], ai + 1):
            ab = a + b
            lo = hi
            hi = len(L) - 1
            while lo != hi:
                mid = (lo + hi + 1) // 2
                if L[mid] < ab:
                    lo = mid
                else:
                    hi = mid - 1
            t += hi - bi
    print(t)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    t = 0
    for ai, a in enumerate(L):
        for bi, b in enumerate(L[ai + 1:], ai + 1):
            ab = a + b
            lo = bi
            hi = len(L) - 1
            while lo != hi:
                mid = (lo + hi + 1) // 2
                if L[mid] < ab:
                    lo = mid
                else:
                    hi = mid - 1
            t += hi - bi
    print(t)


main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort(reverse = True)
cnt = 0
for i in range(N):
  for j in range(i+1,N):
    k = j+1
    while k < N and L[k] > L[i] - L[j] :
      cnt += 1
      k += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
 
for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if i == j or j == k or i == k:
                continue
            elif d[i] + d[j] <= d[k]:
                break
            else:
                ans += 1
print(ans)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted(list(map(int,input().split())))
 
count = 0 
 
for i in range(n - 2):
    for j in range(i+1,n-1):
        
        if l[i] + l[j] > l[n-1]:
            count += n-j-1
            
            continue
        
        low = j+1
        high = n-1
        
        while low < high:
            
            mid = (low + high)//2
            
            if l[i] + l[j] > l[mid]:
                
                low = mid +1
            
            else:    
                
                high = mid 
        else:
            
            count += low - j -1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

sum=0
for i in range(N-2):
    for j in range(i+1,N-1):
         left=j
         right=N-1
         mid=(left+right)//2
         while right-left>1:
             if L[mid]>=L[i]+L[j]:
                 right=mid
                 mid=(mid+left)//2
             else:
                 left=mid
                 mid=(mid+right)//2        
         sum=sum+left-j
         if L[N-1]<L[i]+L[j]:
             sum=sum+1   
        


print(sum)

Submission status: Time Limit Exceeded

Solution code:
def triangle_search(list,item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) // 2
        if mid == high:
            return mid
        elif mid == low:
            return mid
        elif list[mid] > item >= list[mid+1]:
            return mid
        elif list[mid + 1] > item:
            low = mid + 1
        else:
            high = mid - 1
    return mid

N = int(input())
L = list(map(int,input().split()))
L.sort()
L.reverse()
ans = 0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if triangle_search(L,L[i]-L[j]) > j:
            ans = ans + triangle_search(L,L[i]-L[j]) - j 
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from math import *

def main():
    n = int(input())
    l = list(map(int, input().split()))
    cnt = 0
    l.sort()
    for i in range(0, len(l)):
        for j in range(i + 1, len(l)):
            # Start a binary search for the valid third segments
            lower = j
            upper = len(l)
            while upper - lower > 1:
                mid = lower + (upper - lower) // 2
                if l[mid] < l[j] + l[i]:
                    lower = mid
                else:
                    upper = mid
            cnt += lower - j
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    l = list(map(int, input().split()))
    cnt = 0
    for i in range(0, len(l)):
        for j in range(i + 1, len(l)):
            for k in range(j + 1, len(l)):
                a, b, c = l[i], l[j], l[k]
                if a < b + c and b < c + a and c < a + b:
                    cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(l)-2):
    for j in range(i+1, len(l)-1):
        a1 = l[i] + l[j]
        for k in range(j+1, len(l)):
            if l[k] < a1:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

check_i = 0
check_j = 0
count = 0 

for i in reversed(range(0,n)):
    if l[i] == check_i:
        check_i = l[i]
        continue
    
    for j in reversed(range(1,i)):
        
        if l[j] == check_j:
            check_j = l[j]
            continue
        
        
        
        if l[i] - l[j] >= l[j-1]:
            continue
        
        low = 0
        high = j-1
        
        while low < high:
            
            mid = (low + high)//2
            
            if l[i] - l[j] >= l[mid]:
                
                low = mid +1
            
            else:    
                
                high = mid
        else:
            
            count += len(set(l[low:j]))
print(count)

Submission status: Time Limit Exceeded

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

check_i = 0
check_j = 0
count = 0 

for i in reversed(range(0,n)):
    if l[i] == check_i:
        check_i = l[i]
        continue
    
    for j in reversed(range(1,i)):
        
        if l[j] == check_j:
            check_j = l[j]
            continue
        
        if l[i] - l[j] >= l[j-1]:
            continue
        
        low = 0
        high = j-1
        
        while low < high:
            
            mid = (low + high)//2
            
            if l[i] - l[j] >= l[mid]:
                
                low = mid +1
            
            else:    
                
                high = mid
        else:
            
            count += len(set(l[low:j]))
print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for i,n1 in enumerate(l):
    for j,n2 in enumerate(l):
        if i < j:
            a1 = n1 + n2
        else:
            continue
        for k,n3 in enumerate(l):
            if j < k and n3 < a1:
                ans += 1
            else:
                continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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):
        length = l[i] + l[j]
        cnt += bisect.bisect_left(l[j+1:], length)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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):
        cnt += bisect.bisect_left(l[j+1:], l[i]+l[j])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
l = sorted(list((map(int, input().split()))))
m = len(l)
cnt = 0
for i in range(m - 2):
    for j in range(i + 1, m - 1):
        cnt += bisect.bisect_left(l[j+1:], l[i]+l[j])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
l = np.array(sorted(list((map(int, input().split())))))
m = len(l)
cnt = 0
for i in range(m - 1):
    for j in range(i + 1, m):
        cnt += np.sum(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()))
l.sort()
count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        k=j+1
        while l[i]+l[j]>l[k]:
            k+=1
            if k==n:
                break
        count+=k-j-1

print(count)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# D
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 abs(L[i]-L[j]) < L[k] and L[k] < L[i] + L[j]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
data=input().split()
count=0
 
for i in range(num):
  for j in range(num-1-i):
    for k in range(num-2-i-j):
      a=int(data[i])
      b=int(data[i+1+j])
      c=int(data[i+1+j+1+k])
      if a+b>c and b+c>a and c+a>b:
        count+=1
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
ll = list(map(int,input().split()))
n=ll[0]
l = list(map(int,input().split()))
l.sort(reverse=True)
ret=0
 
for i in range(len(l)):
    for o in range(i+1,len(l)):
        for p in range(o+1,len(l)):
            if(l[i]<l[o]+l[p]):
                ret+=1
 
print(ret)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
counter = 0
for i1 in range(len(L)-2):
    for i2 in range((i1+1),(len(L)-1)):
        for i3 in range((i2+1),len(L)):
            if L[i1] < L[i2]+L[i3]:
                counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
ll = list(map(int,input().split()))
n=ll[0]
l = list(map(int,input().split()))
l.sort(reverse=True)
ret=0

for i in range(len(l)):
    for o in range(i+1,len(l)):
        for p in range(o+1,len(l)):
            if(l[i]<l[o]+l[p]):
                ret+=1

print(ret)

Submission status: Time Limit Exceeded

Solution code:
ll = list(map(int,input().split()))
n=ll[0]
l = list(map(int,input().split()))
ret=0

for i in range(len(l)):
    for o in range(i+1,len(l)):
        for p in range(o+1,len(l)):
            if(
                l[i]<l[o]+l[p] and 
                l[o]<l[i]+l[p] and 
                l[p]<l[i]+l[o]
                ):
                ret+=1

print(ret)

Submission status: Time Limit Exceeded

Solution code:
def culc(s,c,l,b,x,y):
    if s == l-1:
        return s
    if x+y >b[c]:
        s = c
        c = int((c+l)/2)
        return culc(s,c,l,b,x,y)
    else:
        l = c
        c = int((c+s)/2)
        return culc(s,c,l,b,x,y)
    
    
N = int(input())
b = list(int(i) for i in input().split())
b.sort()
sum_N = 0
for i,x in enumerate(b):
    s = i+1
    for y in range(i+1,N,1):
        c = int((i+N)/2)
        lim_num =culc(s,c,N,b,x,b[y])
        sum_N += lim_num-y
        s=lim_num
print(sum_N)

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
data=input().split()
count=0

for i in range(num):
  for j in range(num-1-i):
    for k in range(num-2-i-j):
      a=int(data[i])
      b=int(data[i+1+j])
      c=int(data[i+1+j+1+k])
      if a+b>c and b+c>a and c+a>b:
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def culc(s,c,l,b,x,y):
    if s == l-1:
        return s
    if x+y >b[c]:
        s = c
        c = int((c+l)/2)
        return culc(s,c,l,b,x,y)
    else:
        l = c
        c = int((c+s)/2)
        return culc(s,c,l,b,x,y)
N = int(input())
b = list(int(i) for i in input().split())
b.sort()
sum_N = 0
for i,x in enumerate(b):
    for y in range(i+1,N,1):
        c = int((i+N)/2)
        lim_num =culc(i+1,c,N,b,x,b[y])
        sum_N += lim_num-y
print(sum_N)

Submission status: Time Limit Exceeded

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

n = int(input())
l = sorted(list(map(int, input().split(' '))), reverse = True)

ans = 0
for ai in range(len(l)-2):
    a = l[ai]
    for bj in range(ai+1, len(l)-1):
        b = l[bj]
        for ck in range(bj+1, len(l)):
            c = l[ck]
            if a < b+c:
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = sorted(list(map(int, input().split())))
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = j+1
    while k < N and nums[k] < nums[i]+nums[j]:
      k += 1
    count += k-j-1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
b = list(int(i) for i in input().split())
b.sort(reverse=True)
sum_N = 0
for i,x in enumerate(b):
    for y in range(i+1,N,1):
        for z in range(y+1,N,1):
            if x>=b[y]+b[z]:
                break
            else:
                sum_N +=1
print(sum_N)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

def binary_search(imin, imax, target):
    if imin > imax:
        return imin

    imid = (imin + imax) // 2
    if L[imid] == target:
        return imid
    elif L[imid] < target:
        return binary_search(imid+1, imax, target)
    else:
        return binary_search(imin, imid-1, target)

counter = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        upper_bound = binary_search(j+1, N-1, L[i] + L[j])
        counter += upper_bound - (j+1)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

def binary_search(imin, imax, target):
    if imin > imax:
        return imin

    imid = (imin + imax) // 2
    if L[imid] == target:
        return imid
    elif L[imid] < target:
        return binary_search(imid+1, imax, target)
    else:
        return binary_search(imin, imid-1, target)

counter = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        # 許容されるcの値は
        # L[j] < c
        # c < L[i] + L[j]
        upper_bound = binary_search(j+1, N-1, L[i] + L[j])
        counter += upper_bound - (j+1)
print(counter)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        for c in L[j+1:]:
            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())) 

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())  #数値入力 「N」だけの入力のとき
l=list(map(int, input().split())) 
count = 0
for i in range(0, n-2):
   for j in range(i+1, n-1):
       for k in range(j+1, n):
          temp_max = max(l[i], l[j], l[k])
          if l[i]+l[j]+l[k] - temp_max > temp_max:
              count = count + 1
print(count)