Problem:


Score : 400 points

Problem Statement

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

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

a < b + c

b < c + a

c < a + b

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

Constraints

All values in input are integers.

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

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

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

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import accumulate, combinations
from random import random

import numpy as np

sys.setrecursionlimit(200000)


class Solver:
    def __init__(self):
        pass

    def input(self):
        """
            faster input function than builtin stdin.
        """
        return sys.stdin.readline()[:-1]

    def ii(self, t: type = int):
        """
            input single value.
        """
        return t(self.input())

    def il(self, t: type = int):
        """
            input single line.
        """
        return list(map(t, self.input().split()))

    def imi(self, N: int, t: type = int):
        return [self.ii(t) for _ in range(N)]

    def iml(self, N: int, t: type = int):
        return [self.il(t) for _ in range(N)]

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

    def solve(self):
        N = self.ii()
        L = self.il()
        L = list(reversed(sorted(L)))

        ans = 0
        for i, L_0 in enumerate(L):
            for j, L_1 in enumerate(L[i + 1 :]):
                for k, L_2 in enumerate(L[i + j + 2 :]):
                    if not self.is_triangle(L_0, L_1, L_2):
                        break
                    ans += 1
        return ans


if __name__ == "__main__":
    solver = Solver()
    print(solver.solve())

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

    
print(ans)

Submission status: Time Limit Exceeded

Solution code:

import itertools
 
N = int(input())

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

ans = 0

li = sorted(li,reverse=True)

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

print(ans)

Submission status: Time Limit Exceeded

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

i=1
j=0
k=0
ta=0
rb=0
tc=0
cnt=0
m=0

aa=[]
bb=[]
c=[]
for i in range(len(l)*(len(l)-1)):
    # if i%(n)!=0:
    j = int(i/n)
    k = n*(j)+i%n-n*j
    # aa.append(j)
    # bb.append(k)
    # c.append(i)
    if j < k:
        for m in range(k+1,len(l)):
            if l[m] < l[j]+l[k] and l[j]<l[m]+l[k] and l[k]<l[m]+l[j]:
                cnt+=1
print(cnt)
# print(aa)
# print(bb)
# print(c)
#
#

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline())
L = [int(x) for x in stdin.readline().rstrip().split()]

L.sort()

tmp = 0

for i in range(N):

    for j in range(N-i-1):
        j = j + i + 1

        for k in range(N-j-1):
            k = k + j + 1

            if L[k] < L[i] + L[j]:
                tmp = tmp + 1
            else:
                break

print(tmp)

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-1):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(N):
#        if h[0] == j or h[1] == j: continue
        if h[1]>=j: continue
        if v > L[j]:
            ans += 1
        else: break

print(ans)

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:pr]
        #print("x:{} y:{}, lx:{}, ly:{} pl:{}, pr:{}, c:{}".format(x, y, lx, ly, pl, pr, c))
        for lz in c:
            if lx + ly > lz:
                if lx + lz > ly:
                    if ly + lz > lx:
                        #print("{} {} {}".format(lx, ly, lz))
                        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())
L = tuple([int(x) for x in sys.stdin.readline().split()])

def tri_able(x, y, z):
    if x+y > z and y+z > x and z+x > y:
        return 1
    else:
        return 0

answer = 0

for i in range(len(L)-2):
    for j in range(i+1, len(L)-1):
        for k in range(j+1,len(L)):
            answer += tri_able(L[i], L[j], L[k])
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
import itertools

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

cnt = 0

for v in itertools.combinations(L, 3):
    a = int(v[0])
    b = int(v[1])
    c = int(v[2])

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split(" ")))
l.sort()
l.reverse()
cnt = 0 
flag = False
for i in range(0,n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        if i == j:
            continue
        for k in range(j+1,n):
            if i == k and j == k:
                continue
            c = l[k]
            if a >= b + c:
                break
            if a < b + c and b < a + c and c < a + b:
                cnt+=1
            else:
                flag=True
                break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from itertools import islice

N = int(input())
List=list(map(int,input().split()))
List.sort(reverse=True)
flag = True
while flag:
    if len(List) <= 2:
        print(0)
        exit()
    if List[0] > List[1]+List[2]:
        List = List[1:]
    else:
        flag = False
list_que = deque(List)
sum_value = 0
while len(list_que) >= 3:
    Max_value = list_que.popleft()
    while len(list_que) >= 2 and int(list_que[0]) > Max_value/2:
        for i,v in enumerate(list_que):
            for v2 in list(islice(list_que,i+1,len(list_que))):
                if Max_value < v + v2:
                    sum_value += 1
                else:
                    break
        list_que.popleft()
print(sum_value)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def hoge(a):
    if max(a) * 2 - sum(a) < 0:
        return True
    else:
        return False


input()
ans = 0
l = list(map(int, raw_input().split(" ")))
for i in itertools.combinations(l, 3):
    if hoge(i):
        ans += 1
print ans

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
def solve(x, y, z):
    if x < y+z and y < z+x and z < x+y:
        return True
    else:
        return False
counter = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for s in range(j+1,n):
            if solve(l[i],l[j],l[s]):
                counter += 1
            else:
                break
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools

num = int(input())
cmlist = input().split(' ')
count = 0
for i,j,k in itertools.combinations(cmlist, 3):
  if int(i)<int(j)+int(k) and int(j)<int(i)+int(k) and int(k)<int(i)+int(j):
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[int(i) for i 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(j+1,N):
            if L[i]<L[j]+L[k]:
                ans+=1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = input()

a = int(a)

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

b.sort()

from itertools import combinations

comb = combinations(b, 3)

possible_triangles = 0

first_num = -1
second_num = -1

skip = False

for i in comb:
    if skip:
        if i[0] == first_num and i[1] == second_num:
            continue
        else:
            skip = False
    if i[2] >= i[0] + i[1]:
        first_num = i[0]
        second_num = i[1]
        skip = True
        continue
    possible_triangles += 1

print(possible_triangles)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
input = sys.stdin.readline
n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1,n-1):
    for j in range(i+1,n):
        if l[j] - l[i] >= l[i-1]:
            break
        elif i - bisect.bisect_right(l,(l[j]-l[i])) > 0:
            ans += i - bisect.bisect_right(l,(l[j]-l[i]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as C


N = int(input())
Ls = [i for i in map(int, input().split())]

S = sum(True if max(abc) < sum(abc) - max(abc)
        else False
        for abc in C(Ls, 3))

print(S)

Submission status: Time Limit Exceeded

Solution code:

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

r = [0]
def he( l, r):
    m = {}    
    s = []
    t = [0] * 3
    for i in range(len(l)):
        num = l[i]
        t[0] = num
        for j in range(i+1, len(l)-1):
            t[1] = l[j]
            tm = t[0] + t[1]
            ks = j + 1
            if  tm in m:
                ks = m[tm]
                                
            for k in range(ks,  len(l)):
                t[2] = l[k]
                a, b, c = t[0], t[1], t[2]
                if a < b + c and b < a + c and c < b + a:
                    m[a+b] = k
                    r[0] += 1
                    
L = sorted(L, reverse=False)
he(L, r)
print(r[0])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0

for a,b,c in itertools.combinations(li, 3):
    if (a < b+c) and (b < c+a) and (c < a+b):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(num):
  for j in range(i+1, num):
    for k in range(j+1, num):
      if lines[i] < lines[j] + lines[k]:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

L.sort()

num_triangles = 0
for i in range(0, N - 2): # 0, 1, ..., N - 3
    for j in range(i + 1, N - 1): # i+1, i+2, ..., N-2
        for k in range(j + 1, N):
            if L[i] + L[j] <= L[k]:
                break
            else:
                num_triangles += 1

print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
import math
import bisect
import copy

n = int(input())

list1 = list(map(int,input().split()))
list1.sort()
cout = 0
m,k = 0,0
while True:
	if m >= n-2:
		break
	o = list1.pop(0)
	list1_c = copy.deepcopy(list1) #ここでjのためのdeepcopyを更新
	while True:
		if k >= len(list1)-1:
			break
		p = list1_c.pop(0)

		a = abs(o-p) +1
		b = o+p -1 #<= ではなく<条件に揃える

		c = bisect.bisect_left(list1_c,a)
		d = bisect.bisect_right(list1_c,b)

		if c < d:
			cout += d-c
		k+=1

	k = 0
	m += 1

print(cout)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
lst.append(10**10)
total = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        cnt = 0
        k = j+1
        while lst[j]+lst[i] > lst[k]:
            cnt += 1
            k += 1
        total += cnt
print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lx = list(map(int,input().split()))
lx = sorted(lx)
mm = 0

memo = {}
for c1 in range(n):
    a = lx[c1]
    for c2 in range(c1+1, n):
        ab = lx[c2] + a
        if memo.get((ab, c2+1)) is not None:
            mm += memo[(ab, c2+1)]
            continue
        blob = 0
        for c3 in range(c2+1, n):
            c = lx[c3]
            if ab <= c:
                #print(chunk)
                #if memo.get((ab, c2+1)) is None:
                break
            else:
                blob += 1
        mm += blob
        memo[(ab,c2+1)] = blob

print(mm)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import heapq

N = int(input())
L = list(map(int, input().split()))
heapq.heapify(L)
sum = 0
tri = itertools.combinations(L, 3)
for t in tri:
    a, b, c = map(int, t)
    if(a + b > c and b + c > a and c + a > b):
        sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
L = np.array([int(i) for i in input().split()])
L = np.sort(L)

result = 0

for i in range(N):
  for j in range(i+1,N-1):
    tmp = L[j+1::]
    result += sum(x<(L[i]+L[j]) and x>(L[j]-L[i]) for x in tmp)

print(result)

Submission status: Time Limit Exceeded

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

L = sorted(L)
ans = 0
for i in range(N - 2):
    for j in reversed(range(i + 2, N)):
        k = j - 1
        while L[k] > L[j] - L[i] and k > i:
            ans += 1
            k -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

stick_number = int(input())
sticks = list(map(int, input().split()))
sticks.sort() ## 小さい順に並べ直す

## print(stick_number)
## print(sticks)
result = 0

i1 = list(itertools.combinations(sticks, 3))
# print(len(i1))
for j in i1:
  if abs(j[1] - j[2]) < j[0] < j[1] + j[2]:
    result += 1
    
print(result)

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):
  A = L[i]
  break_number = i+2
  for j in range(i+1,N-1):
    B = L[j]
    for k in range(break_number,N):
      if L[k] >= A + B:
        cnt += k - j - 1
        break_number = k
        break
      if k == N-1:
        cnt += N - 1 - j
        break_number = k
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().strip().split()))
l.reverse()
ans = int(0)
for i in range(n-2):
    for k in range(n-2):
        for m in range(n-2):
            if i < k + 1 and k < m + 1:
                if l[i] < l[k+1] + l[m+2] and l[k+1] < l[i] + l[m+2] and l[m+2] < l[i] + l[k+1]:
                    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): 
    ans += sum([1 for k in L[j+1:] if abs(L[j]-L[i]) < k < L[j]+L[i]])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

Lsorted = sorted(L,reverse=True)
Lrev = Lsorted[::-1]

ret = 0
cnt = 0
for i in range(N):
  a = Lsorted[i]
  x = a / 2
  b_max_idx = bisect.bisect_left(Lrev, x)
  for j in range(i+1,N-b_max_idx):
    b = Lsorted[j]
    x = a - b
    c_max_idx = bisect.bisect_left(Lrev, x)

    for k in range(j+1, N-c_max_idx):
      
      c = Lsorted[k]
#      print(a,b,c)
#      cnt += 1
      
      if c >= (a + b):
        break
      if b >= (a + c):
        break
      if a >= (b + c):
        break
      
      ret += 1
print(ret)
#print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys


def main():
    input = sys.stdin.readline
    n = int(input())
    L = map(int, input().split())
    cnt = 0

    ls = itertools.combinations(L, 3)

    for l in ls:
        if sum(l) > max(l)*2:
            cnt += 1

    print(cnt)


if __name__ == '__main__':
    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):
            s_ab = L[i] + L[j]
            cnt += len([l for l in L[j+1:] if l < s_ab])
    print(cnt)


# Generated by 1.1.5 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 = sorted([int(next(tokens)) for _ in range(N)]) # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

count = 0
for i1 in range(N-2):
    for i2 in range(i1+1, N-1):
        for i3 in range(i2+1, N):
            if L[i1] < L[i2]+L[i3] and L[i2] < L[i3]+L[i1] and L[i3] < L[i1]+L[i2]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

sum = 0
for i,k in enumerate(L):
  for j in range(i+1, N):
    for l in range(j+1, N):
      if L[l] < L[j] + k:
        sum += 1
      else:
        break;
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left,bisect_right

n=int(input())
l=sorted(list(map(int,input().split())))
cnt=0
for i in range(n):
    for j in range(i+1,n):
        MIN=abs(l[i]-l[j])
        MAX=l[i]+l[j]
        min_idx=bisect_right(l,MIN)
        max_idx=bisect_left(l,MAX)
        min_idx=max(min_idx,j+1)
        res=max_idx-min_idx
        if res<0:continue
        if min_idx<=i<=max_idx:res-=1
        if min_idx<=j<=max_idx:res-=1
        cnt+=(max(res,0))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
a = list(map(int,input().split()))
b = list(itertools.combinations(a,3))
ans = 0
for i in range(len(b)):
  q = b[i][0]
  w = b[i][1]
  e = b[i][2]
  if (q < w+e) & (w < q+e) & (e < w+q):
    ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
ans = 0
L.sort(reverse = True)
for i,j,k in list(itertools.combinations(L,3)):
    if i < j+k:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

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={}
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 = copy.deepcopy(Lcopy)
        Lcopy2.remove(high)
        
        high=L[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

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
input = sys.stdin.readline
n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1,n-1):
    for j in range(i+1,n):
        if l[j] - l[i] >= l[i-1]:
            break
        elif i - bisect.bisect_right(l[:i-1],(l[j]-l[i])) > 0:
            ans += i - bisect.bisect_right(l[:i-1],(l[j]-l[i]))
print(ans)

Submission status: Time Limit Exceeded

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

L=np.array(L)

M=0
for i in range(len(L)):
    for j in range(i+1,len(L)):
            M+=np.count_nonzero((L[j+1:]>L[i]-L[j])&(L[j+1:]>L[j]-L[i])&(L[j+1:]<L[j]+L[i]))
print(M)

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
from scipy import special

n = int(input())
poll_list = list(map(int,input().split()))
# strings = list(map(str, [input() for i in range(amount)]))

poll_list.sort()
# print(poll_list)
pat = 0
# for i in range(2,n):
#     if poll_list[i] < poll_list[i-2] + poll_list[i-1]:
#         pat += 1 

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if poll_list[k] < poll_list[i] + poll_list[j]:
                # print(str(poll_list[i])+str(',')+str(poll_list[j])+str(',')+str(poll_list[k])+str(','))
                pat += 1
            else:
                break

print(pat)

# pat2 = special.comb(pat, 3, exact = True)
# print(pat2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
# index: 0,...,N-1

ans = 0
print(sum(bisect.bisect_left(Ls[j+1:], J + I) for i,I in enumerate(Ls[:-2]) for j,J in enumerate(Ls[i+1:-1], start=i+1)))
    # i: 0,...,N-3
    # j: i+1,...,N-2
    # k: j+1,...,N-1

Submission status: Time Limit Exceeded

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

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

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:
        if b<c+a:
            if c<a+b:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

L.sort()

buff = []
ll = []


for i in range(N):
    l_b = []
    for j in range(i+1, N):
        l_b.append(L[i]+L[j])
        ll.append(L[i]+L[j])
    if i != N-1:
        buff.append(l_b)
# buff.sort()
# print(L)
# print(buff)

ans = 0
_len = len(buff)

for i in range(_len):
    for j in range(len(buff[i])):
        index = bisect.bisect_left(L[i+j+1+1:], buff[i][j])
        # print(L[i+j+1+1:])
        # print(index, buff[i][j])
        ans += index
print(ans)


# for i in range(N):
#     index = bisect.bisect_left(buff, L[i])
#     print(index)
#     ans += index
# print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=list(map(int, input().split()))
S.sort(reverse=True)
count=0
for i in range(n-2):
    for j in reversed(range(i+2,n)):
        for k in reversed(range(i+1,j)):
            if(S[i]>=S[j]+S[k]):
                count=count+1
            else:
                break
print(int(n*(n-1)*(n-2)/6-count))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
ans = 0
L.sort(reverse = True)
try:
    while L[0] >= L[1]  + L[2]:
        del L[0]
except:
    pass
for i,j,k in list(itertools.combinations(L,3)):
    if i < j+k :
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = sorted([int(item) for item in input().split(' ')])
count = 0

def binary_search(count, a, b, l):
    if len(l) == 0:
        return count
    center = len(l) // 2
    if a + b > l[center]:
        count += center + 1
        return binary_search(count, a, b, l[center+1:])
    else:
        return binary_search(count, a, b, l[:center])


for i in range(N):
    for j in range(i + 1, N):
        l_remained = l[j + 1:]
        count = binary_search(count, l[i], l[j], l_remained)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L_list =  sorted(list(map(int,input().split())),reverse=True)
#print(L_list)
result =0

for i in range(N):
    for j in range(i+1,N):
        if L_list[i] > L_list[j] * 2:
            break
        for k in range(j+1,N):
            if L_list[i] >= L_list[j] + L_list[k]:
                break
            elif L_list[i] < L_list[j] + L_list[k] and \
                    L_list[j] < L_list[k] + L_list[i] and \
                    L_list[k] < L_list[i] + L_list[j]:
                #print(i,j,k)
                result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
L = np.sort(np.array(list(map(int, input().split(" ")))))[::-1]

cnt = 0
for i in range(0, len(L)-2):
    l1 = L[i]
    rest = L[i+1:]
    for i2 in range(0, len(rest)-1):
        l2 = rest[i2]
        rest2 = rest[i2+1:]
        if sum(rest2 > l1 - l2) == 0:
            break
        else:
            cnt += sum(rest2 > l1 - l2)

print(cnt)

Submission status: Time Limit Exceeded

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

m1 = [[ x+y for y in Ls] for x in Ls]
m2 = [[ abs(x-y) for y in Ls] for x in Ls]

c = 0
for i, l in enumerate(Ls):
    for j in range(N):
        if i >= j:
            continue
        for k in range(N):
            if j <= k:
                continue
            if i >= k:
                continue
            if m1[j][k] > l and m2[j][k] < l:
                c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import itertools
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
from collections import Counter


def solve(N: int, L: "List[int]"):
    ans = 0
    L.sort()

    for x in range(N):
        for y in range(N):
            if x==y : continue
            zs = bisect_right(L, max(L[x],L[y]))
            ze = bisect_left(L, L[x]+L[y])            
            cnt = 0
            if(zs <= x <= ze):
                cnt += 1
            if(zs <= y <= ze):
                cnt += 1
            ans += ((ze-zs)-cnt)

    print(ans//2)

    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:
from itertools import combinations

import numpy as np

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


Ls = np.asarray(list(combinations(Ls, 3)))


print(
    sum(
        ((Ls[:, 1] + Ls[:, 2] - Ls[:, 0]) > 0)
        & ((Ls[:, 0] + Ls[:, 1] - Ls[:, 2]) > 0)
        & ((Ls[:, 2] + Ls[:, 0] - Ls[:, 1]) > 0)
    )
)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import itertools

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

t = list(itertools.combinations(l,3))

ans = 0

for i in range(len(t)):
	tmp = list(t[i])
	tmp.sort()
	if tmp[0] + tmp[1] > tmp[2]:
		ans += 1

print(ans)

Submission status: Time Limit Exceeded

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


for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        for k in range(j+1, n):
            c = l[k]
            if c<b+a:
                num = num + 1
            else:
                break



print(num)

Submission status: Time Limit Exceeded

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

ans = round(n*(n-1)*(n-2)/6)
b=0

l.sort()

for i in range(n):
    for j in range(i+1,n):
        b = l[i] + l[j]
        for k in range(n):
            if b<=l[n-k-1]:
                ans-=1
            else:
                break

if ans<0:
    ans=0

print(ans)

Submission status: Time Limit Exceeded

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

count = 0
head = 0

for i in range(N):
    a = L[i]
    for j in range(1,N-i):
        b = L[i+j]
        for c in L[i+j+1:]:
            # print(a,b,c)
            if a < b+c and b < c+a and c < a+b:
                count+=1
                # break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
tri=[[0 for i in range(3)]for j in range(int((N*(N-1)*(N-2))/6))]
num=0

for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            tri[num][0]=L[i]
            tri[num][1]=L[j]
            tri[num][2]=L[k]
            
            num+=1

flag=0

for i in range(0,int((N*(N-1)*(N-2))/6)):
    if tri[i][0]<(tri[i][1]+tri[i][2]) and tri[i][1]<(tri[i][2]+tri[i][0]) and tri[i][2]<(tri[i][0]+tri[i][1]):
        flag+=1
        
print(flag)