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()))
def func(a,b,c):
    if a<(b+c) and b<(c+a) and c<(a+b):
        return True
    else:
        return False
from itertools import combinations
com = list(combinations(L,3))
ans = 0
for a,b,c in com:
    if func(a,b,c):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #a,b,c=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    ml=(10**3)*3
    memo=[0]*ml
    for a in arr:
        memo[a]+=1
    for i in range(1,ml):
        memo[i]+=memo[i-1]
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                a=arr[i]
                b=arr[j]
                c=arr[k]
                if (a<b+c) and (b<a+c) and (c<a+b):
                    ans+=1
    print(ans)
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Submission status: Time Limit Exceeded

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

import itertools

cnt = 0
for v in itertools.combinations(L, 3):
    a = v[0]
    b = v[1] 
    c = v[2] 
    if a < b+c and b < c+a and c< a+b:
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

count = 0
for a,b,c in C:
    if a < b + c and b < c + a and c < b + a:
        count += 1 
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
def bis_right(lis,dev):
    a=0
    b=len(lis)-1
    while a<b:
        c=(a+b)//2
        if lis[c]>dev:
            b=c
        else:
            a=c+1
    if lis[a]<=dev:
        return a
    return a-1



n=int(input())
l=[int(x) for x in input().split()]
l.sort()
s=0
for a in range(n-2):
    for b in range(a+1,n-1):
        c=bis_right(l[b+1:],l[a]+l[b]-1)
        s+=c+1
print(s)

Submission status: Time Limit Exceeded

Solution code:

def comp(ext,list0,dev):
    if list0[int((ext[0]+ext[1])/2)]>dev:
        return ext[0],int((ext[0]+ext[1])/2)
    else:
        return int((ext[0]+ext[1])/2),ext[1]


def bis(a,b,list0,dev):
    ls=[a,b]
    while ls[0]+1<ls[1]:
        ls=comp(ls,list0,dev)
    if list0[ls[0]]==dev:
        return ls[0]-1
    elif list0[ls[1]]==dev:
        return ls[1]-1
    else:
        return ls[0]


n=int(input())
l=[int(x) for x in input().split()]
l.sort()
s=0
for a in range(0,n-2):
    for b in range(a+1,n-1):
        if l[a]+l[b]>l[n-1]:
            c=n-1
        elif l[a]+l[b]<l[b+1]:
            c=b
        else:
            c=bis(b+1,n-1,l,l[a]+l[b])
        s=s+c-b
print(s)

Submission status: Time Limit Exceeded

Solution code:

def comp(ext,list0,dev):
    if list0[int((ext[0]+ext[1])/2)]>dev:
        return ext[0],int((ext[0]+ext[1])/2)
    else:
        return int((ext[0]+ext[1])/2),ext[1]


def bis(a,b,list0,dev):
    ls=[a,b]
    while ls[0]+1<ls[1]:
        ls=comp(ls,list0,dev)
    if list0[ls[0]]==dev:
        return ls[0]-1
    elif list0[ls[1]]==dev:
        return ls[1]-1
    else:
        return ls[0]


n=int(input())
l=[int(x) for x in input().split()]
l.sort()
s=0
for a in range(0,n-2):
    for b in range(a+1,n-1):
        if l[a]+l[b]>l[n-1]:
            c=n-1
        elif l[a]+l[b]<l[b+1]:
            c=b
        else:
            c=bis(b+1,n-1,l,l[a]+l[b])
        s=s+c-b
print(s)

Submission status: Time Limit Exceeded

Solution code:


def comp(ext,list0,dev):
    if list0[int((ext[0]+ext[1])/2)]>dev:
        return ext[0],int((ext[0]+ext[1])/2)
    else:
        return int((ext[0]+ext[1])/2),ext[1]


def bis(a,b,list0,dev):
    ls=[a,b]
    while ls[0]+1<ls[1]:
        ls=comp(ls,list0,dev)
    if list0[ls[0]]==dev:
        return ls[0]-1
    elif list0[ls[1]]==dev:
        return ls[1]-1
    else:
        return ls[0]


n=int(input())
l=[int(x) for x in input().split()]
l.sort()
s=0
for a in range(n-2):
    for b in range(a+1,n-1):
        if l[a]+l[b]>l[n-1]:
            c=n-1
        elif l[a]+l[b]<l[b+1]:
            c=b
        else:
            c=bis(b+1,n-1,l,l[a]+l[b])
        s=s+c-b
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

n = int(input())
li = list(map(int, input().split(" ")))

ans = 0
for tpl in list(itertools.combinations(li, 3)):
    a, b, c = tpl
    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())
listL=list(map(int,input().split()))
listL.sort()
ans=0
for i in range(0,N-2):
  for k in range(i+1,N-1):
    for t in range(k+1,N):
      IF=listL[i]+listL[k]-listL[t]
      if IF>0:
        ans+=1
      else:
        break
print(ans)

Submission status: Time Limit Exceeded

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


def main():
    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):
                sum = L[i] + L[j]
                sub = abs(L[i] - L[j])
                if sub < L[k] < sum:
                    count += 1
    print(count)





if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations 
from bisect import bisect_left
def main():
    N = int(readline())
    L = [int(i) for i in readline().split()]
    L.sort()
    sig = 0
    for i in range(N):
        for j in range(i+1, N):
            l = bisect_left(L[j+1:], L[i]+L[j])
            sig += l
    print(sig)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

counter = 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]):
        counter += 1
    else:
        continue

print(counter)

Submission status: Time Limit Exceeded

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

import itertools
all_comb = list(itertools.combinations(l,3))

for i in range(len(all_comb)):
    a = all_comb[i][0]
    b = all_comb[i][1]
    c = all_comb[i][2]
    if a + b > c and b + c > a and c + a > b:
        count += 1
print(count)

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

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):
  for j in range(i+1, n-1):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    temp1 = bisect.bisect_left(l[j+1:], l[j]-l[i])
    temp2 = bisect.bisect_left(l[j+1:], l[j]+l[i])
    #print(temp1)
    #print(temp2)
    ans += (temp2-temp1)
    
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):
  for j in range(i+1, n-1):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    ans +=  len(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<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()))
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] 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 sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    L = il()

    ret = 0
    for a, b, c in itertools.combinations(L, 3):
        if a < b + c and b < c + a and c < a + b: ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def __bisect_left(data, x, left, right):
    if left >= right:
        return right
    mid = (left+right)//2
    if data[mid] >= x:
        return __bisect_left(data, x, left, mid-1)
    else:
        return __bisect_left(data, x, mid+1, right)

def bisect_left(data, x, left):
    return __bisect_left(data, x, left, len(data))
    
n = int(input())
sides = list(map(int, input().split()))
sides.sort()
ans = 0
for a in range(len(sides)):
    for b in range(a+1,len(sides)):
        bound = bisect_left(sides, sides[a]+sides[b], b+1)
        if bound >= n:
            ans += bound - b - 1
        elif sides[bound] < sides[b]:
            ans += bound - b
        elif bound > b+1:
            ans += bound - b - 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def __lower_bound(arr, x, left, right):
    if left >= right:
        return right
    mid = (left+right)//2
    if arr[mid] < x:
        return __lower_bound(arr, x, mid+1, right)
    else:
        return __lower_bound(arr, x, left, mid-1)
def lower_bound(arr, x, left, right):
    result = __lower_bound(arr, x, left, right)
    if arr[result] >= x:
        result -= 1
    return result

n = int(input())
data = list(map(int, input().split()))
data.sort()
ans = 0
for a in range(n):
    for b in range(a+1, n):
        bound = lower_bound(data, data[a]+data[b], b+1, n-1)
        if bound >= 0:
            ans += bound - b

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

count = 0
for c in circle:
    if c[0] < c[1] + c[2] and c[1] < c[2] + c[0] and c[2] < c[0] + c[1]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

# check
nC3 = list(combinations(L, 3))
case = [
    1
    for a, b, c in nC3
    if a < b + c
    and b < c + a
    and c < a + b
]

print(len(case))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

# check
nC3 = list(combinations(L, 3))
case = [
    (a, b, c)
    for a, b, c in nC3
    if a < b + c
    and b < c + a
    and c < a + b
]

print(len(case))

Submission status: Time Limit Exceeded

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

n = 0

for i, n1 in enumerate(L):
    for j in range(N-i-1):
        n2 = L[i+j+1]
        for k in range(N-i-j-2):
            n3 = L[i+j+k+2]
            if n1 + n2 <= n3:
                break
            n += 1


result = N*(N-1)*(N-2)/6 - n

print(n)

Submission status: Time Limit Exceeded

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

n = 0

for i, n1 in enumerate(L):
    for j, n2 in enumerate(L[i+1:]):
        for n3 in L[i+j+2:]:
            if n1 + n2 <= n3:
                break
            n += 1


result = N*(N-1)*(N-2)/6 - n

print(n)

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
D,l,r=0,0,0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=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(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=l-j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
def nibuta(a,x):
    h=len(a)
    if a[0]>=x:
        return 0
    elif a[h-1]<x:
        return h
    else:
        lo=-1
        up=h-1
        while up-lo>1:
            if a[(lo+up)//2]>=x:
                up=(lo+up)//2
            else:
                lo=(lo+up)//2
        if a[up]>=x:
            return lo+1
        else:
            return up+1
s=0
for i in range(n-2):
    a1=l[i]
    for j in range(i+1,n-1):
        k=a1+l[j]
        s=s+nibuta(l[j+1:],k)
print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
def nibuta(a,x):
    h=len(a)
    if a[0]>=x:
        return 0
    elif a[h-1]<x:
        return h
    else:
        lo=0
        up=h-1
        while up-lo!=1:
            if a[(lo+up)//2]>=x:
                up=(lo+up)//2
            else:
                lo=(lo+up)//2
        if a[up]>=x:
            return lo+1
        else:
            return up+1
s=0
for i in range(n-2):
    a1=l[i]
    for j in range(i+1,n-1):
        k=a1+l[j]
        s=s+nibuta(l[j+1:],k)
print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
from numba import njit, jit
from itertools import combinations


@jit
def solve():
    ans = 0
    for a, b, c in combinations(L, r=3):
        ans += a + b > c
    return ans


print(solve())

Submission status: Time Limit Exceeded

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

ans = 0
for a, b, c in combinations(L, r=3):
    ans += a + b > c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

num=itertools.combinations(l,3)

for i in list(num):
  if i[0]<i[1]+i[2] and i[1]<i[0]+i[2] and i[2]<i[0]+i[1]:
    count+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left,bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
#c - b < a < c + b
for i in range(n-1):
    for j in range(i+1,n):
        sahen = bisect(l,l[j]-l[i])
        uhen = bisect_left(l,l[j]+l[i])
        ans += uhen - sahen
        if sahen <= i <= uhen -1:
            ans -= 1
        if sahen <= j <= uhen -1:
            ans -= 1
print(ans//3)

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[j] < l[i]:
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

lisL.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ab = lisL[i] + lisL[j]
        ans += bisect.bisect_left(lisL[j+1:],ab)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
lisL = list(map(int,input().split()))
arrL = np.array(sorted(lisL))

ans = 0
for i in range(N):
    for j in range(i+1,N):
        a = arrL[i]
        b = arrL[j]
        ans += np.bincount((arrL[j+1:]< a+b),minlength=2)[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] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
        cnt += 1
      else:
        pass
#      else:
#        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-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
      else:
        break
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        sum2 = l[i] + l[j]
        for k in range(j+1, n):
            if l[k] >= sum2:
                break
            if l[i] < l[j] + l[k] and l[j] < l[k] + l[i]:
                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[j] < l[k] + l[i] and l[k] < l[i] + l[j]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
def bin_search(key, list):
    ok = n
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if list[mid] > key:
            ok = mid
        else:
            ng = mid
    return ok

ans = 0
for i in range(1, n - 1):
    for j in range(i + 1, n):
        c_min_len = l[j] - l[i]
        x = i - bin_search(c_min_len, l)
        ans += max(0, x)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
def bin_search(key, list):
    ok = len(list)
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if list[mid] > key:
            ok = mid
        else:
            ng = mid
    return ok

ans = 0
for i in range(1, n - 1):
    for j in range(i + 1, n):
        c_min_len = l[j] - l[i]
        x = i - bin_search(c_min_len, l)
        if x > 0:
            ans += x
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
L = sorted(L, reverse=True)
count = 0
for i in range(0,N-2):
	for j in range(i+1,N-1):
		value = L[i] - L[j]
		if L[j+1] <= value:
			num = 0
		elif L[N-1] > value:
			num = N-j-1
		else:
			start = j+1
			end = N-1
			while start <= end:
				k = (end + start) // 2
				if L[k] > value and L[k+1] <= value:
					num = k-j
					break
				if L[k+1] > value:
					start = k + 1
				else:
					end = k - 1
		count += num
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
L = sorted(L, reverse=True)
count = 0
for i in range(0,N-2):
	for j in range(i+1,N-1):
		value = L[i] - L[j]
		if L[j+1] <= value:
			num = 0
		elif L[N-1] > value:
			num = N-j-1
		else:
			start = j+1
			end = N-1
			while start <= end:
				k = (end + start) // 2
				if L[k] > value and L[k+1] <= value:
					num = k-j
					break
				if L[k+1] > value:
					start = k + 1
				if L[k] <= value:
					end = k - 1
		count += num
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
L = sorted(L, reverse=True)
count = 0
for i in range(0,N-2):
	for j in range(i+1,N-1):
		k = j+1
		while k < N and L[k] + L[j] > L[i]:
			count += 1
			k += 1
print(count)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb = itertools.combinations([i for i in range(N)], 2)
cnt = 0

for cmb in comb:
    a = L[cmb[0]]
    b = L[cmb[1]]
    for i in range(cmb[1]+1, N):
        if L[i] < a+b:
            cnt += 1
    

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
input()
p=0
for i,j,k in itertools.combinations(map(int,input().split()),3):
    if i<j+k and j<i+k and k<i+j:
        p+=1
print(p)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
def find_min_fuka_idx(lst, e1, e2):
  ok = -1
  ng = len(lst)
  while abs(ok-ng)>1:
    mid = (ok+ng)//2
    e3 = lst[mid]
    if e1+e2 > e3 and e2+e3>e1 and e3+e1>e2:
      ok = mid
    else:
      ng = mid
  return ng
c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += find_min_fuka_idx(a[j+1:], a[i], a[j])
print(c)

Submission status: Time Limit Exceeded

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

ln.sort()

def binary_search(x, r):
    left = r + 1
    right = n-1
    while left < right:
        mid = (left + right) // 2
        if ln[mid] == x:
            return mid
        elif ln[mid] > x:
            right = mid - 1
        else:
            left = mid + 1
    mid = (left + right) // 2
    if ln[mid] > x:
        return mid - 1
    else:
        return mid


ans = 0
for a in range(n-2):
    for b  in range(a+1, n-1):
        cmin = ln[b] - ln[a] + 1
        cmax = ln[b] + ln[a] - 1
        ans += max(0, binary_search(cmax, b) - b)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in itertools.combinations(l,3):
	a,b,c=map(int,i)
	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
n = int(input())
L = list(map(int,input().split()))
ans = 0

for v in itertools.combinations(L, 3):
  if v[0] < v[1]+v[2]:
    if v[1] < v[0]+v[2]:
      if v[2] < v[0]+v[1]:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
L = LI()
ans = 0
# for v in itertools.combinations(L, 3):    
#     if v[0] < v[1] + v[2] and v[2] < v[0] + v[1] and v[1] < v[2] + v[0]:
#         ans += 1
# print(ans)

L.sort()
for i in range(1, N-1):
    for q in range(0,i):
        for k in range(i+1,N):
            if L[k] >= L[i] + L[q]:
                break
            if L[i] < L[q] + L[k] and L[k] < L[i] + L[q] and L[q] < L[k] + L[i]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
L = LI()
ans = 0
# for v in itertools.combinations(L, 3):    
#     if v[0] < v[1] + v[2] and v[2] < v[0] + v[1] and v[1] < v[2] + v[0]:
#         ans += 1
# print(ans)

L.sort()
for i in range(1, N-1):
    for q in range(0,i):
        for k in range(i+1,N):
            if L[i] < L[q] + L[k] and L[k] < L[i] + L[q] and L[q] < L[k] + L[i]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

_ = I()
L = LI()
ans = 0
for v in itertools.combinations(L, 3):    
    if v[0] < v[1] + v[2] and v[2] < v[0] + v[1] and v[1] < v[2] + v[0]:
        ans += 1
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):
            a, b, c = L[i], L[j], 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:
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 a<b+c and b<a+c and c<a+b:
              ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
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):
            a=l[i]
            b=l[j]
            c=l[k]
            if a<b+c and b<a+c and c<a+b:
              ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        ub = bisect.bisect_left(aa , aa[i]+aa[j])
        lb = bisect.bisect_right(aa, abs(aa[i]-aa[j]))
        cnt += ub - lb
        if (lb <= i)&(i<ub):
            cnt -= 1
        if (lb <= j)&(j<ub):
            cnt -= 1
print(cnt//3)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
L = LI()
ans = 0
for a, b, c in combinations(L, 3):
    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 = [int(_) for _ 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):
            a, b, c = l[i], l[j], l[k]
            if a < b+c:
                if b < c+a:
                    if c < a+b:
                        ans += 1
print(ans)