Problem:


Score : 400 points

Problem Statement

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

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

a < b + c

b < c + a

c < a + b

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

Constraints

All values in input are integers.

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

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

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

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
import bisect
n=int(input())
lists=list(map(int,input().split()))
listss=sorted(lists)

count=0

for i in range(n):
    for j in range(n):
        if i!=j:
            a=listss[i]+listss[j]
            # abs(lists[i]-lists[j]<a<b+cとなるものの個数を求める)
        
            index1= bisect.bisect_left(listss, abs(listss[j]-listss[i])+1)
            index2=bisect.bisect_right(listss,listss[i]+listss[j]-1)

            count+=(index2-index1)
            x=abs(listss[j]-listss[i])
            if  x+1<=listss[i]:
                count-=1
            if x+1<=listss[j]:
                count-=1


print(count//6)

Submission status: Time Limit Exceeded

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

for i in range(n-3+1):
  for j in range(i+1, n-3+2):
    for k in range(j+1, n-3+3):
      if l[i]+l[j]>l[k]:
        counter += 1
      else:
        break

print(counter)

Submission status: Time Limit Exceeded

Solution code:

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

x = 0


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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
array = list(map(int, input().split()))
count = 0
array.sort(reverse = True)
for a in range(n):
    A = array[a]
    for b in range(a+1,n):
        B = array[b]
        ab = A - B
        end = n-1
        for c in range(end,b,-1):
            #print(c)
            if ab < array[c]:
                #print(A,B,array[c])
                count += c - b
                end = c
                #print(c-b)
                break
print(count)

Submission status: Time Limit Exceeded

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

sums = 0
for i in range(N-2):
  a = L[i]
  for j in range(i+1,N-1):
    b = L[j]
    sums += np.count_nonzero((L[j+1:] > abs(a - b)) & (L[j+1:] < (a + b)))
print(sums)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
length = list(map(lambda x:int(x), input().split()))
length.sort()
ans = 0
for i in range(n):
    a = length[i]
    for j in range(n):
        b = length[j]
        if i >= j:
            continue
        else:
            c_candidates = length[j+1:]
            min_bar = bisect.bisect_right(c_candidates,max(a-b, b-a))
            max_bar = bisect.bisect_left(c_candidates,a+b)
            ans += max_bar - min_bar
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n =  int(input())
L = list(map(int, input().split()))
L_conv = list(itertools.combinations(L, 3))
cnt = 0
for i in L_conv:
    tmp = sorted(i, reverse = True)
    if sum(tmp) > tmp[0] * 2:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

    L = sorted(L, reverse=True)

    ans = 0
    for i in range(N):
        tmp = 0
        count = 0

        for j in range((i+1), N):
            if L[i]/2 >= L[j]:
                break
            elif L[i] == L[j]:
                tmp += len(L[j+1::])
                count += 1
                continue
            elif L[i] != L[j]:
                ans += tmp*count

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

                ans += len([t for t in L[j+1::] if L[i] < (L[j]+t)])





    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

MAXVAL = 10 ** 3

lengthList = [0] * MAXVAL

for i in range(n) :
    lengthList[l[i] - 1] += 1
for i in range(1, MAXVAL) :
    lengthList[i] += lengthList[i-1]
l = sorted(l)
ans = 0
beforeI = -1
beforeLj = -1
count = 0
#print(lengthList)
for i in range(n) :
    for j in range(i+1, n) :
        if l[j] == 1 :
            val = lengthList[min(MAXVAL-1, l[i]+l[j]-2)]
        else :
            val = lengthList[min(MAXVAL-1, l[i]+l[j]-2)] - lengthList[l[j]-2]
        #print('before', val)
        if l[i] == l[j] :
            val -= 2
        else :
            val -= 1
        if beforeI == i and  beforeLj == l[j] :
            count += 1
        else :
            count = 0
        if val != 0 :
            val -= count
        #print(i,j,l[i],l[j], val)
        ans += val
        beforeI = i
        beforeLj = l[j]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split(" ")))
count = 0
l = sorted(l)
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]:
        continue
      count += 1
print(count)

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):
        min_range = abs(L[i] - L[j])
        max_range = L[i] + L[j]
        if max_range - min_range <= 1:
            continue
        for k in range(j+1,N):
            if min_range < L[k] and L[k] < max_range:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
L.sort(reverse = True)
M = 0
for i in range(N-2):
  if L[i]< L[i+1]+L[i+2]:
    for j in range(i+1,N-1):
        for k in range(j+1,N):
          if L[i] < L[j]+L[k]:
            M += 1
print(M)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0

d = []

for i in range(n):
	for j in range(i+1,n):
		index = bisect.bisect_left(l,l[i]+l[j])
		for k in range(index):
			if k == i or k == j:
				continue
			if l[j] < l[k] + l[i]:
				tmp = []
				tmp.append(i)
				tmp.append(j)
				tmp.append(k)
				tmp.sort()
				if tmp not in d:
					d.append(tmp)
					ans += 1

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
keys=[i+1 for i in range(N)]
dic=dict(zip(keys,L))
OK=[(x,y,z) for x in dic.values() for y in dic.values() for z in dic.values() if(x<y+z and y<x+z and z<x+y and [k for k, v in dic.items() if v ==x][0]!=[k for k, v in dic.items() if v ==y][0] and [k for k, v in dic.items() if v ==y][0]!=[k for k, v in dic.items() if v ==z][0] and [k for k, v in dic.items() if v ==x][0]!=[k for k, v in dic.items() if v ==z][0])]
print(len(OK)//6)

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-1):
    for j in range(i+1,N):
        temp=L[i]+L[j]
        for k in range(N):
            f=True
            if k!=i and k!=j:
                if temp<=L[k]:
                    f=False
                elif L[j]+L[k]<=L[i]:
                    f=False
                elif L[k]+L[i]<=L[j]:
                    f=False
                if f:
                    ans+=1


print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
#print(N)
L = [int(i) for i in input().split()]
#print(L)
C = itertools.combinations(L, 3)

cnt = 0
for j in C:
    a, b, c = j
    if a < b+c and b < c+a and c < a+b:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    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 (i, j, k) not in d:
                        cnt += 1
                        d[i, j, k]
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Time Limit Exceeded

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

ans=0

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]<L[j]+L[k] and  L[j]<L[k]+L[i] and L[k]<L[i]+L[j]:
                ans+=1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

L.sort()

tmp = 0
for i in range(N):
    for j in range(N-i-1):
        j = j + i + 1

        for k in range(N-j-1):
            k = k + j + 1

            if L[k] < L[i] + L[j]:
                tmp = tmp + 1
            else:
                break

print(tmp)

Submission status: Time Limit Exceeded

Solution code:
##################################################################
def main():
    Input = [input() for i in range(2)]
    N = int(Input[0])
    L = list(map(int,Input[1].split()))
    L.sort()
    ans = 0
    for i1 in range(N-1,1,-1):
        a = L[i1]
        for i2 in range(i1-1,0,-1):
            b = L[i2]
            for i3 in range(i2-1,-1,-1):
                if L[i3]>a-b:
                    ans += 1
                else:
                    break
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys


def main():
    readline = sys.stdin.readline
    readlines = sys.stdin.readlines
    sys.setrecursionlimit(10 ** 7)

    n = int(input())
    L = tuple(map(int, readline().split()))
    cnt = 0

    ls = tuple(itertools.combinations(L, 3))

    for l in ls:
        if sum(l) > max(l)*2:
            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() #小さい順
counter = 0

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

Submission status: Time Limit Exceeded

Solution code:
n, *x = map(int, open(0).read().split())
y = sorted(x)[::-1]
cnt = 0
for i in range(n - 2):
    a = y[i]
    for j in range(i + 1, n - 1):
        b = y[j]
        for k in range(j + 1, n):
            c = y[k]
            if a < b + c:
                cnt += 1
            else:
                break
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
l=sorted([int(i) for i in input().split()])
q=deque()
ans=0
for i in range(n):
    for j in range(i+1,n):
        q.append((l[i]+l[j],i,j))
q=list(q)
for i in range(n):
    for plus,x,y in q:
        if i>x and i>y and l[i]<plus and l[y]<l[x]+l[i] and l[x]<l[y]+l[i]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

L.sort(reverse = True)
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]:
                break
            if L[i] < L[j] +L[k] and L[j] < L[k] + L[i]:
                count += 1
            else: 
                break
                
print(count)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools
import numpy as np

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


c = np.array([v for v in itertools.combinations(L, 3)])
print(len([a for a, b, c in c if a < b + c and b < c + a and c < a + b]))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
L = list(map(int,input().split()))
L.sort()
ans =0
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    L_ = L[:j]
    ans += j-bisect.bisect_right(L_,L[i]-L[j])
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 1行目の入力を数値として扱う
n = int(input())
# 2行目の入力を数値のリストとして扱う
a = list(map(int, input().split()))

#
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

num = input()
stickLengths = input().split()
counter = 0

combinations = itertools.combinations(stickLengths, 3)

for v in combinations:
    if int(v[0]) < int(v[1]) + int(v[2]):
        if int(v[1]) < int(v[0]) + int(v[2]):
            if int(v[2]) < int(v[1]) + int(v[0]):
                counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

L = sorted(L)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    
    if L[i]+L[j] <= L[min(j+1,N-1)]:
        continue
    
    for k in range(j+1,N):
      if L[i]+L[j] <= L[k]:
        break
      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())
bou =list(map(int, input().split()))

triangles =[]
ans =0


for v in itertools.combinations(bou, 3):
    if (v[0]<v[1]+v[2])and(v[1]<v[0]+v[2])and(v[2]<v[1]+v[0]):
        triangles.append(tuple(sorted(v)))

ans = len(set(triangles))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
arr = list(map(int,input().split()))
arr = sorted(arr)
cnt = 0
for i in range(N-1):
  for j in range(N-i-1):
    a = arr[i]
    b = arr[i+j+1]
    if (i+j+2) < N:
      k = i+j+2
      upper = bisect.bisect_left(arr[k:], (a+b))
      cnt += upper

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def is_triangle(l):
    a, b, c = l
    if a >= b + c or b >= c + a or c >= a + b :
        return 0
    else:
        return 1

ans = 0

for m in list(itertools.combinations(l,3)):
    ans += is_triangle(m)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(input().split())
for i in range(N):
  L[i]=int(L[i])
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]):
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

p = list(itertools.combinations(l,3))
        
ans = [1 for i in p if i[0] < i[1] + i[2] and  i[1] < i[0] + i[2] and i[2] < i[0] + i[1]]

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import bisect

def solve():
  N = int(input())
  L = sorted([int(i) for i in input().split()])
  ans = 0

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

  return ans

print(solve())

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 = sorted(tk[i], reverse=True)
    if (test[1] - test[2] < test[0])and(test[0] < test[1] + test[2]):
        count += 1
        
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def sol():
    n=int(input())
    l=[int(i) for i in input().split()]
    l.sort()
    ans=chk=0
    #for i in range(1,n-1):
    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] and l[i]<l[j]+l[k] and l[j]<l[i]+l[k]:
                    ans+=1
        #for j in range(i):
        #for j in range(i):
            #print(i,j)
            #for k in range(i+1,n):
            #for k in range(i+1,n):
                #print(l[i],l[j],l[k])
            #    if i!=j and i!=k and j!=k and j<i<k:
    print(ans)

if __name__=="__main__":
    sol()

Submission status: Time Limit Exceeded

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

c = 0
for i in range(0,n-2):
    for j in range(i+1, n-1):
        ab = l[i]+l[j]
        for k in range(j+1, n):
            if(ab>l[k]):
                c+=1
            else:
                continue
print(c)

Submission status: Time Limit Exceeded

Solution code:
# D TLE
import itertools
import bisect

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

L.sort()
value = 0

for i, j in itertools.combinations(range(len(L)-1), 2):
    Z = L[j+1:]
    
    index = bisect.bisect_left(Z, L[i]+L[j])
    value+=index
    

print(value)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
count = 0
L.sort()
#print(L)
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        limit = N
        b = L[j]
        c = L[j+1]

        #もしどうやっても無理な値を見つけたとき
        for k in range(j+1,N):
            if L[k]>a+b:
                limit = k
                break

        if a<b+c and b<a+c and c<a+b:
            count += (limit-1) - j
            #print(a,b,c,i,j,j+1,"limit=",limit,"count=",count)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = sorted(LIST())

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ll = L[i] + L[j]
        k = j + 1
        while k < N:
            if L[k] >= ll:
                break
            k += 1
        count += (k - j - 1)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int, input().split()))
cnt = n * (n - 1) * (n - 2) / 6
jud = []

for i in range(n):
    for j in range(n):
        if i > j:
            jud.append(L[i] + L[j])

for p in range(len(jud)):
    for m in range(n):
        if L[m] >= jud[p]:
            cnt -= 1

if cnt < 0:
    print(0)
else:
    print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:

import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        ans += bisect.bisect_left(l[j+1:], l[i] + l[j])
print(ans)

Submission status: Time Limit Exceeded

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

import itertools
comb_list = list(itertools.combinations(sorted(l_list),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:
N = int(input())
L = list(map(int, input().split()))

L.sort()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
List=list(map(int,input().split()))
List.sort(reverse=True)
flag = True
while flag:
    if len(List) <= 2:
        print(0)
        exit()
    if List[0] > List[1]+List[2]:
        List = List[1:]
    else:
        flag = False
sum_value = 0
while len(List) >= 3:
    Max_value = List[0]
    List = List[1:]
    while len(List) >= 2 and List[0] > Max_value/2:
        for i,v in enumerate(List):
            for v2 in List[i+1:]:
                if Max_value < v + v2:
                    sum_value += 1
                else:
                    break
        List = List[1:]
print(sum_value)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for n1 in range(N):
    for n2 in range(n1+1, N):
        for n3 in range(n2+1, N):
            if L[n1] + L[n2] > L[n3]:
                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(0,n):
    for j in range(i+1,n):
        if i == j:
            continue
        for k in range(j+1,n):
            if i == k and j == k:
                continue
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b + c and b < a + c 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()
cnt =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]:
                        cnt+=1
                    else:
                        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tmp = input()
L = [int(x.strip()) for x in tmp.split(' ')]
L.sort()
count = 0
for i in range (0, N-2):
    p1 = L[i]
    for j in range(i+1, N-1):
        p2 = L[j]
        wa = p1 + p2
        if wa <= L[j+1]:
            continue
        else:
            k = 1
            while j+k <= N-1 and wa > L[j+k]:
                count = count + 1
                k = k + 1
                
print(count)

Submission status: Time Limit Exceeded

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

l = len(L)

def judge(a, b, c):
    if a >= b + c:
        return False
    if b >= c + a:
        return False
    if c >= a + b:
        return False
    return True

count = 0
for i in range(l):
    a = L[i]
    for j in range(i+1,l):
        b = L[j]
        ab = a + b
        for k in range(j+1,l):
            if L[k] >= ab:
                break
            count += 1
                
print(count)

Submission status: Time Limit Exceeded

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

    L = sorted(L, reverse=True)

    ans = 0
    for i in range(N):
        #tmp = 0

        for j in range((i+1), N):
            if L[i]/2 >= L[j]:
                break
            elif L[i] == L[j]:
                ans += len(L[j+1::])
                continue

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

            ans += len([t for t in L[j+1::] if L[i] < (L[j]+t)])





    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

l_l.sort()
count=0
for i in range(n):
  for j in range(i+1,n):
    for k in range (j+1,n):
      if(l_l[i]+l_l[j]<=l_l[k]):
        break
      else:
        count +=1
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(N-2):
    J = i+1
    for x in range(N-i-1):
        j = J+x
        K = j+1
        for y in range(N-j-1):
            k = K+y
            if L_list[i] + L_list[j] > L_list[k]:
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

count = 0
for bars in list(combinations(L, 3)):
    if bars[2] < bars[0] + bars[1]:
        if bars[1] - bars[0] < bars[2]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
L = list(map(int, input().split()))
triangle = 0
comb = list(itertools.combinations(L, 3))
for i in range(len(comb)):
    a = comb[i][0]
    b = comb[i][1]
    c = comb[i][2]
    if (a < b + c) and (b < c + a) and (c < a + b):
        triangle += 1
print(triangle)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#ls = [218, 786, 704, 233, 645, 728, 389]

ls = sorted(ls, reverse=True)
#print(ls)
result = 0

#count = 0
for i in range(len(ls)):
    a = ls[i]
    for j in range(i+1, len(ls)):
        b = ls[j]
        if a > b*2:
            break
        for k in range(j+1, len(ls)):
            c = ls[k]
            #print(a,b, c)
            #count += 1
            if a < (b+c):
                result += 1
            else:
                break

#print('count: ', count)
print(result)

Submission status: Time Limit Exceeded

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

L.sort()
cnt = 0
for i in range(N-1):
    for j in range(i):
        a, b = L[i], L[j] 
        k = i + 1
        l = bisect_left(L[i+1:], a-b) + i+1
        r = bisect_left(L, a+b)
        cnt += max(r - l, 0)
            
print(cnt)

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]:
      for h in range(j+1,n):
        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()))

count = 0
head = 0
conb = list(itertools.combinations(L,2))
# print(conb)

for i in range(N):
    c = L[i]
    head = head + len(L)-i-1
    for a,b in conb[head:]:
        if a < b+c and b < c+a and c < a+b:
            # print(a,b,c)
            count+=1
print(count)