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 numpy as np

N = int(input())
A = np.sort(list(map(int,input().split())))[::-1]
ans = 0
i = 0
while i < N-2:
    j = i+1
    while j < N-1:
        a = A[i]
        b = A[j]
        C = A[j+1:]
        J = (C>a-b)
        if (np.any(J)):
            ans += np.size(C[J])
        j += 1
    i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.sort(list(map(int,input().split())))[::-1]
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        a = A[i]
        b = A[j]
        C = A[j+1:]
        J = (C>a-b)
        if (np.any(J)):
            ans += np.size(C[J])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.sort(list(map(int,input().split())))[::-1]
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        a = A[i]
        b = A[j]
        C = A[j+1:]
        J = (C<a+b) * (C>a-b)
        if (np.any(J)):
            ans += np.size(C[J])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
out = 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]:
        out += 1
      else:
        break
print(out)

Submission status: Time Limit Exceeded

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

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

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

print(count)

Submission status: Time Limit Exceeded

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

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

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L = list(map(int,input().split()))
L.sort()
p=0
for i in range(N-1,1,-1):
  #print("ii",i)
  for j in range(i-1,0,-1):
    #print("j",j)
    for k in range(j):
      #print("k",k)
      if L[i]<(L[j]+L[k]):
        break
      else:
        p=p+1
print(N*(N-1)*(N-2)//6-p)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L = [int(n) for n in input().split()]
L.sort()
p=0
for i in range(N-1,1,-1):
  #print("ii",i)
  for j in range(i-1,0,-1):
    #print("j",j)
    for k in range(j):
      #print("k",k)
      if L[i]>=(L[j]+L[k]):
        #print(i,j,k)
        p=p+1
      else:
        break
print(N*(N-1)*(N-2)//6-p)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L = [int(n) for n in input().split()]
L.sort()
p=0
for i in range(N-1,1,-1):
  #print("ii",i)
  for j in range(i-1,0,-1):
    #print("j",j)
    for k in range(j):
      #print("k",k)
      if L[i]>=(L[j]+L[k]):
        #print(i,j,k)
        p=p+1
      else:
        continue
print(N*(N-1)*(N-2)//6-p)

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]:
                if L[j] < L[i] + L[k]:
                    if L[k] < L[i] + L[j]:
                        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import itertools
N=int(input())
L=list(map(int,input().split()))
ans=0
l=list(itertools.combinations(L,3))
#print(max(l[0]))
kumi=len(l)
for i in range(kumi):
    l[i]=list(l[i])
    a=max(l[i])
    l[i].remove(a)
    if a<sum(l[i]):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
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):
            l=[L[i],L[j],L[k]]
            #print(l)
            m=max(l)
            l.remove(m)
            if m<sum(l):
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for ai in range(N-2):
        a = L[ai]
        for bi in range(ai+1,N-1):
            b = L[bi]
            cleft = max((a - b), (b - a))
            cright = a + b
            left_index = bisect.bisect_left(L[bi+1:],cleft)
            right_index = bisect.bisect_left(L[bi+1:],cright)
            if left_index == right_index:
                if L[bi+1+left_index] < cright:
                    ans += 1
            else:
                ans += (right_index - left_index)
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
*l, = sorted(map(int, input().split()))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
ans = 0
for i in range(n):
	    for j in range(i+1,n):
	    	    bottom  = j
	    	    top = n
	    	    while top -bottom > 1:
	    	    	    middle = (top+bottom)//2
	    	    	    if l[middle] <l[i]+l[j]:
	    	    	    	    bottom = middle
	    	    	    else:
	    	    	    	    top = middle
	    	    ans += bottom - j 
print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
ls = [int(i) for i in input().split(" ")]

ls = sorted(ls)

n_triangle = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            
            if ls[k] < ls[i]+ls[j]:
                n_triangle += 1
            else:
                break
print(n_triangle)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [i for i in map(int,input().split())]
L.sort()

import bisect
ans = 0
for i in range(1,N):
  for j in range(i):
    index = bisect.bisect_left(L,L[i]+L[j])
    if index <= i+1:
      continue
    ans += len(L[i+1:index])
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted(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]:
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
s = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    k_max = n-1
    k_min = j
    while k_min!=k_max:
      k = (k_max+k_min)//2+1
      if l[k] < l[i] + l[j]:
        k_min = k
      else:
        k_max = k-1
    s += k_min - j
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def binary_search(arr, low, high, x):
    while low < high:
        mid = (low + high) // 2
        if arr[mid] < x: low = mid+1
        else: high = mid

    return low


def rec_binary_search(arr, l, r, x):
    if r-l <= 0:
        return l
    
    else:
        mid = (l + r) // 2
        if arr[mid] == x:
            return mid
    
        elif arr[mid] > x:
            return binary_search(arr, l, mid-1, x)

        else:
            return binary_search(arr, mid+1, r, x)

ll.sort()
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        c = ll[i] + ll[j]
        limit = binary_search(ll, j+1, n, c)
        ans += limit - j - 1

print(ans)

Submission status: Time Limit Exceeded

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

ll.sort()

def binary_search(arr, l, r, x):
    if r-l <= 0:
        return l
    
    else:
        mid = (l + r) // 2
        if arr[mid] == x:
            return mid
    
        elif arr[mid] > x:
            return binary_search(arr, l, mid-1, x)

        else:
            return binary_search(arr, mid+1, r, x)

ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        c = ll[i] + ll[j]
        limit = binary_search(ll, j+1, n, c)
        ans += limit - j - 1

print(ans)

Submission status: Time Limit Exceeded

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

ll.sort()

def binary_search(arr, l, r, x):
    if r-l >= 1:
        mid = (l + r) // 2
        if arr[mid] == x:
            return mid
    
        elif arr[mid] > x:
            return binary_search(arr, l, mid-1, x)

        else:
            return binary_search(arr, mid+1, r, x)

    else:
        return l


ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        a = ll[i]
        b = ll[j]
        c = a + b
        limit = binary_search(ll, j+1, n, c)
        ans += max(limit - j - 1, 0)

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

def bsearch(l,n,k):
    ok = -1
    ng = n

    while ng-ok>1:
        mid = (ng+ok)//2
        if l[mid]<k:
            ok = mid
        else:
            ng = mid
    return ok

def f(l):
    n = len(l)
    l.sort()

    res = 0
    for i in range(n-1):
        for j in range(i+1,n):
            k = bsearch(l,n,l[i]+l[j])
            res += k-j

    return res

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

Submission status: Time Limit Exceeded

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

import itertools

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

  if a and b and c:
    cnt += 1

print(cnt)

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 - 2):
    L_i = L[i]
    for j in range(i + 1, N - 1):
        L_j = L[j]
        x_left = abs(L_i - L_j)
        x_right = L_i + L_j
        x = bisect.bisect_left(L, x_right) - max(j + 1,bisect.bisect_right(L, x_left))
        ans += x
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse = True)
ans = 0
for i in range(N):
    L_i = L[i]
    for j in range(i + 1, N):
        L_j = L[j]
        L_ipj = L_i + L_j
        L_imj = L_i - L_j
        for k in range(j + 1, N):
            L_k = L[k]
            if L_imj >= L_k or 0 >= L_imj + L_k or L_k >= L_ipj:
                break
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse = True)
ans = 0
for i in range(N):
    L_i = L[i]
    for j in range(i + 1, N):
        L_j = L[j]
        for k in range(j + 1, N):
            L_k = L[k]
            if L_i >= L_j + L_k or L_j >= L_i + L_k or L_k >= L_j + L_i:
                break
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = 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 li[i] < li[j] + li[k] and li[j] < li[k] + li[i] and li[k] < li[i] + li[j]:
                # print(li[i], li[j], li[k])
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lp = j+1
        rp = n-1
        while lp < rp:
            mp = (lp+rp)//2
            if l[mp] < l[i] + l[j]:
                lp = mp+1
            else:
                rp = mp-1
        if l[lp] < l[i] + l[j]:
            ans += lp-j
        else:
            ans += lp-j-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in 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]:
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
def check(a, b, c):
    return (a < b + c) and (b < a + c) and (c < a + b)
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        for k in range(j+1, N):
            c = L[k]
            if check(a, b, c):
                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):
    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
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# ABC-143-D
#尺取り方でやってみる。
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0

for a in range(0, N-2):
    for b in range(a+1, N-1):
        tmp = L[a]+L[b]
        i = b + 1
        while i < N and L[i] < tmp:
            ans += 1
            i += 1
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = itertools.combinations(L,3)
count = 0
for a,b,c in l:

    if a<b+c and b<c+a and c<a+b:
        count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# ABC-143-D
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0

def binary_search(j, a_plus_b):
    left = j + 1
    right = N-1
    while right-left > 1:
        tmp = (left+right)//2
        if L[tmp] < a_plus_b:
            left = tmp
        else:
            right = tmp
    if L[(left+right)//2] >= a_plus_b:
        return j
    else:
        return (left+right)//2

for i in range(0, N-2):
    for j in range(i+1, N-1):
        a_plus_b = L[i] + L[j]
        #この部分をbinary_search関数でうまくできないかもっと考えたい
        if a_plus_b > L[-1]:
            ans += N - (j + 1)
        else:
            ans += binary_search(j, a_plus_b) - j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

L.sort()

for i in range(n-2):
    for j in range(i+1, n):
        c = L[i]+L[j]
        l = j
        r = bisect.bisect_left(L, c, lo=l) -1
        ans += (r-l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def sort_list():
    _ = input()
    K = [int(x) for x in input().split()]
    ans = 0
    n_lst = tuple(sorted(K, reverse=True))
    for idx in range(len(K)-2):
        for diff_idx in range(idx+1, len(K)-1):
            diff = n_lst[idx] - n_lst[diff_idx]
            for search in reversed(range(diff_idx+1, len(K))):
                if n_lst[search] > diff:
                    ans += search - diff_idx
                    break
    print(ans)


if __name__ == "__main__":
    sort_list()

Submission status: Time Limit Exceeded

Solution code:
def sort_list():
    _ = input()
    K = [int(x) for x in input().split()]
    ans = 0
    n_lst = tuple(sorted(K, reverse=True))
    for idx in range(len(K)-2):
        for diff_idx in range(idx+1, len(K)-1):
            diff = n_lst[idx] - n_lst[diff_idx]
            for search in range(diff_idx+1, len(K)):
                if n_lst[search] <= diff:
                    search -= 1
                    break
            ans += search - diff_idx
    print(ans)


if __name__ == "__main__":
    sort_list()

Submission status: Time Limit Exceeded

Solution code:
def sort_list(list_n):
    ans = 0
    n_lst = sorted(list_n, reverse=True)
    for idx in range(len(list_n)-2):
        for diff_idx in range(idx+1, len(list_n)-1):
            diff = n_lst[idx] - n_lst[diff_idx]
            for search in range(diff_idx+1, len(list_n)):
                if n_lst[search] <= diff:
                    search -= 1
                    break
            conbo = search - diff_idx
            ans += conbo
    return ans


def main():
    _ = input()
    K = [int(x) for x in input().split()]
    ans = sort_list(K)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

s = 0
for i, di in enumerate(d):
    d2 = d[i+1:]
    for j, dj in enumerate(d2):
        d3 = d2[j+1:]
        for dk in d3:
            if (di < dj + dk) and (dj < di + dk) and (dk < di + dj):
                s += 1

print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


N = int(input())
L = list(map(int,input().split()))
L.sort()
L = np.array(L)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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


def binarysearch(lista,b):
    left=0
    right=len(lista)
    while left<right:
        mid=(left+right)//2
        if lista[mid]>=b:
            right=mid
        else:
            left=mid+1
            mid+=1
    return mid

ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=(binarysearch(l,l[i]+l[j])-(j+1))
print(ans)

Submission status: Time Limit Exceeded

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


def binarysearch(lista,b):
    left=0
    right=len(lista)
    while left<right:
        mid=(left+right)//2
        if lista[mid]>=b:
            right=mid
        else:
            left=mid+1
            mid+=1
    return mid

ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=(binarysearch(l,l[i]+l[j])-(j+1))
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
L_list = list(map(int, input().split()))
L_comb = list(combinations(L_list, 3)) # 3辺のすべての組み合わせ

cnt = 0

for c in L_comb:
    a = c[0]
    b = c[1]
    c = c[2]
    if (a < b + c) & (b < a + c) & (c < a + b):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

import bisect

ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    temp=[l[k] for k in range(j+1,n) if k!=i and k!=j]
    ind=bisect.bisect_left(temp,abs(l[i]+l[j]))
    ans+=ind
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] 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 = sorted(list(map(int,input().split())))
table = [[0 for _ in range(N)] for _ in range(N)]
ans = 0
for i in range(1,N-1):
  for j in range(i):
    for k in range(i+1,N):
      if L[i]+L[j]<=L[k]:break 
      elif 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 = sorted(list(map(int,input().split())))
table = [[0 for _ in range(N)] for _ in range(N)]
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]:break 
      elif 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 = sorted(list(map(int,input().split())))
table = [[0 for _ in range(N)] for _ in range(N)]
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:

from bisect import bisect_right
N = int(input())
L = sorted(list(map(int,input().split())))
count = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ma = bisect_right(L[j+1:], L[i] + L[j] -1)
        if ma >= 0:
            count += ma
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect
N = int(input())
L = sorted(list(map(int,input().split())))
count = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ma = bisect.bisect_right(L[j+1:], L[i] + L[j] -1)
        if ma >= 0:
            count += ma
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect
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):
        ma = bisect.bisect_right(L[j+1:], L[i] + L[j] -1)
        if ma >= 0:
            count += ma
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect
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):
        maxi = L[i] + L[j] -1
        #mini = abs(L[i] - L[j]) +1
        # mi = bisect.bisect_left(L[j+1:],mini)
        ma = bisect.bisect_right(L[j+1:], maxi)
        #print("mi"+str(mi)+"ma"+str(ma))
        if ma >= 0:
            count += ma
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect
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):
        #print(L[i])
        #print(L[j])
        maxi = L[i] + L[j] -1
        mini = abs(L[i] - L[j]) +1
        #print("maxi"+str(maxi)+"mini"+str(mini))
        #cL = copy.copy(L)
        #del cL[:j+1]
        #print(cL)
        mi = bisect.bisect_left(L[j+1:],mini)
        ma = bisect.bisect_right(L[j+1:], maxi)
        #print("mi"+str(mi)+"ma"+str(ma))
        if ma >= mi:
            count += ma-mi
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect
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):
        #print(L[i])
        #print(L[j])
        maxi = L[i] + L[j] -1
        mini = abs(L[i] - L[j]) +1
        #print("maxi"+str(maxi)+"mini"+str(mini))
        cL = copy.copy(L)
        del cL[:j+1]
        #print(cL)
        mi = bisect.bisect_left(cL,mini)
        ma = bisect.bisect_right(cL, maxi)
        #print("mi"+str(mi)+"ma"+str(ma))
        if ma >= mi:
            count += ma-mi
print(count)

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

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

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] 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())
L = list(map(int, input().split()))
L.sort(reverse=True)
sumnum = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for q in range(j+1,N):
            if L[i]<L[j]+L[q]:
                sumnum += 1
print(sumnum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
sumnum = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for q in range(j+1,N):
            if L[i]+L[j]+L[q]-max(L[i],L[j],L[q])>max(L[i],L[j],L[q]):
                sumnum += 1
print(sumnum)

Submission status: Time Limit Exceeded

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

count = 0

for i in range(N - 2):
    a = lengths[i]
    for j in range(i + 1, N - 1):
        b = lengths[j]
        
        L, R = j, N
        while R - L > 1:
            C = (L + R) // 2
            c = lengths[C]
            if c < a + b:
                L = C
            else:
                R = C
        
        count += L - j

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0
# a <= b <= c

for b in range(1,N-1):
  for c in range(b+1,N):
    # search min(c) with a + b > c <=> a > c - b
    idx = bisect.bisect_left(L[:b],L[c]-L[b]+1)
    #print(L[b],L[c],idx)
    ans += max(b-idx,0) if idx >= 0 else 0 
    #print(idx, ans)
#print(L)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
count = 0
for i in range(0,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 < a+c and c < a+b:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
import operator as op
from functools import reduce

import numpy as np
import math
import bisect


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

    L.sort()
    # M = [L[i] + L[j] for i in range(N) for j in range(i+1, N)]
    # M.sort()

    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            a = L[i]
            b = L[j]

            # l = bisect.bisect_right(L[j+1:], abs(a-b))
            l = 0
            # print(l)

            # Speed up
            if L[j+1] > a + b:
                r = -1
            elif L[-1] < a + b:
                r = len(L[j+1:]) - 1
            else:
                r = bisect.bisect_left(L[j+1:], a+b)-1
            # candidates: [l, r]

            ans += max(0, r - l + 1)

    print(ans)


if __name__ == '__main__':
    main()