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())
A = sorted(map(int, input().split()))
ans = 0

for i in range(0, N-2):
       for k in range(i+1, N-1):
            for l in range(k+1, N):
                if A[i]+A[k] > A[l]:
                    ans +=  1
                elif A[i]+A[k] <= A[l]:                  
                    break
print(ans)

Submission status: Time Limit Exceeded

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


def solve(N: int, L: "List[int]"):
    bar_3 = itertools.combinations(L, 3)

    result = 0
    for a, b, c in bar_3:
        if a < b + c and b < c + a and c < a + b:
            result += 1
        else:
            pass

    print(result)
    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:
import itertools
N = int(input())
L = map(int,input().split())
tmp = list(itertools.combinations(L,3))
ans = 0
for i in range(len(tmp)):
    if abs(tmp[i][1] - tmp[i][2]) < tmp[i][0]:
        if tmp[i][0] < (tmp[i][1] + tmp[i][2]):
            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]:
        if l[j] < l[k] + l[i]:
          if l[k] < l[i] + l[j]:
            s = s+1
 
  
print(s)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    L.reverse()

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                if i != j and j != k and k != i:
                    if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
                        ans += 1
                        # print("{} {} {}".format(L[i], L[j], L[k]))

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lx = list(map(int,input().split()))
lx = sorted(lx)
mm = 0
for c1 in range(n):
    a = lx[c1]
    for c2 in range(c1+1, n):
        b = lx[c2]
        for c3 in range(c2+1, n):
            c = lx[c3]
            if a+b <= c:
                break
            else:
                mm += 1
            #print(a,b,c)
print(mm)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1,n-1):
    for j in range(i+1,n):
        if l[j] - l[i] >= l[i-1]:
            break
        elif i - bisect.bisect_right(l,(l[j]-l[i])) > 0:
            ans += i - bisect.bisect_right(l,(l[j]-l[i]))
print(ans)

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

            C = l[c]

            if A >= B + C:
                break

            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
*L, = map(int, input().split())
ans = 0
while len(L) >= 3:
    c = L.pop()
    for a, b in combinations(L, 2):
        if abs(a - b) < c < a + b: ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
L = read_ints()
L.sort()
import numpy as np
L = np.array(L)

cnt = 0
for i in range(N):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        L_tmp = L[j+1:]
        cnt += np.sum(L_tmp < b+a)

print(cnt)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
ans=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if L[i] < L[j] + L[k]:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
##################################################################

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
L = list(map(int,input().split()))
ans = 0
for cmb in combinations(L,3):
  max_val = max(cmb)
  if 2*max_val < sum(cmb): ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = tuple(map(int, input().split()))
T = 0
for i in range(n-2):
  a = t[i]
  for j in range(n-i-1):
    b = t[i+j+1]
    for k in range(n-i-j-2):
      c = t[i+j+k+2]
      m = max(a,b,c)
      if m < a+b+c-m :
        T += 1
print(T)

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)
b_end = N - 1
c_end = N
for i in range(N - 2):
    for j in range(i + 1, b_end):
        for k in range(j + 1, c_end):
            if L_list[i] < L_list[j] + L_list[k]:
                ans += 1
            else:
                b_end = k
                c_end = k + 1
                break
    b_end = N - 1
    c_end = N

print(ans)

Submission status: Time Limit Exceeded

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

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 i in range(len(comb)):
    a = comb[i][0]
    b = comb[i][1]
    c = comb[i][2]
    if (a < b + c) and (b < c + a) and (c < a + b):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
N = int(input())
edge = list(map(int, input().split()))
edge.sort()
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
        last = edge[k + 1::]
        ham = [x for x in last if (Cmin < x and x < Cmax)]
        counter += len(ham)
print(counter)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = input()
seq = [int(x) for x in input().split()]
total = []
x = list(itertools.combinations(seq,3))

for i in range(len(x)):
    if (x[i][0] < x[i][1] + x[i][2]):
        if x[i][1] < (x[i][2] + x[i][0]):
            if  x[i][2] < (x[i][1] + x[i][0]):
                total.append(x[i])
print(len(total))

Submission status: Time Limit Exceeded

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

L.sort(reverse = True)
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i] < L[j] +L[k] and L[j] < L[k] + L[i] and L[k] < L[i] +L[j]:
                count += 1
            else: 
                break
                
print(count)

Submission status: Time Limit Exceeded

Solution code:

from sys import stdin
import itertools

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

ans = 0
for v in itertools.combinations(ls, 3):
    #print(v)
    a=int(v[0])
    b=int(v[1])
    c=int(v[2])
    if a<b+c:
        if b<c+a:
            if c<a+b:
                ans += 1
            else:
                continue
        else:
            continue
    else:
        continue

print(int(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def backtrack(i, j, memo):
    if (i, j) in memo:
        return 0
    memo[i, j] = True
    l1, l2 = L[i], L[j]
    count = 0
    for l3 in L[j + 1:]:
        if l3 < l1 + l2 and l2 < l1 + l3 and l1 < l2 + l3:
            count += 1
        else:
            break
    return count


if __name__ == '__main__':
    input()
    L = [int(x) for x in input().split()]
    L.sort()
    total = 0
    memo = {}
    for i in range(len(L)):
        for j in range(i + 1, len(L)):
            total += backtrack(i, j, memo)
    print(total)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
llist=list(map(int,input().split()))
kazoe=0

llist.sort()
for a in range(n-2):
	for b in range(a+1,n-1):
		c=b+1
		while llist[a]+llist[b]>llist[c] :
			c+=1
			if c==n:
				break
		for d in range(b+1,c):
			if llist[b]-llist[a]<llist[d]:
				kazoe+=1
		c=b+2
print(kazoe)

Submission status: Time Limit Exceeded

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

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

print(count)

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
dic={}

for i in range(1,a[-1]+1):
  dic[i]=np.count_nonzero(a<=i)

#print(dic)
  
for i in range(n-2):
  for j in range(i+1,n-1):
    if a[i]+a[j]>a[j+1]:
      temp=a[i]+a[j]
      result+=max(0,dic[min(a[-1],temp-1)]-dic[a[j]])
      #print(a[i],a[j],a[j+1:],result)

print(result)

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-1):
        k=L_list[j]
        m=n-k
        s= len([l for l in L_list[j + 1:N] if l > m])
        ret=ret+s
        if s==0:
            break

print(ret)

Submission status: Time Limit Exceeded

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

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):
    t += len([c for c in l if c>l[j] and c<l[i]+l[j]])
print(t)

Submission status: Time Limit Exceeded

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            a, b = [l[i], l[j]]
            tl = [a + b, abs(a - b)]
            mi = min(tl) + 1
            ma = min(max(tl) - 1, a - 1)
            for k in range(i-1, -1, -1):
                if l[k] < mi:
                    break
                elif mi <= l[k] <= ma:
                    ttl = sorted([i, j, k])
                    if (ttl[0], ttl[1], ttl[2]) not in d:
                        d[(ttl[0], ttl[1], ttl[2])]
                        cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = list(map(int, input().split()))
T = 0
for i in range(n-2):
  a = t[i]
  for j in range(n-i-1):
    b = t[i+j+1]
    for k in range(n-i-j-2):
      c = t[i+j+k+2]
      m = max(a,b,c)
      if m < a+b+c-m :
        T += 1
print(T)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

def check03(i,j):
  ret03=0
  for k in range(j+1,n):
    if l[i] >= (l[j]+l[k]):
      ret03+=1
  return ret03

def check02(i):
  ret02=0
  for j in range(i+1,n-1):
    ret02 += check03(i,j)
  return ret02

count=0
for i in range(0,n-2):
  count += check02(i)


count_all = n*(n-1)*(n-2)/6

#print(count_all)
print(int(count_all-count))

Submission status: Time Limit Exceeded

Solution code:
#from scipy.special import comb
from scipy.misc import comb
# a = comb(n, r)
# a = comb(n, r, exact=True)

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
a = []
a.append(l[0])
cnt = 1
numMap = {}

for i in range(1, n):
    if l[i] == l[i-1]:
        cnt += 1
    else:
        numMap[l[i-1]] = cnt
        a.append(l[i])
        cnt = 1

numMap[l[-1]] = cnt

for i, val in numMap.items():
    #print(i, val)
    temp = comb(val, 3, exact=True)
    ans += temp

# print(a)
# print(numMap)
# print(ans)

for i in range(len(a)):
    for j in range(i+1, len(a)):
        length = a[i] + a[j]

        for k in range(j+1, len(a)):
            if a[k] >= length:
                break
            else:
                ans += numMap[a[i]] * numMap[a[j]] * numMap[a[k]]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import bisect

N = int(input())
l_list = sorted(list(map(int,input().split())))
ans = 0

for i in range(N):
    for j in range(i+1,N):
        comb = [l_list[i],l_list[j]]
        minlen = max(comb) - min(comb)
        maxlen = l_list[i] + l_list[j]
        minindex = bisect.bisect_right(l_list[j+1:],minlen)
        maxindex = bisect.bisect_left(l_list[j+1:],maxlen)
        ans += maxindex - minindex

print(ans)

Submission status: Time Limit Exceeded

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

l.sort()
cnt = 0
import itertools
import bisect
for a, b in itertools.combinations(l, r=2):
  #print(a, b, end=' : ')

  left = bisect.bisect_left(l, max(a - b, b))
  right = bisect.bisect_right(l, a + b - 1)

  #print(left, right)
  
  cs = right - left
  if left <= bisect.bisect_left(l, a) <= right:
    cs -= 1
  if left <= bisect.bisect_left(l, b) <= right:
    cs -= 1
  if cs > 0:
    cnt += cs

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
input()
L = sorted(map(int, input().split()))
D = [1 for a, b, c in itertools.combinations(L, 3) if a+b > c]
print(len(D))

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
    return sum(1 for a, b, c in combinations(L, 3) if a < b + c and b < c + a and c < a + b)

print number_of_triangles()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
#a,b = map(int,input().split())
a_L = list(map(int,input().split()))
counter = 0
for i in combinations(a_L,3):
    if abs(i[0]-i[1]) < i[2] and i[2] < i[0] + i[1]:
        counter += 1
    elif abs(i[1]-i[2]) < i[0] and i[0] < i[1] + i[2]:
        counter += 1
    elif abs(i[2]-i[0]) < i[1] and i[1] < i[2] + i[0]:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

count=0
list.sort(L, reverse=True)

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]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(_) for _ in input().split()]
ans = 0
L = [0 for _ in range(1,2000+1)]
s = [0 for _ in range(0,2000+1)]
for k in range(0, n):
    L[l[k]-1] += 1
for x in range(0,2000):
    s[x+1] = s[x] + L[x]

for i in range(0, n-1):
    for j in range(i+1, n):
        exc = 0
        m = abs(l[i] - l[j])
        M = l[i] + l[j]
        if l[i] > m:
            exc += 1
        if l[j] > m:
            exc += 1
        ans += s[M] - s[m] - L[M-1] - exc
print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

l.sort()

ans = 0

for i in range(1, n - 1):
  for j in range(i + 1, n):
    if l[i] * 2 > l[j]:
      idx = bisect.bisect_left(l, l[j] - l[i] + 0.5)
      ans += max(i - idx, 0)

print(ans)

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:
                break
            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:
import itertools

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


def calc(x, y, z):
    if x < y + z:
        if y < x + z:
            if z < y + x:
                return 1
    return 0

# def range_calc():


sum = 0
for i in itertools.combinations(list_, r=3):
    sum += calc(*i)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=[i for i in map(int,input().split())]
#print(L)
ans=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[0] + i[1] :
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

l.sort()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]+l[j] #短い二辺
        b = max(max(np.where(a>np.array(l))))
        cnt += max(0, b-j)

print(cnt)

Submission status: Time Limit Exceeded

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

#arr = [23, 6, 22, 3, 38, 15]
#n = sum(x>10 for x in arr)  # 真偽値リストを作って True の数を合計する方法
#n= sum(x>l[0]+l[1] for in l)

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

print(n)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
bou_list = list(map(int, input().split()))
triangle_list = list(itertools.combinations(bou_list,3))

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

total = 0
for i in triangle_list:
    a, b, c = i
    if triangle_check(a, b, c):
        total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:

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

r = [0]
def he( l, r):    
    s = []
    t = [0] * 3
    for i in range(len(l)):
        num = l[i]
        t[0] = num
        for j in range(i+1, len(l)):
            t[1] = l[j]
            for k in range(j + 1,  len(l)):
                t[2] = l[k]
                a, b, c = t[0], t[1], t[2]
                if a < b + c and b < a + c and c < b + a:
                    r[0] += 1

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = map(int,input().split())
tmp = list(itertools.combinations(L,3))
ans = 0
for i in range(len(tmp)):
    if abs(tmp[i][1] - tmp[i][2]) < tmp[i][0] < (tmp[i][1] + tmp[i][2]):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

preL = l[0]
l2 = []
l2Cnt = 1
for i in range(1,n):
	if preL == l[i]:
		l2Cnt += 1
	else:
		l2.append([l[i-1], l2Cnt])
		l2Cnt = 1
		preL = l[i]

l2.append([l[n-1], l2Cnt])

# print(l)
# print(l2)
n = len(l2)

# c-b < a
for i in range(n):
	a = l2[i][0]
	anum = l2[i][1]
	if anum >= 3:
		cnt += anum * (anum-1) * (anum-2) // 6

	for j in range(i+1,n):
		b = l2[j][0]
		if b < a: break
		bnum = l2[j][1]
		if bnum >= 3:
			cnt += bnum * (bnum-1) * (bnum-2) // 6
		if 2*a-b > 0 and anum >= 2:
			cnt += anum * (anum-1) // 2
		if 2*b-a > 0 and bnum >= 2:
			cnt += bnum * (bnum-1) // 2

		for k in range(j+1,n):
			c = l2[k][0]
			cnum = l2[k][1]

			# print(i, j, k)
			# print(a,b,c,anum,bnum,cnum)

			if cnum >= 3:
				cnt += cnum * (cnum-1) * (cnum-2) // 6
			if 2*a-c > 0 and anum >= 2:
				cnt += anum * (anum-1) // 2
			if 2*b-c > 0 and bnum >= 2:
				cnt += bnum * (bnum-1) // 2
			if 2*c-a > 0 and cnum >= 2:
				cnt += cnum * (cnum-1) // 2
			if 2*c-b > 0 and cnum >= 2:
				cnt += cnum * (cnum-1) // 2
			
			if c - b < a:
				cnt += l2[i][1] * l2[j][1] * l2[k][1]
			else:
				break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[0]*n
l[:]=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
      else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input())
l = list(map(int, input().split()))
 
cnt = 0
for i in range(n):
  a = l[i]
  for j, b in enumerate(l[i+1:]):
    for c in l[i+j+2:]:
      if (a < b+c) and (b < a+c) and (c <  a+b):
        cnt += 1
        
print(cnt)

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]):
                if (L[i]+L[j]>L[k]):
                    sum=sum+1
                else:
                    break
    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(map(int, input().split()))

L = sorted(L)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
N = int(input())
L = [int(_) for _ in input().split()]
 
result = 0
 
for subset in itertools.combinations(L, 3):
    if subset[0] < subset[1] + subset[2] and subset[1] < subset[2] + subset[0] and subset[2] < subset[0] + subset[1]:
        result += 1

print(result)

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(N-2):
    for j in range(i+1, N-1):
        ab_num = [i, j]
        #print(ab_num)
        for k in range(j+1, N):
            if k not in ab_num:
                if L[ab_num[0]] + L[ab_num[1]] > L[k]:
                    count += 1
                else:
                    break


print(count)

Submission status: Time Limit Exceeded

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

cnt = 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 a + b > c:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l.sort()
#print(l)
cnt=0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
count = 0
for i, li in enumerate(l_list):
    for j, lj in enumerate(l_list[i+1:], i+1):
        count += len([lk for lk in l_list[j+1:] if (li + lj > lk)])
print(count)

Submission status: Time Limit Exceeded

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            a, b = [l[i], l[j]]
            tl = [a + b, abs(a - b)]
            mi = min(tl) + 1
            ma = max(tl) - 1
            for k in range(i-1, -1, -1):
                #print(mi, ma, l[k])
                if l[k] < mi:
                    break
                elif mi <= l[k] <= ma:
                    ttl = sorted([i, j, k])
                    #print(ttl)
                    if (ttl[0], ttl[1], ttl[2]) not in d:
                        d[(ttl[0], ttl[1], ttl[2])]
                        cnt += 1
                    #print(ttl)
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Time Limit Exceeded

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

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

print(c)

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):
  j = N-2
  temp = 0
  while j > i:
    if temp > 0:
      k = temp
    else:
      k = N - 1
    while k > j:
      if L[i]-L[j]-L[k] < 0:
        ans += k-j
        temp = k
        break
      k -=1
    j -= 1
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted([int(i) for i in input().split()])
ans = 0
for i,l in enumerate(L):
    for ii,m in enumerate(L[i+1:-1]):
        for n in L[i+ii+2:]:
            if l + m <= n:
                break
            else:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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