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 sys
import bisect

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ls = LI()
    ls = sorted(ls)
    ans = 0
    for i in range(n):
        for j in range(i):
            ans += j - (bisect.bisect_right(ls[:j], ls[i] - ls[j]))

            # ans += a
            # print(ls[i], ls[j], bisect.bisect_left(ls[:j], ls[i] - ls[j]))
            # if ls[i] < ls[j] + ls[h]:
            #     # print(ls[i], ls[j], ls[h])

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:


n = int(input())

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


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

choice = [[l[i],l[j],l[k]] for i in range(0,n) for j in range(i+1,n) for k in range(j+1,n)]

ret = list(map(check3, choice))

print(sum(ret))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = [int(v) for v in input().split()]

comb = list(itertools.combinations(l, 3))
count = 0
for i in range(len(comb)):
    x = comb[i][0] + comb[i][1]
    y = comb[i][1] + comb[i][2]
    z = comb[i][0] + comb[i][2]
    if x > comb[i][2] and y > comb[i][0] and z > comb[i][1]:
        count += 1
    else:
        continue

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

Submission status: Time Limit Exceeded

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

s = 0
# print(l_s)

for i in range(n):
    for j in range(i+1,n):
        if l_s[i] >= l_s[j] * 2:
            break
        for k in range(j+1,n):
            if l_s[i] < l_s[j]+l_s[k]:
                s += 1
            else:
                break
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

    comb = itertools.combinations(L, 3)

    ans = 0
    for v in comb:
        if not v[0] < v[1] + v[2]:
            continue
        elif not v[1] < v[2] + v[0]:
            continue
        elif not v[2] < v[0] + v[1]:
            continue
        else:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def upperbound(nums, value):
    low = 0
    high = len(nums)
    while low < high:
        mid = (low + high) >> 1
        if value > nums[mid]:
            low = mid + 1
        else:
            high = mid
    return low


n = int(input())
ar = list(map(int, input().split()))
ar.sort()
total = 0
for i in range(n):
    for j in range(i + 1, n):
        sum2edge = ar[i] + ar[j]
        index = upperbound(ar, sum2edge)
        if index > j:
            total += (index - j - 1)
print(total)

Submission status: Time Limit Exceeded

Solution code:

import bisect
n = int(input())
L = list(map(int,input().split()))
L.sort()
goukei = []
for i in range(n-1):
    for j in range(i+1,n):
        tmp = L[i] + L[j]
        tm = [tmp,j]
        goukei.append(tm)
ans = 0
for i in range(len(goukei)):
    ans+=  bisect.bisect_left(L[goukei[i][1]+1:],goukei[i][0])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(len(l)-2):
    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[i]+l[j]:
                ans+=1
print(ans)

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
        for c in range(b+1,n):
            C = array[c]
            if ab < C:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
import itertools 
def findsubsets(s, n): 
    return list(itertools.combinations(s, n))
s = set(range(0, n))
com = findsubsets(s, 3)
c = 0
fin = []
for i in com:
    tem = list(i)
    tem.sort()
    fin.append(tem)
l.sort()
for i in fin:
    if l[i[0]] + l[i[1]] > l[i[2]]: c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
n = int(input())
l = list(map(int, input().split()))
 
cnt = 0
 
for subset in itertools.combinations(l, 3):
    L = [subset[0],subset[1],subset[2]]
    L.sort()
    if abs(L[0]-L[1]) < L[2] < L[0]+L[1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
for i, l1 in enumerate(L):
    for k, l2 in enumerate(L[i+1:]):
        num = i + k + 2
        for l3 in L[num:]:
            if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l2 + l1:
                count += 1
            else:
                break

print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    ans = 0
    for i in range(len(l)-2):
        first = l[i]
        for j in range(i + 1, len(l) - 1):
            second = l[j]
            for k in range(j + 1, len(l)):
                if l[k] >= first + second:
                    break
                else:
                    ans += 1
                    #print(first, second,l[k])
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

n = int(input())
lst = list(map(int,input().split()))
ans = 0
lst.sort()
for i in range(n):
    for j in range(i+1,n):
        b,c = lst[i],lst[j]
        posr = bisect_left(lst,b+c)
        posl = max(j+1,bisect_left(lst,abs(b-c)))
        ans += (posr - posl)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int, input().split(" ")))
k = 0
for i in range(N-2):
    a = l[i]
    for j in range(i+1, N-1):
        b = l[j]
        k += len([p for p in l[j+1:] if abs(b-a) < p < (a+b)])
print(k)

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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


def number_of_triangles():
    if N < 3:
        return 0
    result = 0
    for a, b, c in combinations(L, 3):
        if a < b + c and b < c + a and c < a + b:
            result += 1
    return result

print number_of_triangles()

Submission status: Time Limit Exceeded

Solution code:
import bisect as bis

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

res = 0
for i, a in enumerate(L):
    for k, b in enumerate(L[i + 1:]):
        j = k + i + 1

        left = b - a
        right = a + b

        index_l = bis.bisect_right(L, left, j)
        index_r = bis.bisect_left(L, right, j)
        res += index_r - index_l - 1
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(valid)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

result=0
for i in range(n-1):
  for j in range(i+1,n):
    temp=a[i]+a[j]
    #print(a[i],a[j],a[j+1:])
    result+=max(0,np.count_nonzero(a[j+1:] < temp))

print(result)

Submission status: Time Limit Exceeded

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


def solve(N: int, L: "List[int]"):
    L.sort()
    sum=0
    if len(L)<3:
        print(sum)
        return

    for i in range(len(L)-2):
        for j in range(i+1,len(L)-1):
            if i==j:
                continue
            for k in range(j+1,len(L)):
                if k==i or k==j:
                    continue
                if (L[i]+L[j]>L[k]) and (L[j]+L[k]>L[i]) and (L[i]+L[k]>L[j]):
                    sum=sum+1
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
N=int(input())
L_list=[int(thing) for thing in input().split()]
L_list.sort(reverse=True)

ret=0
for i in range(N):
    n=L_list[i]
    for j in range(i+1,N):
        k=L_list[j]
        for h in range(j+1,N):
            l=L_list[h]
            if n+l>k and k+l>n:
                ret=ret+1
            else:
                break
print(ret)

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):
        rest = llist[j+1:]
        num = llist[i] + llist[j] 
        idx = bisect_left(rest, num)
        res += idx

print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
ans = 0
L.sort()
for na,a in enumerate(L[:N-2]):
    for nb_,b in enumerate(L[na+1:N-1]):
        nb = nb_+na+1 
        for c in L[nb+1:]:
            if 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()
L.reverse()
a=L.pop(0)
count=0
while(L!=[]):
    for i in range(len(L)):
        for j in range(i+1,len(L)):
            if a < L[i]+L[j]:
                count+=1
    a=L.pop(0)
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):
    for j in range(i):
        for k in range(j):
            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:
N = int(input())
L= sorted(list(map(int, input().split())))

count = 0
for i in range(N):
  for j in range(i + 1, N):
    x = L[i] + L [j]
    y = L[j]
    count += sum(x > p > y for p in L)
    #print(count)
print(count)

Submission status: Time Limit Exceeded

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

            elif l[i] + l[j] < l[k]:
                break

print(output)

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):
      count=0
      for x in [i,j,k]:
        if 2*L[x]<L[i]+L[j]+L[k]:
          count+=1
      if count==3:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int, input().split()))
S=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]:
                S+=1
print(S)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
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
        for k in range(j, N):
            if j == k:
                continue
            if L[i] >= L[j] + L[k]:
                continue
            elif L[j] >= L[i] + L[k]:
                continue
            elif L[k] >= L[j] + L[i]:
                continue
            else:
                ans += 1
print(ans)

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]
        c = L[j+1]
        if not a < b+c:
            break
        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:
# -*- coding: utf-8 -*-
N = int(input())
L_list = list(map(int, input().split()))

ans = 0
L_list.sort(reverse=True)
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[j] < L_list[i] + L_list[k]:
                    ans += 1
                else:
                    break
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(_) for _ 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 abs(L[j] - L[k]) < L[i] < L[j] + L[k]:
                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())))

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]) 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:
N=int(input())
L=list(map(int,input().split()))

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

Submission status: Time Limit Exceeded

Solution code:
import heapq

n = int(input())
l = [int(x) * -1 for x in input().split()]

l.sort()
ans = 0
Flag = True

for i in range(n):
    a = heapq.heappop(l)
    for j in range(len(l)):
        for k in range(j+1,len(l)):
            if a > l[j] + l[k]:
                ans += 1
                Flag = False
    if Flag:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
  n = int(raw_input())
  parts = map(int, raw_input().split())
  result = 0
  conditions = [
    lambda a,b,c: a<b+c,
    lambda a,b,c: b<c+a,
    lambda a,b,c: c<a+b,
  ]
  for comb in itertools.combinations(parts, 3):
    if all([func(*comb) for func in conditions]):
      result += 1
  print(result)

main()

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)
count = 0

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

Submission status: Time Limit Exceeded

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

from collections import defaultdict

d = defaultdict(int)

for i in range(n):
    d[s[i]]+= 1

r = 0
key = sorted(list(d.keys()))
ng = len(key)
for i in range(ng)[::-1]:
    for j in range(i+1):
        for k in range(j, i+1)[::-1]:
            ti = 0
            if key[i] == key[j] and key[j] == key[k]:
                if d[key[i]] < 3:
                    continue
                else:
                    ti = d[key[i]] * (d[key[i]]-1) * (d[key[i]]-2) // 6
            elif key[i] == key[j]:
                if d[key[i]] < 2:
                    continue
                else:
                    ti = d[key[i]] * (d[key[i]]-1) * d[key[k]] // 2
            elif key[j] == key[k]:
                if d[key[k]] < 2:
                    continue
                else:
                    ti = d[key[j]] * (d[key[j]]-1) * d[key[i]] // 2
            elif key[i] == key[k]:
                if d[key[i]] < 2:
                    continue
                else:
                    ti = d[key[i]] * (d[key[i]]-1) * d[key[j]] // 2
            else:
                ti = d[key[i]] * d[key[j]] * d[key[k]]
            if key[j] + key[k] <= key[i]:
                break
            else:
                r+=ti
print(r)

Submission status: Time Limit Exceeded

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

L.sort()
#print(L)

from bisect import bisect_left

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1:]):
        j=i+1+j
        #print(a+b, abs(a-b), i, j)
        #for k, c in enumerate(L[j+1:]):
        #    if abs(a-b) < c and c < a+b:
        #        ans += 1
        #    if c >= a+b:
        #        break
        l = bisect_left(L[j+1:], abs(a-b))
        r = bisect_left(L[j+1:], a+b)
        #print(r-l)
        ans += r-l
print(ans)

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

Submission status: Time Limit Exceeded

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

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

total = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            a, b, c = bou_list[i], bou_list[j], bou_list[k]
            if a == b or b == c or c == a:
                pass
            else:
                if triangle_check(a, b, c):
                    total += 1

print(total//3//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
input_list = list(map(int, input().split()))
sum = 0
for a in range(n):
    for b in range(n):
        if a <= b: break
        for c in range(n):
            if b <= c: break
            A = input_list[a]
            B = input_list[b]
            C = input_list[c]
            if A < B + C and B < A + C and C < A + B:
                sum += 1
print(sum)

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:
N = map(int, input().split())
L = list(map(int, input().split()))

L.sort()

value = 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 c < a+b:
                if a < c+b:
                    if b < c+a:
                        value+=1
            else:
                break
                

print(value)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int,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 arr[a]<arr[b]+arr[c] and arr[b]<arr[c]+arr[a] and arr[c]<arr[a]+arr[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):
  if L[i] > 2*max(L[i:]):
      continue
  for j in range(N):
    if i<=j:
      continue
    if L[i] > L[j] + max(L[j:]):
      continue
    for k in range(N):
      if j<=k:
        continue
        
      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())
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[i] > abs(l[j]-l[k])):
        s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int,input().split()))
L.sort()
tri = list(itertools.combinations(L,3))
cnt = 0
for a,b,c in tri:
    if a < (b+c) and b < (c+a) and c < (a+b):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

cnt = 0

for subset in itertools.combinations(l, 3):
    L = [subset[0],subset[1],subset[2]]
    L.sort()
    if abs(L[0]-L[1]) < L[2] < L[0]+L[1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import numpy as np
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
L = np.array(L)
ans = 0
# print(*L)
for i in range(N):
    for j in range(i+1, N):
        tmp = L[j+1:] > L[i] - L[j]
        ans += int(sum(tmp))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
nl = sorted(l,reverse=True)
c = 0
for i in range(n-2):
    a = nl[i]
    for j in range(n-1,i,-1):
        for k in range(i+1,j):
            if a<(nl[j]+nl[k]):
                c+=1
            else:
                break
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

n = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

L =list(itertools.combinations(L, 3))
cnt =0
for ele in L:
    if(ele[0] >= ele[1]+ele[2]):
        continue
    if(ele[1] >= ele[0]+ele[2]):
        continue
    if(ele[2] >= ele[0]+ele[1]):
        continue
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

l.sort()
l.reverse()
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
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    l = LIST()
    lis = list(combinations(l, 3))
    #print(lis)
    ans = 0
    for x in lis:
        #print(abs(x[0] - x[1]) , x[2] , x[0] + x[1])
        #print(abs(x[0] - x[1]) < x[2] < x[0] + x[1])
        if abs(x[0] - x[1]) < x[2] < x[0] + x[1]:
            ans +=1
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
n=int(input().rstrip())
l=input().split(" ")
for i in range(n):
    l[i]=int(l[i])
l=sorted(l)

ans = 0;
a=0
b=1
c=2
while(1):
    while(1):
        while(1):
            if(l[a]<l[b]+l[c] and l[b]<l[a]+l[c] and l[c]<l[a]+l[b]):
                ans=ans+1
                c= c+1;
                if(c >=n):
                    break
            else:
                break
        b=b+1
        c=b+1
        if(c >=n):
            break
    a=a+1
    b=a+1
    c=b+1
    if(c>=n):
        break
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for a in range(0, N):
    for b in range(a+1, N):
        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)

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
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] and L[j] < L[k]+L[i] and L[k] < L[i]+L[j]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
from collections import Counter
cou=Counter(l)
ll=[]
for i in range(n):
    if not l[i] in ll:
        ll.append(l[i])

ans=0
for i in range(len(cou)):
    x=cou[i]
    if x>=3:
        ans+=(x*(x-1)*(x-2)//6)

import bisect

ans2=0
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):
                        ans2+=(cou[a]*cou[b]*cou[c])

print(ans+(ans2//3))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4000000)

import itertools

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

cnt = 0
for l in itertools.combinations(L, r=3):
    a, b, c = l[0], l[1], l[2]
    if a < b + c:
        if b < c + a:
            if c < a + b:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))

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

    print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Lsorted = sorted(L)
ret = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      a = Lsorted[i]
      b = Lsorted[j]
      c = Lsorted[k]
      if c >= (a + b):
        break
#      if b >= (a + c):
#        break
#      if a >= (b + c):
#        break
      
      ret += 1
    
    if b >= (a + c):
      break
  if a >= (b + c):
    break
print(ret)

Submission status: Time Limit Exceeded

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

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

cmb_l = list(itertools.combinations(L, 3))
sum = 0
for cmb in cmb_l:
    if is_triangle(cmb[0],cmb[1],cmb[2]):
        sum += 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(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:
from itertools import permutations, combinations,combinations_with_replacement,product

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

L.sort()

cnt = 0
l = list(combinations(L,3))

for i in l:
    if i[0] + i[1] > i[2]:
        cnt += 1
    else:
        pass

print(cnt)

Submission status: Time Limit Exceeded

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