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_right

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

for i in reversed(range(2, n)):
    for j in reversed(range(1, i)):
        ans += j - bisect_right(order[0:j], order[i]-order[j])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
while len(l) >= 3:
  max_l = l.pop()
  for i in range(1, len(l)):
    rest_l = max_l - l[i]
    if rest_l >= l[i - 1]:
      continue
    for j in range(i):
      if l[j] > rest_l:
        triangle += i - j
        break
print(triangle)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
while len(l) >= 3:
  max_l = l.pop()
  for i in range(1, len(l)):
    rest_l = max_l - l[i]
    for j in range(i):
      if l[j] > rest_l:
        triangle += i - j
        break
print(triangle)

Submission status: Time Limit Exceeded

Solution code:
import itertools
#import random
import time
n = int(input())
l = map(int,input().split())
t1 = time.time()
#l = [random.randint(1,999) for i in range(500)]
t2 = time.time()
m = list(itertools.combinations(l,3))
t3 = time.time()
z = [1 for i in m if abs(i[1]-i[2]) < i[0] < i[1] + i[2] ]
t4 = time.time()
#print(len(m))
#print(t2-t1,t3-t2,t4-t3)
print(sum(z))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        big = l[i]+l[j]
    
        ch_max = n
        ch_min = j+1
        
        while ch_min < ch_max:
            ch_i = (ch_min + ch_max) // 2
            if l[ch_i] < big:
                ch_min = ch_i + 1
            else:
                ch_max = ch_i
                
        big_i = ch_max
        
        ans += big_i - (j + 1)
                
print(ans)

Submission status: Time Limit Exceeded

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

m = list(itertools.combinations(l,3))
cnt = 0

for i in m:
	if abs(i[1]-i[2]) < i[0] < i[1] + i[2]:
		cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,*l = map(int, open(0).read().split())

for i in range(n):
    min = 1001
    min_j = -1
    for j in range(i, n):
        if l[j] < min:
            min = l[j]
            min_j = j
    l[i], l[min_j] = l[min_j], l[i]
    
ans = 0
for i in range(n):
    for j in range(i+1, n):
        big = l[i]+l[j]
    
        ch_max = n
        ch_min = j+1
        
        while ch_min < ch_max:
            ch_i = (ch_min + ch_max) // 2
            if l[ch_i] < big:
                ch_min = ch_i + 1
            else:
                ch_max = ch_i
                
        big_i = ch_max
        
        ans += big_i - (j + 1)
                
print(ans)

Submission status: Time Limit Exceeded

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

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if (guess <= item and list[mid+1] >= item):
            return mid
        elif guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None
    
for i in range(n-1):
    for j in range(i+1,n-1):
        if l[i] + l[j] > l[-1]:
            ans = ans + (n-j)*(n-j-1)//2
            break
        else:
            k = binary_search(l,l[i]+l[j]-1)
            if k > j:
                ans = ans +k-j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from copy import copy
import bisect
 
n = int(input())
order = sorted(list(map(int, input().split())))
l = deque(order)
ans = 0
 
for _ in range(len(l)-2):
    first = l.pop()
    m = copy(l)
    for _ in range(len(m)-1):
        second = m.pop()
        fix = first-second
        ans += len(m)-bisect.bisect_right(list(m), fix)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from copy import copy
import bisect

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

for _ in range(len(l)-2):
    first = l.pop()
    m = copy(l)
    for _ in range(len(m)-1):
        second = m.pop()
        fix = first-second
        ans += len(m)-bisect.bisect_right(list(m), fix)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=input()
L=L.split(" ")
L_i=[]
for i in L:
 L_i.append(int(i))
L_i=sorted(L_i)
count=0
for i in range(0,N):
 for j in range(i+1,N):
  for k in range(j+1,N):
   if(L_i[i]<L_i[j]+L_i[k] and L_i[j]<L_i[k]+L_i[i] and L_i[k]<L_i[i]+L_i[j] ):
    count+=1
   else:
    break

print(count)

Submission status: Time Limit Exceeded

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

count=0
for i in range(0,N):
 for j in range(i+1,N):
  for k in range(j+1,N):
   if(L_i[i]<L_i[j]+L_i[k] and L_i[j]<L_i[k]+L_i[i] and L_i[k]<L_i[i]+L_i[j] ):
    count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
A= [int(c) for c in input().strip().split(' ')]
# s = input().strip()
A = sorted(A)
i,j,k=0,1,2
cnt =0
# print(A)
for i in range(n):
    for j in range(i+1,n):
         for k in range(j+1,n):
             if A[k] < A[j]+A[i]:
                 cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
length = list(map(int,input().split()))
length_con = list(itertools.combinations(length, 3))
count = 0

for i in length_con:
    if abs(i[0]-i[1]) < i[2] and i[2] < i[0] + i[1]:
        count += 1
        
print(count)

Submission status: Time Limit Exceeded

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

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
fj = fk = True
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if not fj:
            fj=True
            break
        else:
            k=j+1
            while k<N:
                if sticks[i]<sticks[j]+sticks[k]:
                    count += 1
                    k += 1
                    continue
                else:
                    if j+1 == k :
                        fj = False
                    break
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
def bisec_k(l,x,k_max,k_min):
  if k_max == k_min + 1:
    if a[k_max] < x:
      return k_max
    else:
      return k_min
  else:
    k_mid= k_min + (k_max-k_min)//2
    if l[k_mid] >= x:
      k_max  = k_mid
      return bisec_k(l,x,k_max,k_min)
    else:
      k_min = k_mid
      return bisec_k(l,x,k_max,k_min)

n=int(input())
a=sorted(list(map(int,input().split())))

sum=0
for i in range(n-2):
  for j in range(i+1,n-1):
    tmp = a[i] + a[j]
    k = bisec_k(a,tmp,n-1,j)
    sum += (k - j)

print(sum)

Submission status: Time Limit Exceeded

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

#N=len(sticks)
sticks.sort(reverse = True)
count = 0
fj = True
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if not fj:
            fj=True
            break
        else:
            for k in range(j+1,N):
                #stick[i]>j>k
                if sticks[i]<sticks[j]+sticks[k]:
                    count += 1
                else:
                    if j+1 == k :
                        fj = False
                    break
        
print(count)

Submission status: Time Limit Exceeded

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


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

    cnt = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            a = L[i]
            b = L[j]
            r = bisect.bisect_left(L, b+a, lo=j+1)
            l = bisect.bisect_right(L, b-a, lo=j+1)
            cnt += r - l
    
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

x=0

for i in range(0,N-2):
  for j in range(max(x,i+1),N-1):
    for k in range(max(x,j+1),N):
#      print(i,j,k)
#      print(l[i],l[j],l[k])
      if l[k]>=l[i]+l[j]:
        x=k
        break
      if l[i]<l[j]+l[k] and l[j]<l[k]+l[i]:
        n=n+1
print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
Lb = L[::-1]
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        c = l1 - l2
        p = max(0, len(L) - (i + j + 2) - bisect.bisect_right(Lb, c))
        ans += p
print(ans)

Submission status: Time Limit Exceeded

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

c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += bisect_left(l[j+1:], l[i]+l[j])
 
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        p = a + b
        if p > l[-1]:
            ans += sum([m for m in range(1, n - j)])
            break
        for k in range(j+1, n):
            if p > l[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)
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        for k, l3 in enumerate(L[i + j + 2:]):
            if (l1 < l2 + l3) and (l2 < l3 + l1) and (l3 < l1 + l2):
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

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

c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += max(0, bisect_left(l[j+1:], l[i]+l[j]))

print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(2, N)):
    t_max = l_list[i]
    point = None
    for j in range(0, i-1):
        if l_list[j]+l_list[i-1] > t_max:
            point = j
            break
    if point is None:
        continue
    count += (i-1-point)

    for j in reversed(range(point, i-1)):
        point_sec = point
        t_sec = l_list[j]
        flag = False
        for k in range(point_sec, j):
            if l_list[k]+l_list[j] > t_max:
                point_sec = k
                flag = True
                break
        if not flag:
            continue
        count += (j-point_sec)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(2, N)):
    t_max = l_list[i]
    point = None
    for j in range(0, i-1):
        if l_list[j]+l_list[i-1] > t_max:
            point = j
            break
    if point is None:
        continue
    count += (i-1-point)

    for j in reversed(range(point, i-1)):
        point_sec = None
        t_sec = l_list[j]
        for k in range(point, j):
            if l_list[k]+l_list[j] > t_max:
                point_sec = k
                break
        if point_sec is None:
            continue
        count += (j-point_sec)

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    L = inputList()
    
    L.sort()
    L = L[::-1]
    #print(L)
    
    ans = 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]
                
                tmp = b+c
                if a >= tmp:
                    break
                
                if a < b+c and b < c+a and c < a+b:
                    ans += 1
    
    print(ans)
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    L = inputList()
    
    L.sort()
    #L = L[::-1]
    #print(L)
    
    ans = 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]
                
                tmp = a+b
                if tmp <= c:
                    break
                
                if a < b+c and b < c+a and c < a+b:
                    ans += 1
    
    print(ans)
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
L = LI()

L.sort()

ans = 0
for i, l in enumerate(L):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if l + L[j] <= L[k]:
                break
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    L = inputList()
    
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                a = L[i]
                b = L[j]
                c = L[k]
                
                if a < b+c and b < c+a and c < a+b:
                    ans += 1
    
    print(ans)
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int, input().split()))
tri = 0
ran = list(range(N-2))

for i in ran:
    for j in ran:
        for k in range(N-2-i-j):
            if ((L[i] + L[i+j+1]) > L[i+j+k+2]) and ((L[i] + L[i+j+k+2]) > L[i+j+1]) and ((L[i+j+k+2] + L[i+j+1]) > L[i]):
                tri += 1
print(tri)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
Ls = input().split()
L = [int(s) for s in Ls]
tri = 0

for i in range(N-2):
    for j in range(N-2):
        for k in range(N-2-i-j):
            if ((L[i] + L[i+j+1]) > L[i+j+k+2]) and ((L[i] + L[i+j+k+2]) > L[i+j+1]) and ((L[i+j+k+2] + L[i+j+1]) > L[i]):
                tri += 1
print(tri)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right
 
def main():
    N = int(input())
    L = [int(c) for c in input().split()]
    L = sorted(L)
    num = 0
    for ai in range(N):
        for bi in range(ai+1, N):
            if bi - ai == 1:
                continue
            a = L[ai]
            b = L[bi]
            ci_left = bisect_right(L[ai+1:bi], abs(L[ai] - L[bi]))
            ci_right = bisect_left(L[ai+1:bi], L[ai] + L[bi])
            # print(a, b, ci_left, min(ci_right, bi) - max(ci_left, ai) - 1)
            # num += min(ci_right, bi) - max(ci_left, ai) - 1
            num += ci_right - ci_left
            # print(a, b, ci_right, ci_left, num)
 
    print(num)
 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


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]:
                count+=1
            else:
                break

print(count)

Submission status: Time Limit Exceeded

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

import bisect

Ls = sorted(Ls)

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

Submission status: Time Limit Exceeded

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

import bisect

Ls = sorted(Ls)

ans = 0
for i in range(N - 2):
    a = Ls[i]
    for j in range(i + 1, N - 1):
        b = Ls[j]
        c = bisect.bisect_left(Ls[j + 1:], a + b)
        ans += len(Ls[j + 1:j + 1 + c])
print(ans)

Submission status: Time Limit Exceeded

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

Ls = sorted(Ls, reverse=True)

ans = 0
for i in range(N - 2):
    a = Ls[i]
    for j in range(i + 1, N - 1):
        b = Ls[j]
        if a > 2 * b:
            continue
        for k in range(j + 1, N):
            c = Ls[k]
            if a < b + c:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Ls = sorted(Ls, reverse=True)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ary = sorted(map(int,input().split()))
dp = [[] for _ in range(N-1)]
c = 0
for i in range(1,N):
    for j in range(i,N):
        if i == j:continue
        dp[i] += [ary[j] - ary[i]]
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(len(dp[j])):
            if ary[i] > dp[j][k]:
                c += 1
print(c)

Submission status: Time Limit Exceeded

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

#N=len(sticks)
sticks.sort(reverse = True)
count = 0
fj = fk = True
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if not fj:
            fj=True
            break
        else:
            for k in range(j+1,N):
                #stick[i]>j>k
                if sticks[i]<sticks[j]+sticks[k]:
                    count += 1
                else:
                    if j+1 == k :
                        fj = False
                    break
        
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ary = sorted(map(int,input().split()))
dp = [[] for _ in range(N-1)]
c = 0
for i in range(1,N):
    for j in range(i,N):
        if i == j:continue
        dp[i] += [abs(ary[i] - ary[j])]
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(len(dp[j])):
            if ary[i] > dp[j][k]:
                c += 1
print(c)

Submission status: Time Limit Exceeded

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

x=int(0)
y=int(1)
z=int(2)
ans = 0
while True:
    y = x + 1
    z = y + 1
    while True:
        ans += z-y-2
        z -= 1
        while True:
            if l[x]+l[y] > l[z]:
                ans += 1
                z += 1
                if z > n-1:
                    break
            else:
                break
        y += 1
        if y > n - 2:
            break
    x += 1
    if x > n - 3:
        break

print(ans)

Submission status: Time Limit Exceeded

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

x=int(0)
y=int(1)
z=int(2)
ans = 0
while True:
    y = x + 1

    while True:
        z = y + 1
        while True:
            if l[x]+l[y] > l[z]:
                ans += 1
                z += 1
                if z > n-1:
                    break
            else:
                break
        y += 1
        if y > n - 2:
            break
    x += 1
    if x > n - 3:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
## ABC143
#D
import itertools
N = int(input())
Llist = [int(s) for s in input().split()]

cmb = list(itertools.combinations(Llist, 3))
res = 0

for a, b, c in cmb:
    if (a < b+c) and (b < c+a) and (c < a+b):
        res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
count = 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):
            if L[k] < a + b:
                if a + L[k] > b:
                    if b + L[k] > a:
                        count += 1

print(count)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
c=0
L.sort()
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]:
                c+=N-k
                break
N=int((N-2)*(N-1)*N/6-c)
print(N)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
min = 0
max = 0
hen2 = 0

for i in range(0, N-2):
	for j in range(i+1, N-1):
		min = j+1
		max = N-1
		hen2 = L[i] + L [j]
		
		if L[max] < hen2:
			count += max - min +1
		elif hen2 > L[min]:
			while min <= max:
				mid = (min+max) // 2
				if mid < N-1:
					if ( L[mid] < hen2 ) and ( L[mid+1] >= hen2 ):
						count += (mid - min +1)
						break
					elif ( L[mid+1] < hen2 ) :
						if mid +1 == max:
							count += (max - j)
							break
						else:
							min = mid
					elif ( hen2 <= L[mid] ):
						if min == mid:
							break
						else:
							max = mid
				else:
					if L[mid] < hen2 :
						count += (mid - min +1)
						break
					elif hen2 <= L[mid] :
						break

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 - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        for k in range(j + 1, N):
            if (a + b > L[k] and
                    a + L[k] > b and
                    b + L[k] > a):
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
c=0
L.sort()
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]:
                c+=1
c=int(c)
print(int(N*(N-1)*(N-2)/6-c))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
					m -= 1
			else:
				break

print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

d.sort()

m = 0



for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]==d[a]:
				m -= 1
			if d[c]<d[b]+d[a]:
				m += 1
			else:
				break
			

print(m)

Submission status: Time Limit Exceeded

Solution code:
input()
data=[int(i) for i in input().split()]
data.sort()
tri=0
for aid in range(len(data)-2):
  for bid in range(aid+1, len(data)-1):
    idx=1
    while bid+idx<len(data) and data[aid]+data[bid]>data[bid+idx]:
      idx+=1
    tri=tri+(idx-1)
print(tri)

Submission status: Time Limit Exceeded

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

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

ans = 0 

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

# main
L = sorted(L,reverse = True)
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if(True == isTriangle(L[i],L[j],L[k])):
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
input()
data=[int(i) for i in input().split()]
data.sort()
tri=0
for aid in range(len(data)-2):
  for bid in range(aid+1, len(data)-1):
    for cid in range(bid+1, len(data)):
      if data[aid]+data[bid]>data[cid]:
        tri=tri+1
      else:
        break

print(tri)

Submission status: Time Limit Exceeded

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

N=len(sticks)
sticks.sort()
count = 0
for i in range(0,N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if sticks[i]+sticks[j]>sticks[k]:
                count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[a]<d[b]+d[c] and d[b]<d[c]+d[a] and d[c]<d[a]+d[b]:
				m += 1
				#print(str(a)+" "+str(b)+" "+str(c))

print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
min = 0
max = 0
hen2 = 0

for i in range(0, N-2):
	for j in range(i+1, N-1):
		min = j+1
		max = N-1
		hen2 = L[i] + L [j]
		
		while min <= max:
			mid = (min+max) // 2
			if mid < N-1:
				if ( L[mid] < hen2 ) and ( L[mid+1] >= hen2 ):
					count += (mid - min +1)
					break
				elif ( L[mid+1] < hen2 ) :
					if mid +1 == max:
						count += (max - j)
						break
					else:
						min = mid
				elif ( hen2 <= L[mid] ):
					if min == mid:
						break
					else:
						max = mid
			else:
				if L[mid] < hen2 :
					count += (mid - min +1)
					break
				elif hen2 <= L[mid] :
					break

print(count)