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 bisect
import itertools

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

cnt = 0

for i in range(N):
    L_t = L[i+1:N]
    for v in itertools.combinations(L_t, 2):
        a = int(L[i])
        b = int(v[0])
        c = int(v[1])

        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()
c=[]
for i in range(2**n):
  tmp=[]
  for j in range(n):
    if i>>j&1:
      tmp.append(L[j])
  if len(tmp)==3 and tmp not in c:
    c.append(tmp)
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:
# -*- coding: utf-8 -*-

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

L.sort()

count = 0

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



print(str(count))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

L = sorted(L)
# print(L)

ans = 0

# all_end = False
# next_a = False
# for a in range(N):
#     if all_end:
#         break
#     for b in range(a+1, N):
#         if next_a:
#             next_a = False
#             break
#         for c in range(N-1, b, -1):
#             print("{} {} {} / ans: {}".format(L[a], L[b], L[c], ans))
#             if L[a] + L[b] > L[c]:
#                 ans += 1
#             else:
#                 if c == N-1:
#                     next_a = True
#                     if b == a+1:
#                         all_end = True
#                 break

all_end = False
next_a = False
for a in range(N):
    if all_end:
        break
    for b in range(a+1, N):
        if next_a:
            next_a = False
            break
        for c in range(b+1, N):
            # print("{} {} {} / ans: {}".format(L[a], L[b], L[c], ans))
            if L[a] + L[b] > L[c]:
                ans += 1
                if c == N-1:
                    if b == a+1:
                        next_a = True
                        all_end = True
                        ans += (N-b-2)*(N-b-1)//2
                        # print(ans)
                        # x = N - 3 - a
                        x = N - 3
                        # print(a, b)
                        # ans += ((x*(x*1)*(2*x+1)//6) + ((2*a-2*N+3)*x*(x+1)//2) + ((N**2)+(a**2)-2*N*a-3*N+3*a+2)*x) // 2
                        former = (x * (x+1) * (2*x+1)) // 6 + (3 - 2*N) * x * (x+1) // 2 + (1-N) * (2-N) * x
                        latter = (a * (a+1) * (2*a+1)) // 6 + (3 - 2*N) * a * (a+1) // 2 + (1-N) * (2-N) * a
                        ans += (former - latter) // 2
                        # print(ans)
                        break
                    next_a = True
                    ans += (N-b-2)*(N-b-1)//2
                    break
            else:
                # if c == b+1:
                #     next_a = True
                #     if b == a+1:
                #         all_end = True
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split(" ")))
L.sort() #小さい順
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]:
        break
      else:
        counter += 1
       
print(counter)

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

Submission status: Time Limit Exceeded

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

result = 0

for aIndex,a in enumerate(L):
    for bIndex,b in enumerate(L[aIndex+1:]):
        for c in L[aIndex+bIndex+2:]:
            if a<b+c and b<a+c and c<a+b:
                result+=1

print(result)

Submission status: Time Limit Exceeded

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

#output
import heapq

L = [-l for l in L]
heapq.heapify(L)

sum = 0
while len(L) > 2:
    target = heapq.heappop(L)
    for i in range(len(L)-1):
        for j in range(i+1, len(L)):
            if target > L[i] +  L[j]:
                sum += 1
        
print(sum)

Submission status: Time Limit Exceeded

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

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[j-1:])
        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:
n = int(input())
Ls = list(map(int, input().split()))
cnt = 0


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


for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if check(Ls[i], Ls[j], Ls[k]):
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, *l = map(int, open(0).read().split())
sl = sorted(l,reverse=True)
ans = 0
for i in range (n):
  for j in range (i+1,n):
    for k in range(j+1,n):
      if sl[i]-sl[j]<sl[j] and sl[i]<sl[j]+sl[k]:
        ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[28]:


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


# In[29]:


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


# In[ ]:

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=input()
L=L.split()
L=[int(item) for item in L]
L.sort()
ans=cmb(N,3)
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-=(N-k)
                break


print(int(ans))

Submission status: Time Limit Exceeded

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

lsorted = sorted(l, reverse=True)

for longest in range(len(l)-2):

    for second in range(longest+1, len(l)):
        if lsorted[longest] - 2*lsorted[second] >= 0:
            break 
        for third in lsorted[second+1:]:
            if lsorted[longest] - lsorted[second] - third >= 0:                
                break
            else:
                ans += 1

print(ans)

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]
        if l2 < l1 / 2:
            break
        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:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = sorted(LIST(), reverse=True)

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        flag = 1
        for k in range(N-j):
            if L[i] < L[j] + L[N-k-1]:
                flag = 0
                count += N-k-1-j
                break
        if flag:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:

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

r = [0]
def he( l, r):
    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 < l[ks]:
                continue
                                
            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:
                    r[0] += 1
                    
L = sorted(L, reverse=False)
he(L, r)
print(r[0])

Submission status: Time Limit Exceeded

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


cnt=0
for i in range(n-1):
    for j in range(i+1,n-1):
        for h in range(j+1,n):
            a,b,c=l[i],l[j],l[h]
            if(a<b+c)and(b<a+c)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()))

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


result = 0
for i,s in enumerate(L_list[2:]):
    comb = itertools.combinations(L_list[:i+2], 2)
    for check_t in comb:
        if (check_t[0] + check_t[1]) > s:
            result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
N = str(input())
Lines = input().split(" ")
LinesInt = []
answer = 0

for line in Lines:
    line = int(line)
    LinesInt.append(line)

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

Submission status: Time Limit Exceeded

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

listl.sort(reverse=True)

#print(listl)
ans=0
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]+listl[j+1]<=listl[i]:
			break
		for k in range(j+1,n):
		#	print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    x = ls[i]
    comb = list(itertools.combinations(ls[i+1:], 2))
    for j in range(len(comb)):
        if sum(comb[j]) > x:
            count += 1
print(count)

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):
  for j in range(i+1,n):
    tgt = l[i] - l[j]
    for k in range(j+1, n):
      if l[k] > tgt:
        cnt += 1
      else:
        break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())

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

con = 0

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

for i in range(0,len(edge)):
	a = edge[i][0]
	b = edge[i][1]
	c = edge[i][2]
	total = sum(edge[i])
	if a < b + c and b < a + c and c < a + b:
		con += 1
		
print(con)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

if __name__ == '__main__':
    N = int(input())
    l_list = list(map(int, input().split()))
    l_list.sort()
    count = 0
    for i in range(N):
        for j in range(N):
            if i >= j:
                continue

            shorter_sum = l_list[i] + l_list[j]
            for k in range(j + 1, N):
                if l_list[k] < shorter_sum:
                    count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans=0

def find_gt(a,x):
    i = bisect.bisect_right(a,x)
    if i != len(a):
        return i
    return(-1)

for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        l=L[:j]
        if len(l)>=1:
            num=find_gt(l,L[i]-L[j])
            if num!=-1:
                ans+=len(l)-num
        else:
            continue


print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
n = int(raw_input())
li = map(int, raw_input().split())

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    l_list = list(map(int, input().split()))
    l_list.sort()
    max_l = max(l_list)

    ans = 0
    for i, a in enumerate(l_list):
        for j, b in enumerate(l_list[i+1:]):
            if b - a > max_l:
                break
            for k, c in enumerate(l_list[i+1+j+1:]):
                # if is_ok(a, b, c):
                if c < a + b:
                    ans += 1
                else:
                    break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

#output
import heapq

L = [-l for l in L]
heapq.heapify(L)

sum = 0
while len(L) > 2:
    target = heapq.heappop(L)
    L.sort()
    for i in range(len(L)-1):
        for j in range(i+1, len(L)):
            if target > L[i] +  L[j]:
                sum += 1
        
print(sum)

Submission status: Time Limit Exceeded

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

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

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 i in range(len(C)):
    if C[i][0] < C[i][1] + C[i][2] and C[i][1] < C[i][0] + C[i][2] and C[i][2] < C[i][0] + C[i][1]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n = int(input())
    l = sorted(map(int, input().split()))
    count = 0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if l[k]<l[i]+l[j]:
                    count += 1
                else:
                    break
    print(count)
    
    
if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
#        for line in sys.stdin:
#            lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]
    l = [int(e) for e in lines[1].split(" ")]

    return (n, l)

def solve(n, l):

    l.sort()

    z = []
    last = None
    cnt = 1 
    for i in range(n):
        if l[i] != last:
            z.append((l[i], cnt))
        else:
            z[-1][1] = z[-1][1] + 1

    if debug:
        log("z=%s" % z)

    m = len(z) 
    total_cnt = 0
    for i in range(0, m-2):
        for j in range(i+1, m-1):
            z12_length = z[i][0] + z[j][0]
            z12_cnt = z[i][1] * z[j][1]
            tmp_z3_cnt = 0
            for k in range(j+1, m):

                if debug:
                    log("z[%d][0]=%d, z[%d][0]=%d, z[%d][0]=%d" % (i, z[i][0], j, z[j][0], k, z[k][0]))
                    log("z[%d][1]=%d, z[%d][1]=%d, z[%d][1]=%d" % (i, z[i][1], j, z[j][1], k, z[k][1]))
                    log("tmp_z3_cnt=%d" % tmp_z3_cnt)
                    log("total_cnt=%d" % total_cnt)

                if z[k][0] < z12_length:
                    tmp_z3_cnt = tmp_z3_cnt + z[k][1]
                    if debug:
                        log("tmp_z3_cnt=%d" % tmp_z3_cnt)
                else:
                    break

            total_cnt = total_cnt + z12_cnt * tmp_z3_cnt
            if debug:
                log("total_cnt=%d" % total_cnt)

    return total_cnt 

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
t=0
for i in range(N-2):
    for j in range(i+1,N-1):
        if L[i]<L[j]+L[N-1]:
            t+=N-1-j
        elif L[i]>=L[j]+L[j+1]:
            t+=0
        else:
            l=j+1
            h=N-1
            c=int((l+h)/2)
            while L[i]>L[j]+L[c] or L[i]<L[j]+L[c+1]:
                if L[i]>=L[j]+L[c]:
                    h=c
                    c=int((c+l)/2)
                elif L[i]<=L[j]+L[c+1]:
                    l=c
                    c=int((h+c)/2)
                print(c)
            t+=N-1-c

print(t)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
l = sorted(list(map(int, input().split())))
nl = np.array(l)

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        cnt += sum(nl[j+1:] < a + b)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
c = 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[i] < l[j] + l[k]) and (l[j] < l[i] + l[k]) and (l[k] < l[i] + l[j]):
        c = c + 1
      else:
        break
  else:
    continue
  break
print(c)

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))
    for i in Tri:
        if sum(i)>Ls[t]:
            Ans+=1
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = map(int, input().split())
SL = sorted(list(L))
A = [0] * (10 ** 3 + 10)

for i in SL:
    A[i] = True
for i in range(len(A)):
    if A[i] == True:
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]

# print(A[4-1] - A[2])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        # for k in range(j+1, N):
        #     a = SL[i]
        #     b = SL[j]
        #     c = SL[k]
        #     if a < b + c and b < c + a and c < a + b:
        #         ans += 1
        a = SL[i]
        b = SL[j]
        for k in range(j+1, N):
            c = SL[k]
            if abs(a - b) >= c:
                print('continue')
                continue
            elif c >= a + b:
                break
            else:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Llist.sort(reverse=True)
num = 0
for i in range(N-2):
    for j in range(N-2-i):
        for k in range(N-2-i-j):
            if Llist[i] >= Llist[i+1+j] + Llist[i+2+j+k]:
                break
            else:
                num += 1
        
print(num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

import bisect
ans = 0
for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        t1 = bisect.bisect_right(L,a+b-1)
        t2 = bisect.bisect_right(L,a-b)
        t3 = bisect.bisect_right(L,b-a)
        
        t4 = max(t2,t3)

        if t1!=t4:
            ans += t1-t4
            
        if t4<=i<=t1:
            ans -= 1
        if t4<=j<=t1:
            ans -= 1
        
ans = ans // 3
print(ans)

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):
		for b in range(c - 1, 0, -1):
			for a in range(b - 1, -1, -1):
				if L[a] + L[b] > L[c]:
					# print(a, b, c)
					sum += 1
				else:
					break
	print(sum)

Submission status: Time Limit Exceeded

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

L = sorted(L)

cnt = 0
for c in range(N-2):
    for b in range(c+1, N-1):
        for a in range(b+1, N):
            if L[b]-L[c] >= L[a]:
                continue
            elif L[a] < L[b] + L[c]:
                cnt += 1
                continue
            elif L[a] >= L[a] + L[c]:
                break
            break

print(cnt)

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 reversed(range(i+2,n)):
    k = i+1
    while(k < j):
      if l[j] < l[i]+l[k]:
        ans += j - k
        break
      else:
        k += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
count = 0
L.sort()
#print(L)
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        limit = N
        b = L[j]
        c = L[j+1]

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

        if abs(b-c)<a<b+c:
            count += (limit-1) - j
        #print(a,b,c,i,j,k,"limit=",limit,"count=",count)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = list(map(int, input().split(' ')))
nums.sort(reverse=True)
ans = 0

for i in range(N-2):
    for j in range(i+1, N):
        for l in range(j+1, N):
            if nums[i] < nums[j]+nums[l]:
                ans = ans + 1
            else :
                j = N-1
                l = N-1
print(ans)

Submission status: Time Limit Exceeded

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

L.sort()
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 L[i] < L[j] +L[k] and L[j] < L[k] + L[i]:
                count += 1
            else: 
                break
                
print(count)

Submission status: Time Limit Exceeded

Solution code:

import sys
input=sys.stdin.readline
n = int(input())
a = sorted(list(map(int,input().split())))
res = 0
i = 0
while i < n:
    j = i+1
    while j < n:
        yy = a[i]+a[j]
        for k in range(j+1,n):
            if yy > a[k]:res+=j-i
            else:
                break
        j+=1
    i=j-1
print(res)

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
lst=[]

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

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

Submission status: Time Limit Exceeded

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

L.sort()
tss=[]
for i in range(N-2):
    for j in range(1,N-i):
        tss.append(L[i]+L[i+j])

num=[]
for i in range(1,N-1):
    for j in range(i,N):
        num.append(j)
        
ans=0
for i in range(len(tss)):
    for j in range(num[i]+1,N):
        if tss[i]>L[j]:
            ans+=1
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def hoge(A,B):
    sum = 0
    for i in range(B):
        sum += A
        A -= 1
    return sum

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

L.sort(reverse=True)

List = deque()
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(hoge(N-2,i),len(List)):
        if List[j] > L[i]:
            Sum += 1

print(Sum)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted(list(map(int,input().split())))
count = (n*(n-1)*(n-2))//6
for i in range(n-2):
    for j in range(n-i-2):
        for k in range(n-i-j-2):
            if l[i+j+k+2]>=l[i]+l[i+j+1]:
                count -= n-(i+j+k+2)
                break
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()])

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

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(j+1,n):
            if b>l[k]:
                continue
            else:
                ans-=n-k
                break

if ans<0:
    ans=0

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

num=0
for i in range(N-2):
  for j in range(N-2-i):
    for k in range(N-2-i-j):
      if ((wood[i] < wood[j+i+1] + wood[k+1+i+j+1]) and (wood[j+1+i] < wood[i] + wood[i+j+2+k]) and ((wood[k+i+j+2] < wood[i] + wood[j+1+i]))):
        num += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

input = sys.stdin.readline


def main():
    n = int(input())
    l = map(int, input().split())
    # 種類組み合わせ・条件
    l = sorted(l)
    hoge = []
    for a, b in itertools.combinations(l, 2):
        target = l[:]
        target.remove(a)
        target.remove(b)
        hoge += [sorted([a, b, c]) for c in filter(lambda x: b - a < x < a + b, target)]
    print(len(set(["{}{}{}".format(a, b, c) for a, b, c in hoge])))
    # sum([str(i) for i in


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

b = list(filter(lambda c: c[0] < c[1]+c[2] and c[1] < c[2]+c[0] and c[2] < c[0]+c[1], a))

print(len(b))

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