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())
ll = 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):
            tl = [ll[i], ll[j], ll[k]]
            tl.sort()
            if tl[0] + tl[1] > tl[2]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
ar = list(map(int, input().split()))
total = 0
for a, b, c in combinations(ar, 3):
    if a + b > c and b + c > a and c + a > b:
        total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

N = int(input())
L = list(map(int, input().split()))
ans = 0
for a,b,c in list(itertools.combinations(L, 3)):
  if tri_check(a,b,c):
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


n = int(input())
l = list(map(int, input().split()))
s = sum([a < b + c and b < c + a and c < a + b for a, b, c in combinations(l, 3)])
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools
ans=0
n=int(input())
l=list(map(int,input().split()))
for a,s,d in itertools.combinations(l, 3):
  if abs(a-s)<d<a+s:ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
L = list(map(int,input().split()))
ans = (N*(N-1)*(N-2))//6
L.sort()
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        ans -= bisect.bisect_right(L[:j],L[i]-L[j])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#import sys

#input = sys.stdin.readline



def main():
#    h,w,a,b = map(int, input().split())
    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 m in range(j+1,n):
                if l[m]<l[i]+l[j] and l[m]>abs(l[i]-l[j]):
                    count+=1
                
    print(count)






if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
l = list(map(int, input().split()))
count = 0
for a, b, c in combinations(l, 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())
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:
N = int(input())
L = map(int, input().split())

from itertools import combinations
X = list(combinations(L, 3))

ans = 0
for a,b,c in X:
    if a < b + c and b < c + a and c < a + b:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations
from random import random

import numpy as np

sys.setrecursionlimit(200000)


class Solver:
    def __init__(self):
        pass

    def input(self):
        """
            faster input function than builtin stdin.
        """
        return sys.stdin.readline()[:-1]

    def ii(self, t: type = int):
        """
            input single value.
        """
        return t(self.input())

    def il(self, t: type = int):
        """
            input single line.
        """
        return list(map(t, self.input().split()))

    def imi(self, N: int, t: type = int):
        return [self.ii(t) for _ in range(N)]

    def iml(self, N: int, t: type = int):
        return [self.il(t) for _ in range(N)]

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

    def solve(self):
        N = self.ii()
        L = self.il()
        ans = 0
        for l in combinations(L, 3):
            if self.is_triangle(*l):
                ans += 1

        return ans

if __name__ == "__main__":
    solver = Solver()
    print(solver.solve())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from bisect import bisect

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

def it():
    for i,j in combinations(range(N),2):
        if i+1 < j:
            a,c = L[i],L[j]

            yield max(0,j-bisect(L,abs(a-c), hi=j,lo=i+1))
print(sum(it()))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def solve(pair):
    a,b,c=pair[0],pair[1],pair[2]
    if a<b+c and b<a+c and c<a+b:
        return True
    return False
n=int(input())
arr=list(map(int,input().split()))
coms=list(combinations(arr,3))
c=0
for i in coms:
    if solve(i):
        c+=1
print(c)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        idx1 = bisect_right(l, abs(l[i] - l[j]))
        idx2 = bisect_left(l, l[i] + l[j])
        ansi = idx2 - idx1
        if abs(l[i] - l[j]) < l[i]:
            ansi -= 1
        if abs(l[i] - l[j]) < l[j]:
            ansi -= 1
        ans += ansi
        # print(l[i], l[j], idx1, idx2)

ans //= 3
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A,B = [int(a) for a in input().split()]
    L = sorted([int(a) for a in input().split()])
    # xy = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    r = 0
    for a in range(N):
        for b in range(a + 1, N):
            for c in range(N-1,b,-1):
                if L[a] + L[b] > L[c]:
                    r += (c-b)
                    break

    print(r)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            for k, lk in enumerate(L[i+j+2:]):
                if li < lj + lk and lj < lk + li and lk < li + lj:
                    res += 1
    print(res)

Submission status: Time Limit Exceeded

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

for i,a in enumerate(L):
    for j,b in enumerate(L[i+1:]):
        for k,c in enumerate(L[i+j+2:]):
            if c>=a+b:
                break
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

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

print(valid)

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

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

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

print(total)

Submission status: Time Limit Exceeded

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

from itertools import combinations

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = 0
for c in comb:
    if sum(c) - 2*max(c) > 0:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
res = 0
for comb in list(itertools.combinations(L, 3)):
    comb = sorted(comb)
    if comb[0] + comb[1] > comb[2]:
        res += 1
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

  return ans

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [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 a<b+c and b<a+c and c<a+b:
				ret += 1

print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

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

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      # print("{} {} {} {} {} {}".format(i,j,k,S[i],S[j],S[k]))
      if S[i]+S[j] <= S[k]:
        #print("break")
        cnt += k-j-1
        break 
    else:
      cnt += k-j
         
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

T = list(itertools.combinations(L,3))
ans = 0
for t in T:
    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 itertools

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

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

ans = 0
for ll in L:
    if ll[0] < ll[1] + ll[2] and ll[1] < ll[0] + ll[2] and ll[2] < ll[0] + ll[1]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
A = sorted([int(i) for i in input().split()])
B = [0 for _ in range(2200)]
for a in A:
	for i in range(0,a+1):
		B[i] += 1
C = 0
for i,a in enumerate(A):
	for j,b in enumerate(A):
		if i >= j:
			continue
		mn = max(a,b)-min(a,b) + 1
		mx = a + b
		C += B[mn]-B[mx]
		if mn <= a and a < mx:
			C -= 1
		if mn <= b and b < mx:
			C -= 1
print(int(C/3))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
l = list(map(int, input().split()))
cnt = 0
# print(list(combinations(l, 3)))
for ele in list(combinations(l, 3)):
    if ele[0] < ele[1] + ele[2] and ele[1] < ele[0] + ele[2] and ele[2] < ele[0] + ele[1]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
k = 0
for i in range(n):
    for j in range(i + 1, n):
        m = l[j+1:]
        ind = bisect.bisect_left(m, l[i] + l[j])
        k += ind
print(k)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
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):
        if i == j:
            continue
        ans += bisect_left(l, l[i] + l[j], lo=j + 1) - j - 1
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

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(N):
        for k in range(N):
            if i< j< k:
                if L[i-1]< L[j-1] + L[k-1] and L[j-1]< L[i-1] + L[k-1] and L[k-1]< L[j-1] + L[i-1]:
                    n +=1
print(n)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def read():
    N = int(input().strip())
    L = list(map(int, input().strip().split()))
    return N, L

def solve(N, L):
    L.sort()
    count = 0
    for a, b, c in itertools.combinations(L, 3):
        if c < a + b:
            count += 1
    return count

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

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):
    for b in range(a+1,n):
        for c in range(b+1,n):
            A = l[a]
            B = l[b]
            C = l[c]

            if A >= B + C:
                break

            if B < A + C and C < A + B:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[int(i) for i in input().split()]
p=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=s[i],s[j],s[k]
            if a+b>c and b+c>a and c+a>b:
                p+=1
print(p)

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

Submission status: Time Limit Exceeded

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

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

print(cnt)

'''
a = []
for i in range(n):
    for j in range(i+1,n):
        a.append(l[i]+l[j])

cnt = 0
for i in range(len(a)):
    for j in range(n):
        if a[i] > l[j]:
            cnt += 1

print(cnt)
'''

Submission status: Time Limit Exceeded

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


res = 0

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

                        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 = [int(x) for x in input().split()]
c = 0
for l in itertools.combinations(L, 3):
  if sum(l) - max(l) > max(l):
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

c=0
for i in combinations(l,3):
    p=max(i)
    if p<sum(i)-p:
        c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

n = int(input())
lll = list(map(int, input().split()))
lll.sort()
ans = 0

for i in range(n - 2):
    li = lll[i]
    for j in range(i + 1, n - 1):
        k = bisect_left(lll, li + lll[j], lo=j)
        ans += k - j - 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(input())
L = [0] + list(map(int, input().split()))

L.sort()

def check(i, j, k):
    return L[k] < L[i] + L[j]


# 条件を満たす最大の値を返す
def binarySearch(small, big,i,j):
    mid = (big + small) // 2
    if big - small <= 1:
        if check(i,j,big): return big
        else:          return small
    else:
        if check(i,j,mid):
            return binarySearch(mid, big,i,j)
        else:
            return binarySearch(small, mid,i,j)


ans = 0
for i in range(1, N):
    for j in range(i+1, N):
        k = binarySearch(j+1, N, i, j)
        if check(i, j, k):
            ans += k-j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

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

N = INT()
L = LIST()

count = 0
for ll in itertools.combinations(L, 3):
    if (ll[0] < ll[1] + ll[2]) and (ll[1] < ll[2] + ll[0]) and (ll[2] < ll[0] + ll[1]):
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import bisect

n = int(input())
l = nl()
l.sort()
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        a,b = l[i],l[j]
        if a > b:
            a,b = b,a
        lef = bisect.bisect_right(l,b-a)
        rig = bisect.bisect_left(l,a+b)
        t = rig - lef - 1 - (b < 2*a)
        ans += t
print(ans//3)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

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, reverse=True)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            for h in range(j+1, n):
                # print(ls[i], ls[j], ls[h])
                if ls[i] < ls[j] + ls[h]:
                    # print(ls[i], ls[j], ls[h])
                    ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dat = list(map(int, input().split()))
res = 0
dat.sort(reverse=True)
for a in range(n):
    for b in range(a+1, n):
        if dat[a] >= (dat[b] * 2):
            break
        for c in range(b+1, n):
            if dat[a] < (dat[b] + dat[c]) and dat[b] < (dat[c] + dat[a]) and dat[c] < (dat[a] + dat[b]):
                res += 1
            else:
                break
print(res)

Submission status: Time Limit Exceeded

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

result = 0
for a in range(N):
    for b in range(a+1, N):
        for c in range(b+1, N):
            if arr[c] >= arr[a]+arr[b]:
                break
            result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC143C
import sys
import math
import collections
#sys.setrecursionlimit(100000)


n=int(input())

tmp = input().split()
l = list(map(lambda a: int(a), tmp))

sum=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[k]+l[j]>l[i])):
				sum+=1

print(sum)

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):
      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 = list(map(int, input().split()))
l.sort()
ans = 0

for i in range(n):
    for j in range(i+1, n):
        length = l[i] + l[j]

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = map(int, raw_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]) & (l[i] + l[k] > l[j]) & (l[j] + l[k] > l[i]):
				s += 1

print s

Submission status: Time Limit Exceeded

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

def main():
    n = int(input())
    l = map(int, input().split())
    t = list(itertools.combinations(l,3))
    cnt = 0
    for a, b, c in t:
        if a<b+c and b<c+a and c<a+b:
            cnt += 1
    print(cnt)




if __name__ == '__main__':
        main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
n=int(input())
li=[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):
            a=li[i]
            b=li[j]
            c=li[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 = list(map(int,input().split()))	
l.sort()
ans=0
if l[0]+l[1]>l[n-1]:
    print((n*(n-1)*(n-2))//6)
    exit()
else:
    for i in range(n-2):
        for j in range(n-i-2):
            j+=i+1
            for k in range(n-j-1):
                k+=j+1
                if l[i]+l[j]>l[k]:
                    ans+=1
                else:
                    break
print(ans)

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):
            a,b,c = l[i],l[j],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:
#D問題
N = int(input())
L = list(map(int,input().split()))
L.sort()
T = []

for i in range(N):
    for j in range(N):
        if j <= i:
            pass
        else:
            for k in range(N):
                if k <= j:
                    pass
                else:
                    I,J,K = L[i],L[j],L[k]
                    if I < J+K and J < I+K and K < I+J:
                        if [I,J,K] not in T:
                            T.append([I,J,K])
                                
                                
print(len(T))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
from itertools import combinations
ans = 0
for a,b,c in combinations(L,3):
    if a < b+c and b < a+c and c < a+b:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def tri(l):
    if l[0]<l[1]+l[2] and l[1]<l[2]+l[0] and l[2]<l[0]+l[1]:
        return True
    else: return False

import itertools
n=int(input())
l=list(map(int,input().split()))
li=list(itertools.combinations(l,3))
print(sum([tri(i) for i in li]))

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):
            a, b, c = l[i], l[j], 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().strip())
L = sorted(list(map(int, input().strip().split(' '))))
ans = 0
for i,j in itertools.combinations(range(N-1) ,2):
  for k in range(j+1, N):
    if 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()]

ans=0
for i in range(n-2):
    now=set()
    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]:
                #print(l[i],l[j],l[k])
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)

ans=0
for i in range(N):
  for j in range(i+1,N):
    if L[i]>=2*L[j]:
      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 sys
input = sys.stdin.readline
def solve():
  n = int(input())
  l = list(int(i) for i in input().split())
  l = sorted(l,reverse = True)
  ans = 0
  for i in range(n):
    for j in range(i+1,n):
      for k in range(j+1,n):
        a = l[i]
        b = l[j]
        c = l[k]
        if a< b+c and b< c+a and c < a+b:
          ans += 1
  print(ans)
  
solve()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


ans = 0

for x, y, z in itertools.combinations(l, 3):
    if x < y + z and y < z + x and z < x + y:
        ans += 1

print(ans)