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

count=0
l=sorted(L)

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



print(count)

Submission status: Time Limit Exceeded

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

count=0
l=sorted(L,reverse=True)

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



print(count)

Submission status: Time Limit Exceeded

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

count=0
L.sort()
A=list(it.combinations(L,3))

for a in A:
    if a[2]<a[0]+a[1]:
        count+=1

print(count)

Submission status: Time Limit Exceeded

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

ld={}
for i in range(n):
    ld.setdefault(i,l[i])

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

ld={}
for i in range(n):
    ld.setdefault(i,l[i])

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

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
flag = 0
ma = 2

for left1 in range(N-2):
    for left2 in range(left1+1, N-1):
        ma = left2 +1
        for right in range(max(ma, left2+1), N):
            a = L[right] - ( L[left1] + L[left2])
            if a < 0:
                flag = 1
                if right == N-1:
                    ans += right - left2
                    break
            if a >= 0:
                ma = right - 1
                if flag == 1:
                    ans += right - left2 - 1
                    flag = 0
                break
print(ans)

Submission status: Time Limit Exceeded

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


ans = 0
flag = 0
ma = 2

for left1 in range(N-2):
    for left2 in range(left1+1, N-1):
        ma = left2 +1
        for right in range(max(ma, left2+1), N):
            if L[right] < L[left1] + L[left2]:
                flag = 1
                ma = right
                if right == N-1:
                    ans += right - left2
                    break
            if L[right] >= L[left1] + L[left2] or right == N-1:
                if flag == 1:
                    ans += right - left2 - 1
                    flag = 0
                break
print(ans)

Submission status: Time Limit Exceeded

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


ans = 0

for left1 in range(N-2):
    for left2 in range(left1+1, N-1):
        for right in range(left2+1, N):
            if L[right] < L[left1] + L[left2]:
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

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

L_sorted = sorted(L)

def bis(left, right, SrcList, value):
    if SrcList[left] >= value:
        return -1 # no results
    elif SrcList[right] < value:
        return -2 # all results
    while (left + 1 < right):
        mid = (left + right) // 2
        if SrcList[mid] < value:
            left = mid
        else:
            right = mid
    return left


count = 0
for i in range(0, N-2):
    for j in range(i+1,N-1):
        r = bis(j+1, N-1, L_sorted, L_sorted[i] + L_sorted[j])
        if r == -1:
            pass
        elif r == -2:
            count += ((N-j) * (N-j-1))//2
            break
        else:
            count += r-j
        

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
ll=list(map(int, input().split()))
ll=np.array(sorted(ll))

  
ans=0
for i in range(len(ll)-1):
  for j  in range(i+1,len(ll)):
    tmp=ll[j+1:]
    ans+=len(tmp[tmp<(ll[i]+ll[j])])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ll=list(map(int, input().split()))
ll=sorted(ll)
def f(a,b):
  l=a
  r=len(ll)
  x=0
  while l+1<r:
    x=(l+r)//2
    if ll[x]<b:
      l=x
    else:
      r=x
  return len(ll[a+1:r])
  
ans=0
for i in range(len(ll)-1):
  for j  in range(i+1,len(ll)):
    ans+=f(j,ll[i]+ll[j])
print(ans)

Submission status: Time Limit Exceeded

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

L_sorted = sorted(L)

count = 0
for i in range(0, N):
    for j in range(i+1,N):
        for k in range(j+1, N):
            if L_sorted[i] + L_sorted[j] > L_sorted[k]:
                count += 1
            else:
                break

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


def is_triangle(perm):
    (a, b, c) = perm
    return a + b > c and a + c > b and b + c > a


n = int(input())
sticks = list (map (int, input().strip().split()))

perms = combinations(sticks, 3)

triangles = []

for perm in list(perms):
    if is_triangle(perm):
        triangles.append(perm)
        
print(len(triangles))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())

t = list(map(int,input().split()))

count = 0

for x, y, z in itertools.combinations(t, 3):
    if x+y>z and y+z>x and z+x>y:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

L = sorted(L, reverse = True)

comb = itertools.combinations(L, 3)

count = 0

for item in comb:
#    print(item)
    if item[0] < item[1] + item[2]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
L = np.array(list(map(int, input().split())))

L_s = np.sort(L)

count = 0
for i in range(0, N-2):
    Low = L_s[i]
    for j in range(i+1, N-1):
        Mid = L_s[j]
        num = np.argmax(L_s>=(Low+Mid))
        if num !=0:
            count = count + num - j - 1
        else:
            count = count + N - j - 1
print(count)

Submission status: Time Limit Exceeded

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

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

print(c)

Submission status: Time Limit Exceeded

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

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
read=sys.stdin.buffer.readline

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

L.sort()

def binary_tree(data,l_index,value):
    left=l_index
    right=N-2
    while left<=right:
        mid=(left+right)//2
        if data[mid]>=value and data[mid-1]<value:
            return mid-1
        elif data[mid]<value:
            left=mid+1
        else:
            right=mid-1
    if data[-1]<value:
        return N-1
    return -1

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        x=binary_tree(L,j+1,L[i]+L[j])
        if x!=-1:
            ans+=(x-j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
L = list(map(int,input().split()))
L.sort()
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            if st > L[j+1]:
                m2 = 0
            else:
                m2 = bisect_right(L[j+1:],st)
            c += max(0,m1-m2)
print (c)

Submission status: Time Limit Exceeded

Solution code:
import math
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
L = list(map(int,input().split()))
L.sort()
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            m1 = bisect_right(L[j+1:],lg)
            m2 = bisect_left(L[j+1:],st)
            c += max(0,m1-m2)
print (c)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
L = list(map(int,input().split()))
L.sort()
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lg = L[i] + L[j] - 0.5
        st = L[j] - L[i] + 0.5
        m2 = bisect_left(L[j+1:],st)
        m1 = bisect_right(L[j+1:],lg)
        c += max(0,m1-m2)
print (c)

Submission status: Time Limit Exceeded

Solution code:
import math
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
L = list(map(int,input().split()))
L.sort()
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lg = L[i] + L[j] - 0.5
        st = L[j] - L[i] + 0.5
        m2 = bisect_left(L[j+1:],st)
        m1 = bisect_right(L[j+1:],lg)
        c += max(0,m1-m2)
print (c)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
L = list(map(int,input().split()))
L.sort()
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lg = L[i] + L[j]
        st = L[j] - L[i]

        BL = j + 1
        BH = n - 1

        if L[BL] >= lg or L[BH] <= st:
            continue

        if L[BH] < lg:
            m1 = BH
        else:
            m1 = math.ceil((BL + BH) / 2)
            while True:
                if L[m1] >= lg:
                    BH = m1 - 1
                else:
                    BL = m1
                if BH <= BL:
                    m1 = BH
                    break
                m1 = math.ceil((BH + BL)/2)

        BL = j + 1
        BH = n - 1
        if L[BL] > st:
            m2 = BL
        else:
            m2 = (BL + BH) // 2
            while True:
                if L[m2] <= st:
                    BL = m2 + 1
                else:
                    BH = m2
                if BH <= BL:
                    m2 = BL
                    break
                m2 = (BH + BL) // 2

        c += max(0,m1-m2+1)


print (c)

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        a, b = x[i], x[j]
        left, right = j + 1, n
        while right - left > 1:
            k = (left + right) // 2
            if a < b + x[k]:
                left = k
            else:
                right = k
        if a < b + x[left]:
            ans += (left - j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import bisect
    N = int(input())
    L = sorted([int(x) for x in input().split()])

    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            a = L[i]
            b = L[j]
            hi = bisect.bisect_left(L, a+b, lo=j+1)
            ans += hi - j - 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import bisect
    N = int(input())
    L = sorted([int(x) for x in input().split()])

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            a = L[i]
            b = L[j]
            lo = bisect.bisect_right(L, b-a, lo=j+1)
            # print(i, j, a, b, L[lo])
            # if lo <= j:
            #     continue
            hi = bisect.bisect_left(L, a+b, lo=j+1)
            ans += (hi - lo)
            # print(a, b, L[lo:hi])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import bisect
    N = int(input())
    L = sorted([int(x) for x in input().split()])

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            a = L[i]
            b = L[j]
            lo = bisect.bisect_right(L, b-a, lo=j+1)
            # print(i, j, a, b, L[lo])
            if lo <= j:
                continue
            hi = bisect.bisect_left(L, a+b)
            ans += (hi - lo)
            # print(a, b, L[lo:hi])
    print(ans)


if __name__ == '__main__':
    main()

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):
    l, r = j, N - 1
    while r - l >= 1:
      if (r - l) % 2 == 0:
        pt = (r + l) // 2
      else:
        pt = (r + l + 1) // 2
      if L[i] + L[j] > L[pt]:
        cnt += pt - l
        l = pt
      else:
        r = pt - 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i, a in enumerate(L[:N-2]):
  for j, b in enumerate(L[i+1:N-1]):
    over_index = bisect_left(L[i+j+2:],a+b)
    ans += over_index
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import itertools

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

ans = 0
for c in C:
  if c[0]<c[1]+c[2] and c[1]<c[0]+c[2] and c[2]<c[0]+c[1]:
    ans +=1
    
print(ans)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

print( cnt )

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arrl = list(map(int,input().split()))
import itertools
count = 0
for i in itertools.combinations(arrl,3):
    i = list(i)
    i.sort()
    if i[0] + i[1] > i[2]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

for x,y,z in itertools.combinations(l,3):
  lt = sorted([x,y,z])
  if lt[2] < lt[0] + lt[1]:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

for x,y,z in itertools.combinations(l,3):
  if x+y >z and y+z >x and z+x >y:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

#a<=b<=c とする
#a,b 固定
#cf : http://drken1215.hatenablog.com/entry/2019/10/20/032700
for i in range(N):
 for j in range(i,N):
   if(i != j):
    a,b = L[i],L[j]
    a_plus_b = a+b
    k = bisect.bisect_left(L,a+b)
    tmp = max(0, k-(j+1))
    count += tmp
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
 
ans = 0
for i in range(0, N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        if L[-1] > a - b:
            ans += len(L[j+1:])
        else:
            for k in range(j+1, N):
                c = L[k]
                if c > a - b:
                    ans += 1
                else:
                    break
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(0, 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:
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

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

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

cnt = 0
l = list(itertools.combinations(range(N),2))
for i1,i2 in l:
  a,b = L[i1],L[i2]
  if a == b:
    ib = bisect.bisect_right(L, b)
    ic = bisect.bisect_right(L, a+b)
  else:
    ib = bisect.bisect_left(L, b)
    ic = bisect.bisect_left(L, a+b)
  if ic - ib >=1:
    cnt += ic - ib -1
print(cnt)

Submission status: Time Limit Exceeded

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

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

cnt = 0
l = list(itertools.combinations(range(N),3))
for i1,i2,i3 in l:
  a,b,c = L[i1],L[i2],L[i3]
  if j(a,b,c):
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	L = LI();L.sort();L=np.array(L);
	#a<=b<=c
	ans = 0
	for i in range(N-1):
		for j in range(i+1,N):
			a,b = L[i],L[j]
			ch=(L>=b)&(L<(a+b))
			ch[[i,j]]=False
			ans +=  np.sum(ch)
	print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = LIST()

a = sorted(L)

su = 0
for i in range(N - 2):
	flag = 0
	for j in range(i+1, N - 1):
		if flag == 1:
			break
		for k in range(j + 1, N):
			if a[i]+a[j] > a[k]:
				su += 1
			else:
				flag = 0
			if flag == 1:
				break

print(su)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = map(int,input().split())
count = 0

l = list(itertools.combinations(l,3))
# print(l)

for i in l:
    if(i[0]+i[1]>i[2] and i[0]+i[2]>i[1] and i[1]+i[2]>i[0]):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def binary_search(a,b,j):
   left=j
   right=N
   while left<right-1:
      mid=(left+right)//2
      if L[mid]<a+b:
         left=mid
      else:
         right=mid

   return left

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

count=0

for i in range(N):
   for j in range(N):
      if j<=i:
         continue
      if j==N-1:
         continue
      a=L[i]
      b=L[j]

      c_index=binary_search(a,b,j)
      count+=c_index-j

print(count)

Submission status: Time Limit Exceeded

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
#import math
#import sys
#import heapq
#import fractions
#import bisect
#import numpy
#import queue
#import math
'''
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
n = int(input())   
l = list(map(int, input().split()))

l.sort(reverse=True)
ans=0
for i in range(0,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 = 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]:
                ans += 1
            else:
                break
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):
    a = L[i]
    for ii in range(i + 1, N):
        b = L[ii]
        for iii in range(N - 1, ii, -1):
            c = L[iii]
            if a >= b + c:
                continue
            ans += iii - ii
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
length_list = sorted(list(map(int, input().split())))
result = 0

for i in range(n):
  for j in range(i+1, n):
    upper = length_list[i] + length_list[j] - 1
    search_target = length_list[j+1:]
    less_than_upper = bisect.bisect_right(search_target, upper)
    result += less_than_upper
    
print(result)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(N):
    for ii in range(i + 1, N):
        for iii in range(ii + 1, N):
            if L[i] + L[ii] > L[iii] and \
                L[i] + L[iii] > L[ii] and \
                L[ii] + L[iii] > L[i]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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


def solve(N: int, L: "List[int]"):
    cnt=0
    for s in itertools.combinations(L, 3):
        a, b, c = s
        if (a < b + c) and (b < a + c) and (c < a + b):
            cnt+=1
    return cnt


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, L))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

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

count = 0
length_list.sort()

for a_idx in range(n - 2):
    for b_idx in range(a_idx + 1, n - 1):
        a = length_list[a_idx]
        b = length_list[b_idx]
        if b > a:
            a, b = b, a
        
        left_count = bisect_left(length_list, a+b)
        count += max(0, left_count - b_idx - 1)


print(count)

Submission status: Time Limit Exceeded

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

count = 0

for a_idx in range(len(length_list) - 2):
    for b_idx in range(a_idx+1, len(length_list) - 1):
        for c_idx in range(b_idx+1, len(length_list)):
            a = length_list[a_idx]
            b = length_list[b_idx]
            c = length_list[c_idx]
            # print(a,b,c)
            if a < b+c and b < c+a and c < a+b:
                count += 1  

print(count)

Submission status: Time Limit Exceeded

Solution code:
# ソートしたやつの小さい方から2つを決めてもうひとつはにぶたん
# 3, 5としたときに残りの一つは5, 6, 7みたいになる
# このにぶたんなんか実装がめっっっちゃむずくない？サンプル1が通らんのだが

import bisect

n = int(input())
arr = sorted(list(map(int, input().split())))


def lower_bound(arr, x):
    l, r = 0, len(arr)
    while l < r:
        mid = (l + r) // 2
        if arr[mid] < x:
            l = mid + 1
        else:
            r = mid
    return l


ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        idx_l = lower_bound(arr, arr[i] + arr[j]) - 1
        # print(
        #     "arr[{}]+arr[{}]={}より小さくなるはじめてのインデックス {}".format(
        #         i, j, arr[i] + arr[j], idx_l
        #     )
        # )
        # print("idx_l = {}, arr[{}]={}".format(idx_l, idx_l, arr[idx_l]))
        # print("範囲 {}".format(arr[j + 1 : idx_l + 1]))
        ans += len(arr[j + 1 : idx_l + 1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
#print(L)
ans = 0
def find(x, arr):
  a = len(arr)//2
  cur = a
  while True:
    a //= 2
    if arr[cur] < x:
      if cur == len(arr)-1:
        return cur+1
      elif arr[cur+1] >=x:
        return cur+1
      else:
        cur += max(1,a)
    else:
      if cur == 0:
        return 0
      else:
        cur -= max(1, a)
for i in range(N-2):
  for j in range(i+1, N-1):
    ans += find(L[i] + L[j], L)-j-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
#print(L)
ans = 0
def find(x, arr):
  a = len(arr)//2
  cur = a
  while True:
    a //= 2
    if arr[cur] < x:
      if cur == len(arr)-1:
        return cur+1
      elif arr[cur+1] >=x:
        return cur+1
      else:
        cur += max(1, a)
    else:
      if cur == 0:
        return 0
      else:
        cur -= max(1, a)
for i in range(N-2):
  for j in range(i+1, N-1):
    ans += find(L[i] + L[j], L[j+1:])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
base = set()
res = 0
for a in L:
    for b in L:
        for c in L:
            if (a+b > c and b + c > a and a + c > b):
                if len(frozenset((a,b,c))) == 3:
                    base.add(frozenset((a,b,c)))
print(len(base))

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
N = int(input())
L = list(map(int, input().split()))
L = sorted(L, reverse=True)
 
counter = 0
 
for i in range(0, N-2):
    temp = L[i]
    other = list(itertools.combinations(L[i+1:], 2))
    for j in range(len(other)):
        if temp < other[j][0] + other[j][1]:
            counter += 1
 
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

counter = 0

for i in range(0, N-2):
    temp = L[i]
    other = list(itertools.combinations(L[i+1:], 2))
    for j in range(len(other)):
        if temp < other[j][0] + other[j][1] and other[j][0] < temp + other[j][1] and other[j][1] < temp + other[j][0]:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
length_list = input().split()

counter = 0
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      a = int(length_list[i])
      b = int(length_list[j])
      c = int(length_list[k])
      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())
L = list(map(int, input().split()))

l_sorted = sorted(L, reverse=True)
ans = 0

for i in range(N - 2):
    a = l_sorted[i]
    for j in range(i + 1, N - 1):
        b = l_sorted[j]
        ans += len(list(filter(lambda x: abs(a - b)
                               < x < a + b, l_sorted[j + 1:])))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = list(map(int,input().split(" ")))
nums.sort()
total = 0
for i in range(n):
    for j in range(i+1,n):
        k = j+1
        while k < n and nums[k] < nums[i] + nums[j]:
            k+=1    
        total += k-j -1 
print(total)