Problem:


Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        sum = L[i] + L[j]

        for k in range(j+1, N):
            if sum > L[k]:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

L_MAX = 3000 + 7

N = int(input())
L = list(map(lambda x: int(x), input().split(" ")))
L = sorted(L)

cnt = np.array([0 for i in range(L_MAX)])
for i in range(N):
  cnt[L[i]] += 1

s = np.cumsum(cnt)

ans = 0
for _i in range(N*N):
  i = _i // N
  j = _i % N

  if i == j: continue

  a = L[i]
  b = L[j]

  c_min = abs(a-b)
  c_max = abs(a+b)

  add = s[c_max-1] - s[c_min]

  if c_min < a < c_max: add -= 1
  if c_min < b < c_max: add -= 1

  ans += add

print(ans // 6)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

L_MAX = 3000 + 7

N = int(input())
L = list(map(lambda x: int(x), input().split(" ")))
L = sorted(L)

cnt = np.array([0 for i in range(L_MAX)])
for i in range(N):
  cnt[L[i]] += 1

s = np.cumsum(cnt)

ans = 0
for i in range(N):
  for j in range(N):
    if i == j: continue

    a = L[i]
    b = L[j]

    c_min = abs(a-b)
    c_max = abs(a+b)

    add = s[c_max-1] - s[c_min]

    if c_min < a < c_max: add -= 1
    if c_min < b < c_max: add -= 1

    ans += add

print(ans // 6)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N = int(input())
L = list(map(int,input().split()))
L_1 = sorted(L)

ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
      A = bisect_left(L_1,L_1[i]+L_1[j])
      for k in range(j+1,A):
          if L_1[i]+L_1[j] > L_1[k]:
              ans += 1
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A=int(input())
L=input().split(' ')
L = [int(s) for s in L]

L.sort(reverse=True)
flag = 0

for i in range(A):
    for j in range(i+1,A):
        for k in range(j+1,A):
            if L[k]>L[i]-L[j]:
            	if L[j]<L[k]+L[i]:
		            flag += 1
print(flag)

Submission status: Time Limit Exceeded

Solution code:
#import random
import numpy as np

N=int(input())
Ln_d=list(map(int,input().split()))
Ln=np.array(Ln_d)

#for i in range(N):
#    Ln=np.append(Ln,[random.randint(1,1000)])

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

Ans=0
left=0
right=0
count=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break

        right=N-1
        left=dj
        while left<=right :
            count +=1
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)

print(Ans)

Submission status: Time Limit Exceeded

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

L=sorted(L)
counter=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]:counter+=1
print(counter)

Submission status: Time Limit Exceeded

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

import bisect
for i in range(N):
  for j in range(i+1,N-1):
    insert = bisect.bisect_left(L[j+1:],L[i]+L[j])
    cnt += insert
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = input().split()
L = [int(L[i]) for i in range(len(L))]
L.sort(reverse=True)
tri = 0
for i in range(N):
  for j in range(i+1,N):
    tri += len([k for k in range(j+1,N) if L[i]-L[j] < L[k] < L[j]])
    
print(tri)

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break

        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = input().split()
L = [int(L[i]) for i in range(len(L))]
L.sort(reverse=True)
tri = 0
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]:
        tri += 1
print(tri)

Submission status: Time Limit Exceeded

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

tri = 0
bar = [[L[i], L[j], L[k]] for i in range(N) for j in range(i+1,N) for k in range(j+1,N)]
for i in range(len(bar)):
  if bar[i][0] + bar[i][1] > bar[i][2]:
    if bar[i][0] + bar[i][2] > bar[i][1]:
      if bar[i][1] + bar[i][2] > bar[i][0]:
        tri += 1
print(tri)

Submission status: Time Limit Exceeded

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

tri = 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[i] + L[k]:
          if L[k] < L[i] + L[j]:
            tri += 1
print(tri)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def check_l3(l):
    
    if l[0] < l[1] + l[2] and l[1] < l[0] + l[2] and l[2] < l[1] + l[0]:
        return 1
    else:
        return 0
    
N = int(input())

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

L3 = []

i = 0
j = i + 1
k = j + 1

for i in range(N-2):
    for j in range(j,N-1):
        
        for k in range(k,N):
            l3 = [L[i],L[j],L[k]]
            if l3 not in L3:
                L3.append(l3)
            k = k + 1

        j = j + 1
        k = j + 1
    i = i + 1
    j = i + 1
    k = j + 1

# print(L3) #!!!!!!!

result = 0
for i in range(len(L3)):
    result += check_l3(L3[i])
print(result)

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(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l[j+1:], l[i] + l[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import bisect
n = int(input())
l = np.array(list(map(int, input().split())))
l = np.sort(l)
ans = 0

for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l[j+1:], l[i] + l[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        if (Ln[dj-1]+Ln[dj])<Ln[di-1] : break
        for k in range(N-dj):
            dk=dj+k+1
            a=Ln[di-1]
            b=Ln[dj-1]
            c=Ln[dk-1]
            if((b+c)>a)&((c+a)>b) :
                Ans +=1
            else : break

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        for k in range(N-dj):
            dk=dj+k+1
            a=Ln[di-1]
            b=Ln[dj-1]
            c=Ln[dk-1]
            if((a+b)>c)&((b+c)>a)&((c+a)>b) :
                Ans +=1

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
count = 0
for i in range(N-2):
    a = Ls[i]
    for k in range(i+1,N-1):
        ab = a + Ls[k]
        count += len(list(filter(lambda c: c<ab, Ls[k+1:N])))
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=input().split(" ")
count=0
for n,a in enumerate(L[:N-2]):
    a=int(a)
    for m,b in enumerate(L[n+1:N-1]):
        b=int(b)
        for c in L[m+n+2:N]:
            c=int(c)
            if a<b+c and b<a+c and c<b+a:
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=input().split(" ")
count=0
for n,a in enumerate(L[:N-2]):
    for m,b in enumerate(L[n+1:N-1]):
        for c in L[m+n+2:N]:
            if int(a)<int(b)+int(c) and int(b)<int(a)+int(c) and int(c)<int(b)+int(a):
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

def main():
    N = int(input())
    lst_L = list(map(int, input().split()))
    cmb_L = combinations(lst_L, 3)
    ans = sum(1 for cmb in cmb_L if (cmb[0] < cmb[1] + cmb[2]) and (cmb[1] < cmb[2] + cmb[0]) and (cmb[2] < cmb[0] + cmb[1]))

    print(ans)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=input().split(" ")
count=0
for a in range(0,N-2):
    for b in range(a+1,N-1):
        for c in range(b+1,N):
            if int(L[a])<int(L[b])+int(L[c]) and int(L[b])<int(L[a])+int(L[c]) and int(L[c])<int(L[b])+int(L[a]):
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
number = int(input())
list = list(map(int, input().split()))
ls = sorted(list)
count = 0

for a in range(0, number - 2):
    num_a = ls[a]
    for b in range(a + 1, number - 1):
        num_b = ls[b]
        for c in  range(b + 1, number):
            num_c = ls[c]
            if num_a + num_b > num_c:
                count += 1
            else:
                break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ls = list(map(int, input().split()))
count = 0
for i in range(N-2):
    a = Ls[i]
    for k in range(i+1,N-1):
        b = Ls[k]
        count = count + len(list(filter(lambda c: a+b>c and b+c>a and c+a>b, Ls[k+1:N])))
print(count)

Submission status: Time Limit Exceeded

Solution code:
number = int(input())
list = list(map(int, input().split()))
ls = sorted(list)
count = 0

for a in range(0, number - 2):
    num_a = ls[a]
    for b in range(a + 1, number - 1):
        num_b = ls[b]
        for c in  range(b + 1, number):
            num_c = ls[c]
            if num_a + num_b > num_c:
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if l[i] + l[j] <= l[k]:
        break
      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(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[k] > l[i] and l[k] + l[i] > l[j]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
t = [int(i) for i in input().split(" ")]
te = np.array(t) + np.array(t).reshape((-1,1)) - np.array([[[i for a in range(len(t))] for b in range(len(t))] for i in t])
tes = te>0
test = np.logical_and(tes, tes.transpose(1,2,0))
test = np.logical_and(test, tes.transpose(2,0,1))
test = np.tril(test,k=-1)
mask = np.array([[[False if i>=j or i<=k or j<=k else True for i in range(len(t))] for j in range(len(t))] for k in range(len(t)-1)])
print(np.sum(np.logical_and(test[:-1], mask)))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np
n = int(stdin.readline().rstrip())
le = np.array(list(map(int, stdin.readline().rstrip().split())))
res = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if le[i] < le[j] + le[k] and le[j] < le[i] + le[k] and le[k] < le[i] + le[j]:
                res += 1
print(res)

Submission status: Time Limit Exceeded

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

M = int(len(L))

I = []

for i in range(0,M):
    for j in range(0,M):
        for k in range(0,M):
            if L[i] < L[j]+L[k] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j] and i != j and j != k and k != i:
                I.extend([i])

if int(len(I)) == 0:
    n = 0
else:
    n = int(len(I))//6

print(n)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = sorted([int(i) for i in input().split(" ")])
te = [[t[a]+t[b] for b in range(a+1, len(t))] for a in range(len(t)-1)]
le = len(t)
co = 0
for a in range(le):
    for b in range(a+1, le):
        temp = te[a][b-a-1]
        for c in range(b+1, le):
            if t[c] < temp:
                co += t[a] < te[b][c-b-1] and t[b] < te[a][c-a-1]
            else:
                break
print(co)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = [int(i) for i in input().split(" ")]
te = [[t[a]+t[b] for b in range(a+1, len(t))] for a in range(len(t)-1)]
tes = [1 if te[a][b-a-1]>t[c] and te[b][c-b-1]>t[a] and te[a][c-a-1]>t[b] else 0 for a in range(len(t)) for b in range(a+1,len(t)) for c in range(b+1, len(t))]
print(sum(tes))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
t = [int(i) for i in input().split(" ")]
te = np.array(t) + np.array(t).reshape((-1,1))
tes = [1 if te[a,b]>t[c] and te[b,c]>t[a] and te[c,a]>t[b] else 0 for a in range(len(t)) for b in range(a+1,len(t)) for c in range(b+1, len(t))]
print(sum(tes))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
count = 0
for i in itertools.combinations(l, 3):
    if i[2] < i[1]+ i[0]:
        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):
    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(n - i - 2):
        b = l[i + j + 1]
        for k in range(n - i - j - 2):
            c = l[i + j + k + 2]
            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_list = list(map(int,input().split()))
l_list.sort(reverse=True)
count = 0
for a in range(n-2):
    x=0
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if (l_list[a]<l_list[b]+l_list[c]):
                count += 1
            else:
                if c==b+1 or c==b+2 or c==b+3:
                    x=1
                    break
        if x == 1:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for c in range(2,n):
    a = 0
    b = 1
    while True:
        if l[a]<l[b]+l[c] and  l[c]<l[a]+l[b] and l[b]<l[c]+l[a]:
            ans += 1
        b += 1
        if b == c:
            a += 1
            if a == c-1:
                break
            b = a+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort(reverse=True)
count = 0
for a in range(n):
    for b in range(a+1,n):
        for c in range(b+1,n):
            if (l_list[a]<l_list[b]+l_list[c]):
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(map(int,input().split()))
count = 0
for a in range(n):
    for b in range(a+1,n):
        for c in range(b+1,n):
            if (l_list[a]<l_list[b]+l_list[c]) and (l_list[b]<l_list[c]+l_list[a]) and (l_list[c]<l_list[a]+l_list[b]):
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys 
N=int(input())
L=list(map(int,sys.stdin.readline().split()))
counter=0
L.sort()
for i,A in enumerate(L[:-2]):
    for j,B in enumerate(L[i+1:-1],i+1):
        l=j
        r=len(L)-1
        c=(r+l)//2
        while abs(r-l)>1:    
            if A>abs(L[c]-B):
                b=c
                c=(r+c)//2
                l=b
            else:
                b=c
                c=(c+l)//2
                r=b
        if A-abs(L[l]-B)>0 and A-abs(L[r]-B)>0:
            c=r
        elif A-abs(L[l]-B)>0 and A-abs(L[r]-B)<0:
            c=l
        if A>abs(L[c]-B):
            counter+=c-j
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i in range(len(L)):
    for j in range(i+1,len(L)-1):
        l=j
        r=len(L)-1
        c=(r+l)//2
        while abs(r-l)>1:    
            if L[i]>abs(L[c]-L[j]):
                b=c
                c=(r+c)//2
                l=b
            else:
                b=c
                c=(c+l)//2
                r=b
        if L[i]-abs(L[l]-L[j])>0 and L[i]-abs(L[r]-L[j])>0:
            c=r
        elif L[i]-abs(L[l]-L[j])>0 and L[i]-abs(L[r]-L[j])<0:
            c=l
        if L[i]>abs(L[c]-L[j]):
            counter+=c-j
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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



N = int(input())

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

L3 = []

i = 0
j = i + 1
k = j + 1

for i in range(N-2):
    for j in range(j,N-1):
        
        for k in range(k,N):
            l3 = [L[i],L[j],L[k]]
            if l3 not in L3:
                L3.append(l3)
            k = k + 1

        j = j + 1
        k = j + 1
    i = i + 1
    j = i + 1
    k = j + 1

# print(L3) #!!!!!!!

result = 0
for i in range(len(L3)):
    result += check_l3(L3[i])
print(result)

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()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = bisect_right(L[j+1:], abs(l1-l2))
            e = bisect_left(L[j+1:], l1+l2)

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)

Submission status: Time Limit Exceeded

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

l.sort(reverse = 1)
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
R=list(map(int,input().split()))
L=sorted(R)[::-1]
s=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[k]>L[i]-L[j]:
				s+=1
			else:
				break
print(s)

Submission status: Time Limit Exceeded

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

cnt = 0

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

Submission status: Time Limit Exceeded

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

cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=min(bisect.bisect_left(l,p),i)-min(bisect.bisect_left(l,l[j]-l[i]+1),i)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=bisect.bisect_left(l[:i],p)-bisect.bisect_left(l[:i],l[j]-l[i]+1)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N=int(input())
l=list(map(int,input().split(" ")))

counter = 0
new_l = list(itertools.combinations(l,3))
for abc in new_l:
    a,b,c = abc
    if((a < b + c) and (b < c + a) and (c < a + b)):
        counter += 1     
print(int(counter))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split(" ")))
count = 0
for p in range(N):
    for q in range(N):
        if q == p:
            continue
        for r in range(N):
            if r == p or r == q:
                continue
            elif L[p] < L[q] + L[r] and L[q] < L[r] + L[p] and L[r] < L[p] + L[q]:
                count += 1
print(int(count/6))

Submission status: Time Limit Exceeded

Solution code:
#143d
import itertools

N = int(input())
L_list = [int(e) for e in input().split()]

ans = 0

for comb in itertools.combinations(L_list, 3):
    if comb[0]<comb[1]+comb[2] and comb[1]<comb[2]+comb[0] and comb[2]<comb[0]+comb[1]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools 
n = int(input())
l = list(map(int, input().split()))
l_group = list(itertools.combinations(l,3))
count = 0
for i in range(len(l_group)):
        if l_group[i][0]<l_group[i][1]+l_group[i][2] and l_group[i][1]<l_group[i][0]+l_group[i][2] and l_group[i][2]<l_group[i][0]+l_group[i][1]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
number_of_sticks = int(input())

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

sticks.sort()

# print(sticks)

triangles = 0

import bisect

for i in range (number_of_sticks - 2):
    for j in range (i+2, number_of_sticks):
        # print(sticks[i], sticks[j])
        # find number of sticks between range range sticks[j]-sticks[i], sticks[i] + sticks[j]
        # max_range = bisect.bisect_left(sticks, sticks[i] + sticks[j]) - 1
        max_range = j
        min_range = max(bisect.bisect(sticks, sticks[j] - sticks[i]), i + 1)
        # print("max range: " + str(max_range))
        # print("min range: " + str(min_range))
        triangles += max(0, max_range - min_range)

print(triangles)

Submission status: Time Limit Exceeded

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

cnt = 0
for first in range(N):
    for second in range(first+1,N):
        for third in range(second+1,N):
            if L[third] < L[first] + L[second]:
                cnt += 1
                # print(L[first],L[second],L[third])

print(cnt)

Submission status: Time Limit Exceeded

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

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

L.sort(reverse=True)

#print(L)
for i in range(N):
    L[i] *= -1
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if -L[i] >= -L[j] * 2:
            break
        data = L[i] - L[j]
        #print(data, L[j + 1 : N])
        #print(bisect.bisect_left(L[j + 1 : N], data))
        count += bisect.bisect_left(L[j + 1 : N], data)

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def U(a, n):
    l,h=-1,len(a)
    while h-l>1:
        m=(h+l)//2
        if a[m]>n:h=m
        else:l=m
    return h

n, *l = map(int, open(0).read().split());l.sort()
print(sum([sum([max(0, j-U(l,l[i]-l[j]))for j in range(1,i)])for i in range(2,n)]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
count = 0
l.sort()
print(l)
'''
def binary_search(key,l,n):
    key_number = int((n-1)//2)
    L = 0
    R = n-1
    while True:
        if l[key_number] < key:
            L = key_number
            key_number = (L+R)//2
        else:
            R = key_number
            key_number = (L+R)//2
        if key == l[key_number]:
            return key_number
        if (R-L) == 1:
            return L+1
'''
def binary_search(key,l,n):
    L = 0
    R = n-1
    while L < R:
        key_number = int((n-1)//2)
        if l[key_number] < key:
            L = key_number + 1
        else:
            R = key_number
    return key_number

for i in range(n-2):
    for j in range(i+1,n-1):
        double_count = 0
        a = l[i]
        b = l[j]
        key_numberR = binary_search(a+b,l,n)
        key_numberL = binary_search(b-a,l,n)
        print("{} <c< {} b-a = {} a+b = {}".format(key_numberL,key_numberR,b-a,a+b))

        if key_numberL<= i and i<=key_numberR:
            double_count += 1
        if key_numberL<= j and j <= key_numberR:
            double_count += 1

        #print('i={} j={} key_numberL={} key_numberR={} count={}'.format(i,j,key_numberL,key_numberR,-key_numberL-double_count))
        count += key_numberR-key_numberL-double_count
print(count)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for b in range(1, N - 1):
    for a in range(b):
        ans += bisect_left(L[b + 1:], L[a] + L[b])
        
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

x=0

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N = int(input())
L = [int(x) for x in input().split()]
L.sort()
ans = 0
for a in range(N-2):
    for b in range(a+1, N-1):
        ans += bisect_left(L[b+1:], L[a]+L[b])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

l = list(map(int,input().split()))
l.sort()
ans = [1 for a in range(n-2) for b in range(a+1,n-1) for c in range(b+1,n) if l[a]+l[b]>l[c] and l[b]+l[c]>l[a] and l[c]+l[b]>l[a]]
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = input()
L = [int(x) for x in input().split()]
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)