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:
n=int(input())
li=input().split()
l = [int(s) for s in li]
a=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]:
        if l[j]<l[i]+l[k]:
          if l[k]<l[j]+l[i]:
            a+=1
print(a)

Submission status: Time Limit Exceeded

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

#l = list(set(l))
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] 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:
import numpy as np

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

l = np.sort(l)[::-1]

cnt = 0
for a in range(n):
    for b in range(a, n):
        for c in range(b, n):
            if a != b and b != c and c != a:
                if l[a] > (l[b] + l[c]):
                    break
                if l[a] < (l[b] + l[c]) and l[b] < (l[a] + l[c]) and l[c] < (l[a] + l[b]):
                    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
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())
S = list(map(int,input().split()))
counter = 0
for i in range(N):
  for j in range(N-1-i):
    for k in range(N -2 -i -j):
      a = S[i]
      b = S[i+j+1]
      c = S[i+j+k+2]
      if (a + b > c) and (c > abs(a - b)):
        counter += 1
    
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0
for a, b, c in itertools.combinations(L, r=3):
    if a + b > c and b + c > a and c + a > b:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)

L_new = []

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            L_new.append([L[i],L[j],L[k]])
            
count = 0

for i in range(len(L_new)):
    a = L_new[i][0]
    b = L_new[i][1]
    c = L_new[i][2]
    
    if a+b > c and b+c > a and c+a > b:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=list(map(int, input().split()))
S=0
C=list(itertools.combinations(L,3))
for i in range(len(C)):
    if C[i][0]+C[i][1]>C[i][2] and C[i][1]+C[i][2]>C[i][0] and C[i][2]+C[i][0]>C[i][1]:
        S+=1
print(S)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
inputData = input().split()
L = [int(x) for x in inputData]
L.sort()
ans = 0
for a in range(0, N):
    for b in range(a+1, N):
        for c in range(b+1, N):
            if L[c] < L[a] + L[b]:
                    ans += 1
            else:
                continue
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

L.sort()
#print(L)


cnt = 0
for i in range(N-2):
    highJ = 0
    for j in range(i+1,N-1):
        tmphighJ = max(j,highJ)
        for k in range(max(j+1,highJ+1),N):
            if L[k] < L[i]+L[j]:
                tmphighJ = k
            else:
                break
        highJ = max(j,tmphighJ)
        cnt+= tmphighJ - j
        #print(i,j,highJ,cnt)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l):
            if n!=m:
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//6)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L_list = list(map(int, input().split()))
count = 0
tri_list = list(itertools.combinations(L_list, 3))

for tri in tri_list:
    if tri[0] < tri[1] + tri[2] and tri[1] < tri[0] + tri[2] and tri[2] < tri[1] + tri[0]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(l) for l in input().split()]
ans = 0
for i in range(N):
    for j in range(i, N):
        if i == j:
            continue
        temp = list(filter(lambda x: x > abs(L[i]-L[j]) and x < L[i]+L[j],L[j+1:]))
        ans += len(temp)
print(ans)

Submission status: Time Limit Exceeded

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

from itertools import combinations


p = combinations(ls, 3)

result = 0
for a, b, c in p:
    if a < (b+c) and b < (c+a) and c < (a+b):
        result += 1

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = [int(x) for x in input().split()]

count = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, n):
            if L[a] < L[b]+L[c] and L[b] < L[c]+L[a] and L[c] < L[a]+L[b]:
                count += 1
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):
    A = L[i]
    for j in range(i+1,N-1):
        B = L[j]
        for k in range(j+1,N):
            C = L[k]
            if A < B + C and B < C + A and C < A + B:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

for l in ls:
    if l[0] < l[1]+l[2] and l[1] < l[2] + l[0] and l[2] < l[0] + l[1]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def A():
    temp = [int(i) for i in input().split()]
    print(max(0, temp[0]-2*temp[1]))

def B():
    N = int(input())
    T = [int(i) for i in input().split()]
    s = 0
    for i in range(N):
        for j in range(i):
            s += T[i]*T[j]
    print(s)

def C():
    N = int(input())
    S = input()
    if N == 1:
        print(1)
    else:
        ans = 1
        cur_c = S[0]
        for c in S:
            if c != cur_c:
                ans += 1
                cur_c = c
        
        print(ans)

def D():
    N = int(input())
    L = sorted([int(i) for i in input().split()],reverse = True)
    # dp_sum = [[0 for i in range(N)] for j in range(N)]
    # for i in range(N):
    #     for j in range(i):
    #         dp_sum[i][j] = L[i]+L[j]
    count = 0
    for i in range(N):
        for j in range(i):
            for k in range(j):
                if L[k] < L[i]+L[j] and L[j] < L[i]+L[k] and L[i] < L[j]+L[k]:
                    count += 1
    print(count)

D()

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):
      """
      print("i:",i)
      print("j:",j)
      print("k:",k)
      """
      if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j]:
        #print("ok")
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

from sys import stdin

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

x = 0#位置
ans = 0
while x < n-2:
    a = ls[x]
    for y in range(x+1,n-1):
        b = ls[y]
        for z in range(y+1,n):
            c = ls[z]
            if a<b+c:
                if b<c+a:
                    if c<a+b:
                        ans += 1
    x += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
L = sorted([int(x) for x in input().split()])
def comb(n, r=3):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
t = comb(N)
c = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(N-1,j,-1):
      if L[i] + L[j] <= L[k]:
        
        c += 1
        #print(L[i],L[j],L[k],c)

      else:
        #print(L[i],L[j],L[k],c)

        break
print(t-c)

Submission status: Time Limit Exceeded

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

L = sorted(L)
counter = 0
for a, c in itertools.combinations(L, 2):
    left = abs(a-c)
    right = a+c
    LL = [l for l in L if l not in [a, c]]
    lefti = bisect.bisect_right(LL, left)
    righti = bisect.bisect_left(LL, right)
    counter += max(0, righti - lefti)

print(counter//3)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = tuple(map(int,input().split()))
count = 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)):
			a = L[i]
			b = L[j]
			c = L[k]
			if a < b+c and b < c+a and c < a+b :
				count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import bisect

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[j]+l[i]):
                ans+=1
print(ans)
#くそでは？

Submission status: Time Limit Exceeded

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

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


            ans += 1
#        k += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
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
      while arr[k]<(a+b):
        cnt +=1
        k += 1
        if k == N:
          break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
##################################################################

if __name__ == "__main__":
    Input = [input() for i in range(2)]
    N = int(Input[0])
    L = list(map(int,Input[1].split()))
    L.sort()
    L = np.array(L)
    ans = 0
    for i1 in range(N-1,1,-1):
        a = L[i1]
        for i2 in range(i1-1,0,-1):
            b = L[i2]            
            ans += sum(L[0:i2]>a-b)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
import itertools 
combi = itertools.combinations(L, 3)
wa = 0
for c in combi:
    l = list(c)
    m = max(l)
    l.remove(m)
    if(m < sum(l)):
        wa += 1   
print(wa)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
n = int(input())
l_ls = [int(i) for i in sys.stdin.readline().split()]
l_ls.sort()
l_dict = { i : j for i, j in enumerate(l_ls)}
_sum_ls = []
cnt = 0
for i in range(1,n-1):
    base = l_dict[i]
    next_base = l_dict[i+1]
    edagiri = -1
    for l in l_ls[:i][::-1]:
        if l + base > next_base:
            bisect.insort_left(_sum_ls, l + base)
    for k, _sum in enumerate(_sum_ls[::-1]):
        if next_base < _sum:
            cnt += 1
        else:
            edagiri = k
            break
    if edagiri > 0:
        _sum_ls = _sum_ls[-edagiri:]
print(cnt)

Submission status: Time Limit Exceeded

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

llist.sort()
res = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        num = llist[i] + llist[j] 
        idx = bisect_left(llist, num, lo=j+1, hi=n)
        res += idx - j - 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0
L.sort()

for i in range(n):
    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:
import itertools
 
N=int(input())
Ls=list(map(int,input().split()))
Tri=list(itertools.combinations(Ls, 3))

Ans=0

for t in Tri:
    if t[0]<t[1]+t[2] and t[1]<t[0]+t[2] and t[2]<t[0]+t[1]:
        Ans+=1

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
readline = sys.stdin.readline
n = int(readline())
A = list(map(int,readline().split()))
A.sort()
ans =0
for i in range(1,n):
    for j in range(i+1,n):
        b = A[i]
        c = A[j]
        a = c -b
        ans += i- bisect.bisect(A[:i],a)
print(ans)

Submission status: Time Limit Exceeded

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

memo = [[0] * (N+1) for _ in range(N+1)]
for i in range(N - 1):
    for j in range(i + 1, N):
        memo[i][j] = (abs(L[i] - L[j]), L[i] + L[j])

ans = set()
for i in range(N - 2):
    l1 = L[i]
    for j in range(i + 1, N - 1):
        l2 = L[j]
        for k in range(j + 1, N):
            l3 = L[k]
            if memo[j][k][0] < l1 < memo[j][k][1]:
                ans.add(tuple(sorted([l1, l2, l3])))

print(len(ans))

Submission status: Time Limit Exceeded

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

l_list.sort()

count = 0
for i in range(n):
    start_j = i + 1
    a = l_list[i]
    for j in range(start_j, n):
        start_k = j + 1
        b = l_list[j]
        
        a_b = a + b
        for k in range(start_k, n):
            if (l_list[k] < a_b):
                count += 1
            else:
                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):
    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[k] + L[i]:
                    if L[k] < L[i] + L[j]:
                        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
a = 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 a[i]+a[j]>a[k] and a[i]+a[k]>a[j] and a[j]+a[k]>a[i]:
                ans += 1


print(ans)

Submission status: Time Limit Exceeded

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

def calc(a, b, c):
  if a < b + c:
    return 1
  return 0

n = int(input())
l = [int(s) for s in input().split()]
conter = 0
for v in itertools.combinations(l, 3):
    conter += calc(v[0],v[1],v[2]) & calc(v[1],v[0],v[2]) & calc(v[2],v[1],v[0])
print(conter)

Submission status: Time Limit Exceeded

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

cnt=0

L=sorted(L0)

for a in range(N-2):
    for b in range(a+1,N-1):
        for c in range(N-1,b,-1):
            if L[c]<L[a]+L[b]:
                  cnt+=1
            else:
                continue 
print(cnt)

Submission status: Time Limit Exceeded

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

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

L = sorted(L, reverse=True)

for i in range(N-2):
    if L[i+1] + L[i+2] <= L[i]:
        continue
    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]:
                total +=1
            else:
                break

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
A = [0]*1000
B = [0]*1000
ans = 0
for i in range(N):
    A[L[i]-1] += 1
B[0] = A[0]
for i in range(1,1000):
    B[i] = B[i-1]+A[i]
for i in range(N):
    for j in range(i+1,N):
        m = min([1000,L[i]+L[j]])
        n = max([L[i]-L[j],L[j]-L[i]])
        if n < L[i] and n < L[j]:
            r = 2
        elif n < L[i] or n < L[j]:
            r = 1
        else:
            r = 0
        ans += max([B[m-2] - B[n-1]-r,0])
print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)[::-1]

ans = 0
for i in range(n):
    max_l = l[i]
    for j in range(i+1, n):
        next_l = l[j]
        ans += n-j-1 - bisect.bisect_left(l[j+1:n][::-1], (max_l-next_l+0.01))
print(ans)

Submission status: Time Limit Exceeded

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

L.sort()

counter=0
i=0
while i<N-2:
  j=i+1
  k=j+1
  while j<N-1:
    if L[i]+L[j]>L[k]:
      if k<N-1:
        counter+=1
        k+=1
      else:
        counter+=1
        j+=1
        k=j+1
    else:
      j+=1
      if j==k:
        k+=1
  i+=1
  
print(counter)

Submission status: Time Limit Exceeded

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

def is_build(a, b, c):
    return (a<b+c)and(b<a+c)and(c<a+b)

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

print(buildable)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l= list(map(int, input().split()))
a=0
list.sort(l, reverse=True)
for i in range(n-2):
    ten = l[0]
    l.pop(0)
    for j in range(len(l)-1):
        for k in range(j+1,len(l)):
            if ten < l[j] + l[k] and l[j] < ten + l[k] and l[k] < l[j] + ten:
                a+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
def check(x,a,b,c):
    if x==a or x==b or x==c:
        return False
    return True


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

ans=[]

for i in range(n):
    for j in range(i+1,n):
        for z in range(j+1,n):
            a1=a[i]
            b1=a[j]
            c1=a[z]

            if a1+b1>c1 and a1+c1>b1 and c1+b1>a1:
                ans.append([i,j,z])
count =0


print(len(ans))
# for i in range(len(ans)):
#     for j in range(i+1,len(ans)):
#         if check(ans[i][0],ans[j][0],ans[j][1],ans[j][2]):
#             count+=1
#         elif check(ans[i][1],ans[j][0],ans[j][1],ans[j][2]):
#             count+=1
#         elif check(ans[i][2],ans[j][0],ans[j][1],ans[j][2]):
#             count+=1
# 
# 
# print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


def main():
    N = int(input())
    L = list(map(int, input().split()))
    min_l = min(L)
    max_l = max(L)

    ans = 0

    for a in range(N):

        for b in range(a+1, N):
            if L[a] >= L[b] + max_l:
                continue

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

count = 0
for a, b, c in combinations(ls, 3):
    if a < b + c and b < c + a and c < a + b:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

for a, aa in enumerate(li):
  if a < n - 2:
    for b, bb in enumerate(li[a+1:]):
      for c, cc in enumerate(li[a+1+b+1:]):
        if aa < bb + cc and bb < cc + aa and cc < aa + bb:
          ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
inf = float("inf")
# sys.setrecursionlimit(1000000)

from bisect import bisect_left,bisect_right
# import numpy as np

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())
Arr = get_array()
Arr.sort()

ans = 0
for i in range(n):
    for j in range(i+1,n):
        new = Arr[i]+Arr[j]
        ans+=bisect_left(Arr[j+1 : ], new)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
def judgement(a,b,c):
    if a < b + c:
        if b < c + a:
            if c < a + b:
                return True
    else:
        return False
def triangle(N,L):
    t = 0
    for i in range(0,N):
        for j in range(i+1,N):
            for k in range(j+1,N):
                if judgement(L[i],L[j],L[k]):
                    t = t + 1
    return t
print(triangle(N,L))

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-1):
    tmp=sorted(L[j+1:],reverse=True)
    for k in range(len(tmp)):
      if L[i]+L[j]>tmp[k]:
        ans+=len(tmp)-k
        break
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(len(li)):
    for j in range(i, len(li)):
        if i==j:
            continue
        for k in range(j, len(li)):
            if i==k or j==k:
                continue
            a = li[i]
            b = li[j]
            c = li[k]
            if (a < (b + c)) and (b < (a + c)) and (c < (a + b)):
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

t = []
r = [0]
def he(t, idx, l, r):
    if  len(t) == 3:
        a, b, c = t[0], t[1], t[2]
        if a < b + c and b < a + c and c < b + a:
            r[0] += 1
        return
    
    for i in range(idx, len(l)):
        t.append(l[i])
        he(t, i + 1, l, r)
        t.pop()

he(t, 0, L, r)
print(r[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N):
  for j in range(i + 1, N):
    for k in range(j + 1, N):
      #print(str(i) + str(j) + str(k))
      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:
n = int(input())
num =list(map(int,input().split()))

s_num = sorted(num, 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 s_num[i] < s_num[j] + s_num[k]:
                c += 1
                
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L_i = list(map(int, input().split()))
L_i.sort(key=lambda x: -x)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip
from itertools import permutations
from __builtin__ import xrange as range
from math import ceil
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from math import log, ceil
from bisect import bisect, insort, bisect_left, bisect_right
import heapq
import sys
import os
import re
inf = float('inf')
mod = int(1e9) + 7
mod_ = 998244353
 
'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''
 
def main():
    n=int(input())
    arr=list(map(int,input().split()))
    arr.sort()
    c=0
    i=0
    j=i+1
    while i<n-2:
        k=j+1
        while k<n and arr[k]<(arr[i]+arr[j]):
            k+=1
        c+=(k-j-1)
        j+=1
        if j>=n:
            i+=1
            j=i+1
    print(c)
    
    
 
BUFSIZE = 8192
class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(
                b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()
class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)
 
    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()
def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
    def bootstrap(cont):
        call, arg = cont.switch()
        while True:
            call, arg = cont.switch(to=continulet(
                lambda _, f, args: f(*args), call, arg))
    cont = continulet(bootstrap)
    cont.switch()
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product

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

print(cnt)

Submission status: Time Limit Exceeded

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

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