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())
L = list(map(int,input().split()))
s = 0
for i in range(N):
  a = L[i]
  for j in range(i):
    b = L[j]
    for k in range(j):
      c = L[k]
      if max(a,b,c)*2 < a+b+c:
        s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
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):
        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
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0
for trio in itertools.combinations(Ls, 3):
    a = trio[0]
    b = trio[1]
    c = trio[2]
    if a < b + c and b < c + a and c < a + b:
        ans = ans + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
L = [int(x) for x in input().split(' ')]

count = 0
for i, a in enumerate(L[:-2]):
    count += sum([(a < b + c) * (b < c + a) * (c < a + b) for b, c in itertools.combinations(L[(i+1):], 2)])

print(count)

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
l = nl()

l = sorted(l)[::-1]

ans = 0


for a in range(n):
    fl = 0
    for b in range(a+1,n):
        if fl == 1:
            break
        for c in range(b+1,n):
            A = l[a]
            B = l[b]
            C = l[c]

            if A >= B + C:
                if a+1 == b:
                    fl = 1
                break

            if B < A + C 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()))

def check(a, b, c):
    if a + b + c > 2 * max(a, b, c):
        return True
    else:
        return False

ans = 0
for i, j, k in itertools.combinations(range(N),3):
    if check(L[i], L[j], L[k]):
                ans += 1
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
ll=map(int,input().split())
from itertools import combinations
print(sum(1 for a,b,c in combinations(ll,3) if a<b+c and b<c+a and c<a+b))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
length = list(map(int, input().split()))
length.sort(reverse=True)
ans = 0


def tri_judge(i, j, k):
    if i+j > k and j+k > i and k+i > j:
        return True
    else:
        return False


for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if tri_judge(length[i], length[j], length[k]):
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
N = int(input())
edge = list(map(int, input().split()))
counter = 0

for i in range(len(edge) - 2):
    A = edge[i]
    for k in range(i + 1, len(edge)):
        B = edge[k]
        Cmin = max(A - B, B - A)
        Cmax = A + B
        for j in range(k + 1, len(edge)):
            if Cmin < edge[j] and edge[j] < Cmax:
                counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(x) for x in input().split()]
L = sorted(L, key=lambda x: -x)

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

print(num_triangle)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

res = 0
for a, b, c in combi_list:
    if a < b + c and b < c + a and c < a + b:
        res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = list(map(int,input().split()))
a = list(itertools.combinations(l,3))

ans = 0
for v in a:
    x = v[0]
    y = v[1]
    z = v[2]
    if x < y + z and y < x + z and z < y + x:
        ans += 1            


print(ans)

Submission status: Time Limit Exceeded

Solution code:
def f(L):
    n = len(L)
    L.sort()
    count = 0
    for i in range(n):
        for j in range(i + 1, n):
            a, b = L[i], L[j]
            for k in range(n):
                if k != i and k != j and L[k] < a + b:
                    # other two checks
                    if a < b + L[k] and b < L[k] + a:
                        count += 1
                else:
                    break
    return count

assert f([3, 4, 2, 1]) == 1
assert f([1, 1000, 1]) == 0
assert f([218, 786, 704, 233, 645, 728, 389]) == 23

_N = input()
L = list(map(int, input().split()))
ans = f(L)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    
    L = sorted(L)
    
    ans = 0
    for i in range(N-2):
        for j in range(N-1):
            if j > i:
                b = L[j] - L[i]
                c = L[i] + L[j]
                mi = bisect.bisect_left(L[j+1:], b)
                ma = bisect.bisect_left(L[j+1:], c)
                ans += ma - mi
    
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = list(map(int,input().split()))
a = [i for i in range(n)]
ans = 0

def abs(x):
    if x < 0:
        return -x
    else:
        return x

for x in itertools.combinations(a,3):
    if abs(l[x[0]]-l[x[1]]) < l[x[2]] < l[x[0]] + l[x[1]]:
        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):
    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:
N = int(input())
l_list = sorted(map(int,input().split()))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if l_list[i]+l_list[j] > l_list[k]:
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input().strip())
Ls = list(map(int, input().strip().split()))

ans = 0
for cs in combinations(Ls, 3):
    a, b, c = cs

    ret = (a < (b + c)) and (b < (c + a)) and (c < a + b)
    if ret:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n=int(input())
l=[int(i)for i in input().split()]
l2=list(combinations(l, 3))
sum=0
for i in range(len(l2)):
    a=l2[i][0]
    b=l2[i][1]
    c=l2[i][2]
    if(a<b+c and b<c+a and c<a+b):
        sum+=1
print(sum)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(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[i]+L[j]:
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, L: "List[int]"):
    combi = itertools.combinations(L,3)
    answer = 0
    for c in combi:
        if c[0]<c[1]+c[2] and c[1]<c[0]+c[2] and c[2]<c[1]+c[0]:
            answer += 1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def solve(n, l):
    l.sort()
    r = 0
    for i in range(n - 2):
        li = l[i]
        for j in range(i + 1, n - 1):
            lj = l[j]
            for k in range(j + 1, n):
                if li + lj <= l[k]:
                    break
                else:
                    # print(li, lj, l[k])
                    r += 1
    return r

def main():
    n = int(input())
    l = [int(x) for x in input().split()]
    print(solve(n, l))


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

input = sys.stdin.readline


def main():
    n = int(input())
    l = map(int, input().split())
    # 種類組み合わせ・条件
    hoge = 0
    for a, b, c in itertools.combinations(l, 3):
        if a < b + c and b < c + a and c < a + b:
            hoge += 1
    print(hoge)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
*l, = 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):
            s = sum([ l[i], l[j], l[k] ])
            m = max(l[i], l[j], l[k])
            if m < s-m:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
l_ls = [int(i) for i in sys.stdin.readline().split()]
l_ls.sort()
_sum_ls = []
cnt = 0
for i in range(1,n-1):
    base = l_ls[i]
    next_base = l_ls[i+1]
    for j in range(0,i):
        _sum_ls.append(l_ls[j] + base)
    for _sum in _sum_ls:
        if next_base < _sum:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
from bisect import bisect_left
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):
    s = l[i]+l[j]
    tmpl = l[j+1:n]
    ans += bisect_left(l[j+1:n], s)

print(ans)

Submission status: Time Limit Exceeded

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

result=0
for i in range(len(li)-2):
  for j in range(i+1,len(li)-1):
    for k in range(j+1,len(li)):
      if li[i]<li[j]+li[k] and li[j]<li[i]+li[k] and li[k]<li[j]+li[i]:
        result+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
import bisect
for i in range(n):
    for j in range(n):
        if i<j:
            a=l[i]
            b=l[j]
            x=bisect.bisect_left(l,a+b)
            for k in range(x):
                if k==i or k==j:
                    continue
                else:
                    c=l[k]
                    if a<(b+c) and b<(a+c) and c<(a+b):
                        ans+=1
print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

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


def main():
  input()
  values = list(map(int, input().split()))
  values.sort()
  result = 0

  for i in range(len(values) - 2):
    for j in range(i + 1, len(values) - 1):
      for k in range(j + 1, len(values)):
        if (values[i] < values[j] + values[k]
            and values[j] < values[i] + values[k]
            and values[k] < values[i] + values[j]):
          result += 1

  print(result)


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

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

if __name__ == "__main__":	
	N = int(input())
	L = [int(e) for e in input().split()]

	res = 0

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import bisect

N = int(input())
Llist = list(map(int, input().split()))
Llist.sort()

num = 0
for a, b in combinations(Llist, 2):
    mins = abs(a - b)
    maxs = a + b
    idx_front = bisect.bisect_right(Llist, mins)
    idx_back = bisect.bisect_left(Llist, maxs)
    num += idx_back - idx_front
    if a > mins and a < maxs:
        num -= 1
    if b > mins and b < maxs:
        num -= 1

print(num//3)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

N = int(input())
L = [int(v) for v in sys.stdin.readline().split()]

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted([int(x) for x in input().split()],reverse=True)
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if L[j] < L[i] / 2:
            break
        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:
import itertools

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

ans = 0

t = list(itertools.combinations(l,3))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split())) 
A.sort()
ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    val = A[i] + A[j]
    for k in range(j+1,N):
      if val > A[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.sort()

ans = 0
for i in range(2, N):
    large = L[i]
    for j in range(1, i):
        mideum = L[j] 
        for k in reversed(range(j)):
            if(L[k] > (large-mideum)):
                ans += 1

            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = [0]

x = list(itertools.combinations(a, 3))

def check_triangle(li):
    li.sort(reverse=True)
    if li[0] < li[1] + li[2]:
        count[0] += 1


for i in x:
    check_triangle(list(i))

print(count[0])

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N, *L= map(int, open(0).read().split())
X = sorted(L)
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        lb = bisect_left(X[j + 1:], X[j] - X[i])
        ub = bisect_left(X[j + 1:], X[j] + X[i])
        ans += ub - lb
        
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import bisect

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

L = sorted(L)

ans = 0
for i in range(N-2):
    for j in range(N-1):
        if j > i:
            b = L[j] - L[i]
            c = L[i] + L[j]
            mi = bisect.bisect_left(L[j+1:], b)
            ma = bisect.bisect_left(L[j+1:], c)
            ans += ma - mi

print(ans)

Submission status: Time Limit Exceeded

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

from itertools import combinations

ans = [1 for x1, x2, x3 in combinations(L, 3) if x1 < x2 + x3 and x2 < x1 + x3 and x3 < x2 + x1]

print(len(ans))

Submission status: Time Limit Exceeded

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

L.sort()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import heapq
import itertools
#import math
#import numpy as np
#import sys

N = int(input())
L = list(map(int, input().split()))
#S = [input() for _ in range(H)]
#T = [list(map(int,input().split())) for _ in range(N)]
#sys.exit()
L = sorted(L)
a = [(x, y, z) for (x, y, z) in itertools.combinations(L, 3) if ((x+y) > z) and ((x+z) > y) and ((y+z) > x)]
print(len(a))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

L_len = len(L)

count = 0
for i in range(L_len - 2):
    for j in range(i + 1, L_len - 1):
        for k in range(j + 1, L_len):
            f = 0
            if L[i] >= L[j] + L[k]:
                f = 1
            if L[j] >= L[i] + L[k]:
                f = 1
            if L[k] >= L[i] + L[j]:
                f = 1
            
            if f == 0:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    l_list = LI()

    # 短い順
    l_list = sorted(l_list)
    ind_list = list(range(len(l_list)))

    from bisect import bisect_left, bisect_right
    from itertools import combinations
    dprint(l_list)
    cnt = 0
    for a, b in combinations(ind_list, 2):
        # 2つえらぶ
        # 残りでできたl_listを作る
        cand_list = []
        for c in range(len(l_list)):
            if c != a and c!= b:
                cand_list.append(l_list[c])

        # cのmax, min
        la = l_list[a]
        lb = l_list[b]

        mx = la + lb
        mn = max(la, lb) - min(la, lb)

        # cand_listをbisectする
        right_ind_plus1 = bisect_left(cand_list, mx)
        left_ind = bisect_right(cand_list, mn)

        dprint(la, lb, mn, mx, cand_list, left_ind, right_ind_plus1, cnt)
        cnt += right_ind_plus1 - left_ind

    print(cnt//3)

solve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for a,b,c in itertools.combinations(l,3):
  if a<b+c and b < a+c and c < a+b:
    count += 1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
nums = list(map(int, input().split()))
ans = 0
nums = itertools.combinations(nums, 3)
for num in nums:
    a = num[0] < num[1] + num[2]
    b = num[1] < num[2] + num[0]
    c = num[2] < num[0] + num[1]
    if a and b and c:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    start_j = i + 1
    for j in range(start_j, n):
        start_k = j + 1
        for k in range(start_k, n):
            a = l_list[i]
            b = l_list[j]
            c = l_list[k]
            
            if (c<a+b and b<a+c and a<b+c):
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
flagC = False
# c-b < a
for i in range(n):
	a = l[i]
	for j in range(i+1,n):
		b = l[j]
		if b < a: break
		for k in range(j+1,n):
			c = l[k]
			if c - b < a: cnt += 1
			else:
				flagC = True
				break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:

import heapq
N = int(input())
nums = list(map(int,input().split(" ")))
nums.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if nums[k] < nums[i] +nums[j]:
                ans +=1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n = int(input())
    L = sorted(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 L[i] + L[j] > L[k]:
                    ans += 1
    print(ans)
solve()

Submission status: Time Limit Exceeded

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

# print(L)
ans = 0
for i in range(n):
    # print(i)
    a = L[i]
    ci = 0
    for j in range(i+1,n-1):
        b = L[j]
        ci = n-1
        # print("ci",ci)
        while ci > j and b+L[ci] <= a:
            ci -= 1
        ans += ci-j
print(ans)

Submission status: Time Limit Exceeded

Solution code:


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

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

count=0
for i in range(0,n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      #print(i,j,k)
      if check3(l[i], l[j], l[k]):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L_list = sorted([int(x) for x in input().split()])
cnt = 0
for i, a in enumerate(L_list[:-2]):
    for j, b in enumerate(L_list[i+1:-1]):
        for c in L_list[i+j+2:]:
            cnt += (c < a + b)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right
N = int(input())
L = [int(c) for c in input().split()]
L.sort()
ans = 0
for i in range(N):
  for j in range(i+1, N):
    x = L[i]+L[j]
    ind = bisect_left(L, x)
    IND = bisect_right(L,x)
    ans += ind-j-1 if ind-j>0 else 0
#    print(x,ind)

print(ans)

Submission status: Time Limit Exceeded

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


L_list.sort()

res = 0


for i in range(len(L_list)):
        a= L_list[i]
        for j in range(i+1,len(L_list)):
                b= L_list[j]
                for k in range(j+1,len(L_list)):
                        c= L_list[k]

                        if c<a+b:
                                res+=1
                        else:
                                break

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort(reverse=True)
c = 0
for ll in range(n):
    for lm in range(ll+1, n):
        for lr in range(lm+1, n):
            if l[ll] < l[lm] + l[lr]:
                c += 1

print(c)

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

print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np
N=int(input())
L=list(map(int, input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        for k in range(j+1,N):
            if L[k]<l:
                ans+=1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(l)):
    max_l = l[i]
    for j in range(i+1, len(l)):
        next_l = l[j]
        
        ans += sum([ll>(max_l-next_l) for ll in l[j+1:]])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 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:
                cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

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

s = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if (l[i] < l[j]+l[k]) and (l[j] < l[k]+l[i]) and (l[k] < l[i]+l[j]):
        s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = [int(elem) for elem in input().split()]

import itertools

res = 0
cands = itertools.combinations(ls, 3)
for a, b, c in cands:
    if a < (b + c) and b < (c + a) and c < (a + b):
        res += 1
print(res)

Submission status: Time Limit Exceeded

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

ret = 0

for i in range(len(l)):
	a = l[i]
	for j in range(i + 1, len(l)):
		b = l[j]
		for k in range(j+1, len(l)):
			c = l[k]
			if c >= a+b:
				break
			if a<b+c and b<a+c and c<a+b:
				ret += 1

print(ret)

Submission status: Time Limit Exceeded

Solution code:
n1 = int(input())
d1 = [int(i) for i in input().split()]

r1 = 0

for i1 in range(n1 - 1):
    for i2 in range(n1 - i1 - 1):
        for i3 in range(n1 - i1 - i2 - 2):
            if d1[i1] < d1[i2 + i1 + 1] + d1[i1 + i2 + i3 + 2]:
                if d1[i2 + i1 + 1] < d1[i1] + d1[i1 + i2 + i3 + 2]:
                    if d1[i1 + i2 + i3 + 2] < d1[i1] + d1[i2 + i1 + 1]:
                        r1 += 1

print(r1)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0
for a in range(N-2):
    for b in range(a+1, N-1):
        minc = L[a] + L[b]
        indc = bisect.bisect_left(L[b+1:], minc)
        ans += max(indc, 0)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def check(a, b, c):
    return True if a < b + c and b < a + c and c < a + b else False

def resolve():
    n = int(input())
    targets = list(map(int, input().split()))
    ans = 0

    for i in range(len(targets)):
        for j in range(i + 1,len(targets)):
            for k in range(j + 1,len(targets)):
                if check(targets[i],targets[j],targets[k]):
                    ans += 1



    print(ans)
resolve()

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