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:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

i = "218 786 704 233 645 728 389"
L = list(map(int, i.split()))



L.sort()

print(L)

l1 = 0
l2 = 1
l3 = 2
ans = 0
while l1 < N - 2:
    while l3 < N: 
      if L[l1] + L[l2] > L[l3]:
        l3 += 1
      else:
        ans += cmb(l3 - l1 + 1, 3) 
        l2 = l3 - 1
        l1 = l2 - 1
  
      if l3 == l2 + 1 and l2 == l1 + 1: 
        l3 += 1
      elif l2 == l1 + 1:
        l2 += 1
      else:
        l1 += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
c=0
L.sort()
for i in range(N-2):
    for j in range(N-i-1):
        for k in range(N-i-j):
            if L[i+j+k]>=L[i]+L[i+j+1]:
                c+=1
c=int(c)
print(int(N*(N-1)*(N-2)/6-c))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

result = 0
for i in itertools.combinations((data), r=3):
  diff0 = i[0] - (i[1] + i[2])
  if diff0 < 0:
    diff1 = i[1] - (i[0] + i[2])
    if diff1 < 0:
      diff2 = i[2] - (i[0] + i[1])
      if diff2 < 0:
        result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
L=np.array(list(map(int, input().split())))
S=0
L.sort()
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]:
                S+=1
            else:
                break
print(S)

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
#print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        for k in range(j+1,len(L)):
            if L[i] + L[j] > L[k]:
                ans += 1
                #print(L[i], L[j], L[k])
            else:
                #print("break")
                break
print(ans)

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)
count = 0
for i in range(n-2):
    for j in range(n-i-2):
        j = j + i + 1
        count += len(np.where((l[i] + l[j]) > l)[0]) - j - 1
print(count)

Submission status: Time Limit Exceeded

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

l = list(l)
for i in range(n):
	l[i] = int(l[i])
l.sort()
count = 0
#a<b+c, a>b-c, a>c-b
for a in range(n):
	for b in range(a+1,n):
		for c in range(b+1,n):
			if l[a]<l[b]+l[c]:
				if l[b]<l[c]+l[a]:
					if l[c]<l[a]+l[b]:
						count += 1
					else:
						break

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
L = list(map(int, inputs[1].split()))

sort_L = sorted(L)
ans = 0
for i in range(n-2):
    a = sort_L[i]
    for j in range(i+1, n-1):
        b = sort_L[j]
        d = a+b
        for k in range(j+1, n):
            c = sort_L[k]
            if c < d:
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import time

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

#start = time.time()
L.sort()

def is_build(a, b, c):
    return (a<b+c)and(b<a+c)and(c<a+b)

buildable = 0
"""
# TLE
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if is_build(L[i], L[j], L[k]):
                buildable += 1
"""
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[k] >= L[i] + L[j]:
                break
            #if is_build(L[i], L[j], L[k]):
            buildable += 1

print(buildable)
#print(time.time() - start)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def combinations(iterable, r):
    # combinations('ABCD', 2) --> AB AC AD BC BD CD
    # combinations(range(4), 3) --> 012 013 023 123
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    yield tuple(pool[i] for i in indices)
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        yield tuple(pool[i] for i in indices)


n = int(input())
l = list(map(int,input().split()))
cnt =0
ret=list(combinations(l,3))

for i in range(len(ret)):
  if ret[i][0] < ret[i][1] + ret[i][2] and ret[i][1] < ret[i][0] + ret[i][2] and ret[i][2] < ret[i][1] + ret[i][0]:
    cnt += 1
#if l[i] < l[j] + l[k] and l[j] < l[i] + l[k] and l[k] < l[j] + l[i]:
#	cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
l = list(map(int, input().split()))
t = list(itertools.combinations(l, 3))

count = 0
for i in t:
    i_s = sorted(i)
    a,b,c = i_s
    if b <a+c and c<a+b:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ln = input().split()
s = 0

for i in range(n):
  for j in range(i + 1, n):
    for k in range(j + 1, n):
      if int(ln[i]) < int(ln[j]) + int(ln[k]) and int(ln[j]) < int(ln[k]) + int(ln[i]) and int(ln[k]) < int(ln[j]) + int(ln[i]):
        s += 1
        
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = str(input())
N = int(N)
Lines = input().split(" ")
Lines = list(map(int, Lines))
answer = 0

for lineI in range(N):
    for lineJ in range(lineI+1,N):
        for lineK in range(lineJ+1,N):
             if (Lines[lineI] + Lines[lineJ] > Lines[lineK]) and (Lines[lineK] + Lines[lineJ] > Lines[lineI]) and (Lines[lineK] + Lines[lineI] > Lines[lineJ]):
                answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = 0

for combi in itertools.combinations(l_list, 3):
    a = combi[0]
    b = combi[1]
    c = combi[2]
    if a<b+c and b<c+a and c<a+b:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def calc(a, b, c):
  if abs(b-c) < a and a < b+c:
    return 1
  return 0

n = int(input())
l = [int(s) for s in input().split()]
conter = 0

for i in l:
  if all([2*j < i for j in l]):
    l.remove(i)
    n-=1

for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      conter += calc(l[i],l[j],l[k])
print(conter)

Submission status: Time Limit Exceeded

Solution code:
import time
def binary_search(List,key,start,goal):
    if start >= goal:
        if key - List[start] >= 0:
            return start - 1
        else:
            return start
    else:
        mid = start + int((goal - start) / 2)

        if key - List[mid] >= 0:
            return binary_search(List,key,start,mid-1)
        else:
            return binary_search(List,key,mid+1,goal)


N = int(input())
L = [int(x) for x in input().split()]

L.sort(reverse=True)
count = 0

#t1 = time.time()

for i in range(N-2):
    for j in range(i+1,N-1):
        #if L[j]*2 <= L[i]:
        #    break

        diff = L[i] - L[j]
        itr = binary_search(L,diff,j+1,N-1)
        count += itr - j
        #print(f"{itr-j}をたしました")
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np
N = int(input())
L = np.array(input().split(), dtype=np.int32)
L = np.sort(L)[::-1]
diff = L[:-2] - (L[1:-1] + L[2:])
idx_list = np.where(diff < 0)[0]
res = 0
for idx in idx_list:
    comb_list = itertools.combinations(L[idx+1:], 2)
    res += sum(L[idx] < comb[0] + comb[1] for comb in comb_list)
print(res)

Submission status: Time Limit Exceeded

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

L.sort()
c=(list(itertools.combinations(L,3)))
ans=0
for a,b,c in c:
  if 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()))

L = sorted(L)
ans = 0
H = {}
for i in range(N-1):
    for j in range(i+1, N):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(h[1]+1, N):
        if v <= L[j]:
            break
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
N=int(input())
Ls=sorted(list(map(int,input().split())))[::-1]

Ans=0

for t in range(len(Ls)):
    Ls2=Ls[t+1:]
    Tri=list(itertools.combinations(Ls2, 2))
    Ans+=len(list(filter(lambda x: sum(x)>Ls[t], Tri)))

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = 0

for i in itertools.combinations(L, 3):
  if i[0] < i[1] + i[2]:
    if i[1] < i[0] + i[2]:
      if i[2] < i[1] + i[0]:
        count += 1
      else:
        continue
    else:
      continue
  else:
    continue

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

e = sorted(d)

ans = 0

for i in range(N-2):
    for j in range(i+1,N-1):
        S = e[i] + e[j]
        for k in range(j+1,N):
            if S <= e[k]:
                break
            else:
                ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
L.sort(reverse=True)

for i in range(N-2):
    if L[i] > L[i+1] + L[i+2]:
        continue
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] < L[j] + L[k]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] < h[j] + h[k] and h[j] < h[i] + h[k] and h[k] < h[j] + h[i]:
                    x = x + 1
    return x
print(triangle(n,h))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for ai in range(N):
  for bi in range(ai+1,N):
    for ci in range(bi+1,N):
      if L[ci] < L[ai] + L[bi]:      
        ans += 1
      else:break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools



N = int(input().strip())
L = [int(str) for str in input().split()]

L.sort()

ans = 0

for c_i in range(2, N):
    min_a_i = 0
    while L[c_i] >= L[min_a_i] + L[c_i - 1] and min_a_i < c_i - 1:
        min_a_i += 1
    
    for b_i in range(min_a_i + 1, c_i):
        a_i = min_a_i
        while L[a_i] + L[b_i] <= L[c_i] and a_i < b_i:
            a_i += 1
        
        ans += b_i - a_i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

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

dp = [[-1 for i in range(1001)] for j in range(n)]

cnt = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    tgt = l[i] - l[j]
    if dp[j+1][tgt] != -1:
      cnt += dp[j+1][tgt]
    else:
      lcnt = 0
      for k in range(j+1, n):    
        if l[k] > tgt:
          cnt += 1
          lcnt += 1
        else:
          break
      dp[j+1][tgt] = lcnt

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

from itertools import accumulate
from scipy.misc import comb


# def factorial(x):
#     if x <= 0:
#         return 1
#
#     return factorial(x - 1) * x
#
#
# def comb(n, r):
#     return factorial(n) / factorial(r) / factorial(n - r)


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

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
                cnt += int(comb(nums[b], 2)) * nums[a]
                tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

t = list(itertools.combinations(l,3))
sum = 0
for combi in t:
    i = combi[0]
    j = combi[1]
    k = combi[2]
    a = abs(j-k)
    b = j + k
    if a < i < b:
        sum += 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
counter = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):

            if((l[i] < l[j]+l[k]) and (l[j] < l[i]+l[k]) and (l[k] < l[i]+l[j])):
                counter += 1


print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[int(_) for _ in input().split()]
L.sort(reverse=True)

ans=0

for i in range(N):
    for j in range(i+1,N):
        for k in range(N-1,j,-1):
            if L[i]<L[j]+L[k]:
                ans+=k-j
                break

print(ans)

Submission status: Time Limit Exceeded

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

from bisect import bisect_left, bisect_right

cnt = 0
for i in range(N):
    a = l[i]
    for j in range(i, N):
        if i == j:
            continue
        b = l[j]
        l2 = l[j+1:]
        start = bisect_right(l2, b-a)
        end = bisect_left(l2, a+b)
        cnt += len(l2[start:end])
print(cnt)

Submission status: Time Limit Exceeded

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

L.sort(reverse=True)
sum = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    if(L[i] > L[j] + L[j+1]):
        break
    else:
      for k in range(j+1, N):
        if(L[i] < L[j] + L[k]):
          sum +=1
        else:
          break

print("{}".format(sum))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted(map(int, input().split()))
length = len(L)


count = 0
for x in range(length):
    a = L[x]

    for y in range(x + 1, length):
        b = L[y]

        for z in range(y + 1, length):
            c = L[z]

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = sorted([int(item) for item in input().split(' ')])
count = 0
 
for i in range(N):
    kmax = N
    for j in range(N-1, i, -1):
        for k in range(j+1, kmax):
            if l[i] + l[j] > l[k]:
                count += 1
            else:
                kmax -= 1
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=list(map(int,input().split()))
C=[x for x in itertools.combinations(L,3) if x[0]<x[1]+x[2] and x[1]<x[0]+x[2] and x[2]<x[0]+x[1]]
print(len(C))

Submission status: Time Limit Exceeded

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


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

    result = 0
    # print(l)
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            target = l[j + 1:]
            count = sum(1 for x in target if x < (l[i] + l[j]))
            # count = np.count_nonzero(target < (l[i] + l[j]))
            # print(l[i], l[j], target, count)
            result += count

    print(result)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
#print(l)
ans = 0
for x in range(n - 1):
    for y in range(x + 1, n):
        lx = l[x]
        ly = l[y]
        s = lx + ly
        pl = bisect.bisect_left(l, s)
        #pr = bisect.bisect_right(l, s)
        c = l[y + 1: pl]
        #print("x:{} y:{}, lx:{}, ly:{}, pr:{}, c:{}".format(x, y, lx, ly, pr, c))
        for lz in c:
            ans += 1 if lx + lz > ly and ly + lz > lx else 0
            #print("ans: {} - {} {} {}".format(ans, lx, ly, lz))
print(ans)

Submission status: Time Limit Exceeded

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


def solve(N: int, L: "List[int]"):
    bar_3 = itertools.combinations(L, 3)

    result = 0
    for a, b, c in set(bar_3):
        if abs(b - c) < a < b + c:
            result += 1
        else:
            pass

    print(result)
    return


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]"
    solve(N, L)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
l = list(map(int, input().split()))
t = list(itertools.combinations(l, 3))

count = 0
for i in t:
    i_s = sorted(i)
    a,b,c = i_s
    if a<b+c and b <a+c and c<a+b:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

lines.sort()
# print(lines)

sum = 0
for i in range(N):
    for j in range(i + 2, N):
        # print("i,j:{0},{1}".format(i, j))
        # print("lines[i],lines[j]:{0},{1}".format(lines[i], lines[j]))
        k = j - 1
        while i < k:
            # print("i,j,k:{0},{1},{2}".format(i, j, k))
            # print("lines[i],lines[j],lines[k]:{0},{1},{2}".format(lines[i], lines[j], lines[k]))

            if ((lines[i] + lines[j]) > lines[k]) and (lines[i] + lines[k]) > lines[j]:
                # print("count up")
                sum += 1
            k -= 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        min_range = abs(L[i] - L[j])
        max_range = L[i] + L[j]
        if max_range - min_range <= 1:
            break
        # print(L[j+1:])
        # print((min_range < L[j+1:]) & (L[j+1:] < max_range))
        ans += np.count_nonzero((min_range < L[j+1:]) & (L[j+1:] < max_range))
print(ans)

Submission status: Time Limit Exceeded

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

L.sort()
L2 = [(l, 1) for l in L]
LR = []
#print(L)

from bisect import bisect_left

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1:]):
        j=i+1+j
        L2.append((abs(a-b), 0))
        L2.append((a+b, 0))
        LR.append((abs(a-b), a+b, i, j))

L2.sort()
L_dict = {}

cnt = 0
for v, f in L2:
    if f == 0:
        L_dict[v] = cnt
    else:
        cnt += 1
        
ans = 0
for l, r, i, j in LR:
    x = max(L_dict[l], j+1)
    y = max(L_dict[r], j+1)
    ans += y-x
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):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        l = L[j+1:]
        ans += sum(c < (a+b) for c in l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
d_list = list(map(int, input().split()))
c_d_list = list(itertools.combinations(d_list, 3))
count = 0
for i in c_d_list:
    a = i[0]
    b = i[1]
    c = i[2]
    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())
ln = sorted([int(i) for i in input().split()])
ans = 0
for j in range(n - 2):
    for k in range(n - 1):
        if j >= k:
            continue
        else:
            if ln[j] + ln[k] > ln[k + 1]:
                for l in range(k + 1, n):
                    if ln[j] + ln[k] > ln[l]:
                        if ln[j] + ln[l] > ln[k]:
                            if ln[l] + ln[k] > ln[j]:
                                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations 
input = sys.stdin.readline

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

l.sort()
cnt = 0

for n,i in enumerate(l[:]):
    for m,j in enumerate(l[n+1:],n+1):

        cnt +=len(list([c for c in set(l[m+1:]) if c<=i+j-1]))

        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import itertools
num = int(input())
lines = list(int(i) for i in input().split())
lines.sort(reverse=True)
counter = 0

comb = itertools.combinations(lines, 3)

for c in comb:
  cl = list(c)
  if cl[0] < cl[1] + cl[2]:
    counter += 1
    
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
l=list(map(int,input().split()))
cnt=0
ls = sorted(l)
for i in range(n-1):
    for j in range(i+1,n-1):
        for h in range(j+1,n):
            a,b,c=ls[i],ls[j],ls[h]
            if(a+b<c):
                break
            if(a<b+c)and(b<a+c)and(c<a+b):
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

L = np.array(sorted(L, reverse=True))

ans = 0

for n in range(0,N-2):
    if L[n] > L[n+1] + L[n+2]:
        pass
    else:
        for o in range(n+1,N-1):
            ans += np.sum(L[o+1:]>L[n]+-L[o])
                
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
def main():
    number_of_bars = int(input())
    bar_list = list(map(int,input().split()))
    print(len(traiangle_maker(bar_list))//3)


def traiangle_maker(bar_list):
    bar_list.sort(reverse=True)
    result_list = []
    for i in range(len(bar_list)):
        for j in range(len(bar_list)):
            if i == j or bar_list[i] < bar_list[j]:
                continue
            minimum_length = bar_list[i] - bar_list[j]
            max_length = bar_list[i] + bar_list[j]
            for k in bar_list:
                if k < minimum_length:
                    continue
                if k > minimum_length and k < max_length and k != bar_list[i] and k != bar_list[j]:
                    traiangle = [bar_list[i],bar_list[j],k]
                    result_list.append(traiangle)

    return result_list


main()

Submission status: Time Limit Exceeded

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


def solve(N: int, L: "List[int]"):
    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] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j]:
                    cnt += 1
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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]"
    solve(N, L)

if __name__ == '__main__':
    main()

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-1):
    for j in range(i+1,N):
        temp=L[i]+L[j]
        idx=bisect.bisect_left(L,temp)
        for k in range(idx-1,-1,-1):
            if k!=i and k!=j:
                if min(L[i],L[j])+L[k]<=max(L[i],L[j]):
                    continue
                ans+=1


print(ans//3)

Submission status: Time Limit Exceeded

Solution code:
import time
def binary_search(List,key,start,goal):
    if start >= goal:
        if key - List[start] >= 0:
            return start - 1
        else:
            return start
    else:
        mid = start + int((goal - start) / 2)

        if key - List[mid] >= 0:
            return binary_search(List,key,start,mid-1)
        else:
            return binary_search(List,key,mid+1,goal)


N = int(input())
L = [int(x) for x in input().split()]

L.sort(reverse=True)
count = 0

#t1 = time.time()

for i in range(N-2):
    for j in range(i+1,N-1):
        if L[j]*2 <= L[i]:
            break

        diff = L[i] - L[j]
        itr = binary_search(L,diff,j+1,N-1)
        count += itr - j
        #print(f"{itr-j}をたしました")
print(count)

#t2 = time.time()

#print(f"経過時間:{t2-t1}")

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L.sort()
	sum = 0
	for c in range(2, N):
		if L[c] < L[c - 1] + L[c - 2]:
			for b in range(c - 1, 0, -1):
				if L[c] < L[b] + L[b - 1]:
					for a in range(b - 1, -1, -1):
						if L[c] < L[b] + L[a]:
							sum += 1
						else:
							break
	print(sum)

Submission status: Time Limit Exceeded

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

res = 0

for i in range(N-2):
    L1 = L[i+1:]
    a = L[i]
    for j in range(len(L1)-1):
        L2 = L1[j+1:]
        b = L1[j]
        sup = a + b
        inf = max(a-b,b-a)
        SL2 = set(L2)
        test = {x for x in range(inf+1,sup)}
        Scan = SL2 & test
        if len(Scan) == 0:
            break

        LScan = list(Scan)
        M = len(LScan)
        for c in LScan:
            res += L2.count(c)

print(res)

Submission status: Time Limit Exceeded

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

import itertools
C = list(itertools.combinations(L,3))
l = len(C)

for i in range(l):
    if C[i][0] + C[i][1] <= C[i][2]:
        pass
    elif C[i][1] + C[i][2] <= C[i][0]:
        pass
    elif C[i][2] + C[i][0] <= C[i][1]:
        pass
    else:
        count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import copy
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))




N=one_int()
L=many_int()

L=sorted(L)

sankaku_dict={}
search_end={}
count=0
for i in range(len(L)-1):
    low=L[i]
    Lcopy = copy.deepcopy(L)
    Lcopy.remove(low)
    
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        temp = str(L[i]) +","+ str(L[j])
        if temp in search_end:
            continue
        high = L[j]
        Lcopy2 = Lcopy[j:]
        
        #下限を取得    
        under_index = bisect.bisect_right(Lcopy2,high-low)
        #上限を取得
        high_index = bisect.bisect_left(Lcopy2,high+low)
        
#         for va in Lcopy2[under_index:high_index]:
#             temp = sorted([high,low, va])
#             temp = (temp[0]*10**8) + (temp[1]*10**4) + temp[2]
#             sankaku_dict[temp]=1
        count+=len(Lcopy2[under_index:high_index])

# len(sankaku_dict)
print(count)
# print(len(sankaku_dict.keys()))

Submission status: Time Limit Exceeded

Solution code:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
n = int(input())
L = list( map(int, input().split()) )	# 1 2 3 4 5 ...

L.sort()

ans=0

#p(L)

def bsl(c,L):
	
	rMax = len(L)-1
	
	l=0
	r=rMax
	
	while True:
		m=(l+r)//2
		#p("  [bsl]c,l,r,m ",c,l,L[l],r,L[r],m,L[m] )

		if L[m]==c:
			while True:
				if m==rMax: return m
				if L[m]==L[m+1]:
					m+1
				else:
					return m
		
		if (r-l)==1:
			if L[r]<=c:
				return r
			else:
				return l
		
		if c<L[m]: r=m
		if L[m]<c: l=m


for i in range(n-2):
	a=L[i]
	
	for j in range(i+1, n-1):
		b=L[j]
		#if b>(a*2): break
		
		#p("a,b,a+b-1 ",a,b,a+b-1)
		k = bsl(a+b-1, L)
		
		if j<k: ans += (k-j)
		#p("j,k,(k-j),ans ",j,k,(k-j),ans)

print(ans)

Submission status: Time Limit Exceeded

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

L.sort()
L.reverse()

cnt = 0
for i in range(int(N)):
	for j in range(i+1, N):
		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()))
s=0
for i,l0 in enumerate(l):
  for j,l1 in enumerate(l[i+1:]):
    for l2 in l[i+j+2:]:
      if abs(l0-l1)<l2<(l0+l1):
        s+=1
print(s)