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 itertools
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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

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

for l in ls:
    if sum(l) > max(l)*2:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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[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 = sorted(l, reverse = True)

ans = []
for i in range(len(l)-2):
    for j in range(len(l)-2-i):
        if l[i] > 2 * l[i+j+1]:
            break
        for k in range(len(l)-2-i-j):
            if l[i] < l[i+j+1] + l[i+j+k+2]:
                if [l[i], l[i+j+1], l[i+j+k+2]] not in ans:
                    ans.append([l[i], l[i+j+1], l[i+j+k+2]])
            else:
                break

print(len(ans))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int,input().split()))
count =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[k] + L[i] and L[k] < L[i] +L[j]:
                count += 1
                
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int , input().split()))
l = sorted(l, key=None, reverse=True)
ans = 0
for i in range(0, 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]:
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if check(Ls[i], Ls[j], Ls[k]):
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans =0

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

Submission status: Time Limit Exceeded

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

    L = sorted(L, 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

            ans += len([t for t in L[j+1::] if L[i] < (L[j]+t)])


    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
l = list(map(int, input().split()))
l.sort()
total = 0
result = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            total += 1
            if l[k] < l[i] + l[j]:
                result +=1
            else:
                break
print(result)

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)

s = 0
for i in range(N):
    o = []
    for j in range(i+1,N):
        for k in range(j+1,N):
            o.append(L[j]+L[k])
    o.sort()
    o = [0] + o + [3000]
    key = L[i]
    l = 0
    r = len(o)-1
    while r - l > 1:
        m = (r + l) // 2
        if o[m] > key:
            r = m
        else:
            l = m
    #print(key,o,l,len(o))
    s += len(o)-l-2

print(s)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ls_L = sorted(map(int, input().split()))
count = 0
for i, a in enumerate(ls_L[:-2]):
    for j, b in enumerate(ls_L[i+1:-1]):
        for c in ls_L[i+j+2:]:
            if abs(a - b) < c < a + b:
                count += 1
                if c >= a + b:
                    break
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

print(
    sum(
        int(
            cs[0] < (cs[1] + cs[2])
            and (cs[1] < cs[2] + cs[0])
            and (cs[2] < cs[0] + cs[1])
        )
        for cs in combinations(Ls, 3)
    )
)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

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

L.sort()
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[k]>L[j]-L[i] and L[k]<L[i]+L[j]:
                ans +=1
            elif L[k]>=L[i]+L[j]:
                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(0,n-2):
    for j in range(i+1,n-1):
        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)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = [int(l) for l 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[k]<L[i]+L[j]) and (L[i]<L[j]+L[k]) and (L[j]<L[k]+L[i]):
                total += 1
print(total)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            x, y, z = l[i], l[j], l[k]
            if x + y > z and x + z > y and y + z > x:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = sorted([int(item) for item in input().split(' ')])
count = 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]:
                count += 1
            else:
                break

print(count)

Submission status: Time Limit Exceeded

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

Ans=0

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

print(Ans)

Submission status: Time Limit Exceeded

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

lengthList = [0] * (10 ** 3)

for i in range(n) :
    lengthList[l[i] - 1] += 1

l = sorted(l)
ans = 0
beforeI = -1
beforeLj = -1
count = 0
#print(lengthList)
for i in range(n) :
    for j in range(i+1, n) :
        val = sum(lengthList[l[j]-1:l[i]+l[j]-1])
        if l[i] == l[j] :
            val -= 2
        else :
            val -= 1
        if beforeI == i and  beforeLj == l[j] :
            count += 1
        else :
            count = 0
        if val != 0 :
            val -= count
        #print(i,j,l[i],l[j], val)
        ans += val
        beforeI = i
        beforeLj = l[j]
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):
    for j in range(i+1, N):
        for k in range(j+1, N):
            A = L[i] < L[j] + L[k]
            B = L[j] < L[i] + L[k]
            C = L[k] < L[i] + L[j]
            if (L[i] < L[j] + L[k]) and (L[j] < L[i] + L[k]) and (L[k] < L[i] + L[j]):
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    for j in range(n):
        if i > j:
            for k in range(n):
                    if j > k:
                        if k != i and k != j:
#                             print(l_list[i], l_list[j], l_list[k])
                            if (l_list[i] < l_list[j] + l_list[k]) and (l_list[j] < l_list[i] + l_list[k]) and (l_list[k] < l_list[i] + l_list[j]):
                                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.append(0)
L.sort(reverse=True)
t=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]:
                t+=1

print(t)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import numpy as np
input = sys.stdin.readline


def main():
    n = int(input())
    l = list(map(int, input().split()))
    index = np.argsort(l)

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

    print(result)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

from itertools import combinations

ans = [1 for x in combinations(L, 3) if max(x) < sum(x)/2]

print(len(ans))

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# n = int(input())
# a, b = map(int, input().split())
# an = list(map(int, input().split()))

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

ln.sort(reverse=True)

bcs = []
for i in range(1, n-1):
  row = []
  for j in range(i+1, n):
    row.append(ln[i] + ln[j])
  bcs.append(row)

cnt = 0
ix = [0 for _ in range(n-2)]
# a > b,c
for i in range(n-2):
  a = ln[i]
  for j in range(i, n-2):
    try:
      while ix[j] < (n - 2 - j) and bcs[j][ ix[j] ] > a:
        ix[j] += 1
    except:
      print(j, ix[j])
      exit()
  cnt += sum(ix[i:])
print(cnt)

Submission status: Time Limit Exceeded

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

lsorted = sorted(l, reverse=True)

for longest in range(len(l)-2):

    for second in range(longest+1, len(l)):


        for k in range(second+1, len(l)):
            if lsorted[longest] - lsorted[second] - lsorted[k] >= 0:                
                break
            else:
                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())]
M=[]
ans=0
for i in itertools.permutations(L,3):
    X=list(i)
    X.sort()
    if X not in M :
        if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[0] + i[1] :
            ans += 1
            M.append(X)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if li[i] < li[j] + li[k]:
                if li[j] < li[k] + li[i]:
                    if li[k] < li[i] + li[j]:
                        total += 1

print(total)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

ans=0
for x,a in enumerate(L):
	for y,b in enumerate(L):
		for z,c in enumerate(L):
			if not x<y<z:
				continue
			elif a<b+c and b<c+a and c<a+b:
				ans+=1

print(int(ans))

Submission status: Time Limit Exceeded

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

L.sort()

ans = 0
b = 1
c = 2
while b < N-1:
  sub = L[c] - L[b]
  if L[b-1] <= sub:
    b += 1
    c = b + 1
  else:
    ans += 1
    for a in range(b-2, -1, -1):
      if L[a] > sub:
        ans += 1
      else:
        break
    c += 1
    if c >= N:
      b += 1
      c = b + 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, *l = map(int, open(0).read().split())
sl = 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):
      if sl[i]<sl[j]+sl[k] and sl[j]<sl[k]+sl[i] and sl[k]<sl[i]+sl[j]:
        ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort(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):
            hen = []
            hen.append(l[i])
            hen.append(l[i+j+1])
            hen.append(l[i+j+k+2])
            if hen[0] < hen[1] + hen[2]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = map(int, input().split())
sum = 0
tri = set(itertools.combinations(L, 3))
for t in tri:
    a, b, c = t
    if(a + b > c and b + c > a and c + a > b):
        sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

cnt = 0
for a in range(n):
    for b in range(a, n):
        for c in range(b, n):
            if l[c] <= l[a] - l[b]:
                break
            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()))
ans = 0
L.sort(reverse=True)
for i in range(len(L) - 2):
    a = L[i]
    for j in range(i + 1, len(L) - 1):
        b = L[j]
        flg = False
        flg2 = True
        for k in range(j + 1, len(L)):
            c = L[k]
            if a < b + c and b < c + a and c < a + b:
                flg = True
                flg2 = False
                ans += 1
            elif flg:
                break
        if flg2:
            break
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

cnt = 0

for i in range(len(edge)):
    if max(edge[i]) < sum(edge[i]) - max(edge[i]):
        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:
        return False
    elif b >= a + c:
        return False
    elif c >= a + b:
        return False
    return True

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()))
l.sort(reverse=True)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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
L.sort(reverse=True)
for l in itertools.combinations(L, r=3):
    a, b, c = l[0], l[1], l[2]
    if a >= 2*b:
        continue
    if a < b + c:
        if b < c + a:
            if c < a + b:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
_= input()
l = list(map(int,input().split()))
ans = 0
sp = itertools.combinations(l, 3)

for i in sp:
    tmp = sorted(i)

    if tmp[0] + tmp[1] > tmp[2]:
        ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(N):
  for j in range(N):
    for k in range(N):
      if i != j and j != k and k != i:
        if L[i] > L[j]:
          if L[k] > (L[i]-L[j]) and L[k] < (L[i]+L[j]):
            sum += 1
print(int(sum/3))

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7
from math import factorial
def comb(n,r):
    return factorial(n) // (factorial(r) * factorial(n - r))

n = INT()
l = MAP()

l.sort()
res=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]:
                res+=n-k
                break
        else:
            break


print(comb(n,3)-res)

Submission status: Time Limit Exceeded

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

res = 0

for i in range(N-2):
    L1 = L[i+1:]
    a = L[i]
    for j in range(len(L1)-1):
        L2 = L1[j+1:]
        b = L1[j]
        temp1 = max(L2)
        temp2 = min(L2)
        if temp2 >= a + b:
            break
        elif temp1 <= a - b:
            break
        elif temp1 <= b - a:
            break
        for k in range(len(L2)):
            c = L2[k]
            sum = a + b + c
            if (sum > 2*a) & (sum > 2*b) & (sum > 2*c):
                res += 1

print(res)

Submission status: Time Limit Exceeded

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

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

# solve
ans = 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[j] + L[i]:
                ans += 1

# output
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


ans=0
for com in list(itertools.combinations(l,3)):
    com=sorted(com)
    if com[2]<com[0]+com[1]:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

L = sorted(L)
# print(L)

ans = 0

# all_end = False
# next_a = False
# for a in range(N):
#     if all_end:
#         break
#     for b in range(a+1, N):
#         if next_a:
#             next_a = False
#             break
#         for c in range(N-1, b, -1):
#             print("{} {} {} / ans: {}".format(L[a], L[b], L[c], ans))
#             if L[a] + L[b] > L[c]:
#                 ans += 1
#             else:
#                 if c == N-1:
#                     next_a = True
#                     if b == a+1:
#                         all_end = True
#                 break

all_end = False
next_a = False
for a in range(N):
    # if all_end:
    #     break
    for b in range(a+1, N):
        if next_a:
            next_a = False
            break
        for c in range(b+1, N):
            # print("{} {} {} / ans: {}".format(L[a], L[b], L[c], ans))
            if L[a] + L[b] > L[c]:
                ans += 1
                if c == N-1:
                    next_a = True
                    ans += (N-b-2)*(N-b-1)//2
                    break
            else:
                # if c == b+1:
                #     next_a = True
                #     if b == a+1:
                #         all_end = True
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
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
        continue
      else:
        break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = sorted(l)

comb = list(itertools.combinations(l, 3))
count = 0
for i in range(len(comb)):
    a = comb[i][0]
    b = comb[i][1]
    c = comb[i][2]
    if a + b <= c:
        continue
    elif a + c <= b:
        continue
    elif b + c <= a:
        continue
    else:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
i=0
while i<n-2:
	j=i+1
	while j<n-1:
		k=j+1
		while k<n:
			if l[k]<l[i]+l[j]:
				ans=ans+1
			else:
				k=n
			k=k+1
		j=j+1
	i=i+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np

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

v=np.array([l[0], l[1]])
vsum=np.array([l[0]+l[1]])

c=0

for i in range(2, n):
    p=l[i]
    c+=np.sum(vsum>p)
    vsum = np.concatenate([vsum, v+p], 0)
    v=np.append(v, p)

print(c)

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] and L[k] + L[ab_num[1]] > L[ab_num[0]] and L[k] + L[ab_num[0]] > L[ab_num[1]]:
                    count += 1


print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N=int(input())
l1=list(map(int,input().split()))
l2=tuple(combinations(l1,2))
l3=[sum(i) for i in l2 if sum(i)<=max(l1)]
ans=len(tuple(combinations(l1,3)))
for i in l3:
  for j in l1:
    if i<=j:
      ans-=1
print(ans)

Submission status: Time Limit Exceeded

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

l.sort()

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if tmp < l[i] + l[j] < tmp:
            output += count
        else:
            count = 0
            for k in range(j + 1, n):
                if l[k] < l[i] + l[j]:
                    output += 1
                    count += 1

                else:
                    tmp = l[k]
                    break

print(output)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
num = []
ans = 0

for i in itertools.permutations(L, r=3):
    i = list(i)
    i.sort()
    if i not in num:
        num.append(i)

for i in range(len(num)):
    if num[i][0] + num[i][1] > num[i][2]:
        if num[i][1] + num[i][2] > num[i][0]:
            if num[i][0] + num[i][2] > num[i][1]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted(list(map(int, input().split())))
s = 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 c<a+b:
          s += 1
print(s)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list = input().split()
L = [int(n) for n in list]
L.sort()
sum = 0
for i in range(N):
  for j in range(N):
    if i > j:
      for k in range(N):
        if j > k:
          a = L[i]
          b = L[j]
          c = L[k]
          if (a<b+c) & (b<c+a) :
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

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

from itertools import combinations
print(len([True for a, b, c in combinations(l, 3) if (a < b + c and b < a + c and c < a + b)]))