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:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 20:56:06 2020

@author: liang
"""

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

L.sort()
ans = 0
#print(L)
for i in range(N-2):
    p = i+2
    for j in range(i+1,N-1):
        while p < N and L[p] < L[i] + L[j] :
            p += 1
        ans += len(L[j+1:p])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]
        x = (a+1) - b
        y = (b+1) - a
        z = max(x,y)
        a = j+1
        b = n-1
        c = (a+b) // 2
        while a <= b:
            if l[c] == z:
                a += 1
            elif l[c] > z:
                a = c + 1
            elif l[c] < z:
                b = c - 1
            else:
                pass
            c = (a+b) // 2
        ans += c-j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if l[c]<l[a]+l[b]:
                if l[b]<l[a]+l[c]:
                    if l[a]<l[b]+l[c]:
                        ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if l[a]<l[b]+l[c] and l[b]<l[a]+l[c] and l[c]<l[a]+l[b]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def bisect_left(L,x):
  lo=0
  hi=N
  while lo<hi:
    mid=(lo+hi)//2
    if L[mid]<x: lo=mid+1
    else: hi=mid
  return lo

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    """
    lo=0
    hi=N
    x=a+b
    while lo<hi:
      mid=(lo+hi)//2
      if L[mid]<x: lo=mid+1
      else: hi=mid
    ans+=lo-(j+1) 
    """
    ans+=bisect_left(L,a+b)-(j+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    lo=0
    hi=N
    x=a+b
    while lo<hi:
      mid=(lo+hi)//2
      if L[mid]<x: lo=mid+1
      else: hi=mid
    ans+=lo-(j+1)    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    l=-1
    r=N
    while r-l>1:
      mid=(l+r)//2
      if L[mid]<a+b:
        l=mid
      else:
        r=mid
    ans+=r-(j+1)    
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in combinations(a, 3):
    x, y, z = i[0], i[1], i[2]
    if x < y+z and y < x+z and z < x+y:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = 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 a[i] < a[j]+a[k] and a[j] < a[i]+a[k] and a[k] < a[i]+a[j]:
                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
for i,a in enumerate(L):
  for j,b in enumerate(L[i+1:],start=i+1):
    for k,c in enumerate(L[j+1:],start=j+1):
      if c>=a+b:
        break
      elif b<c+a:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0
for i in range(N):
  for s in range(N):
    for k in range(N):
      if i<s<k and st[i]+st[s]>st[k]:
        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
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=bisect.bisect_left(l[j+1:],l[i]+l[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def is_ok(arg):
    if tmp - l[arg] < 0:
        return True
    return False

def meguru_binary_search(ng, ok):
    while abs(ng - ok) > 1:
        mid = (ng + ok) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

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

l.sort(reverse=True)
l += [0]

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        tmp = l[i] - l[j]
        c = meguru_binary_search(n, j)
        if c == j:
            break
        ans += c-j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def is_ok(arg):
    if l[arg] < tmp_sum:
        return True
    return False

def meguru_binary_search(ng, ok):
    while abs(ng - ok) > 1:
        mid = (ng + ok) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

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

l.sort()
l += [1001001001]

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        tmp_sum = l[i] + l[j]
        c = meguru_binary_search(n, j)
        ans += c-j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    l = i_list()
    l.sort()
    ans = 0
    for i in range(len(l)):
        for k in range(i+1,len(l)):
            for u in range(k+1,len(l)):
                a = l[i]
                b = l[k]
                c = l[u]
                if b < a+c and c < a+b:
                    ans += 1
                if a+b < c:
                    break
    print(ans)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

# a, bをfixしてcを探索
# n*n*logn
# c_i < a+b をにぶたん
def binary_search(list, item):
    # listからitem未満の最大のindexを取得
    low = 0
    high = len(list) - 1
    if list[high] < item:
        return high+1
    if list[low] >= item:
        return low
    while True:
        mid = (low + high) //2
        guess = list[mid]
        if high - low <= 1:
            return high
        if guess >= item:
            high = mid
        else:
            low = mid

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        a = l[i]
        b = l[j]
        c = binary_search(l, b+a)
        ans += c-(j+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
for a in range(N):
    for b in range(a+1,N):
        for c in range(a):
            if arr[a] < arr[b] + arr[c] and arr[b] < arr[c] + arr[a] and arr[c] < arr[a] + arr[b]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

def findNumberOfTriangles(arr, n): 
	count = 0
	
	
	 
	for i in range(n): 
		for j in range(i + 1, n): 
			
			
			
			for k in range(j + 1, n): 
				
				 
				 
				if (arr[i] + arr[j] > arr[k] and
					arr[i] + arr[k] > arr[j] and
					arr[k] + arr[j] > arr[i]): 
					count += 1
	return count 
n=int(input())
li = [int(x) for x in input().split()]

print( findNumberOfTriangles(li, len(li)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n=int(input())
li=[int(x) for x in input().split()]
l = list(range(n))
s = combinations(l,3)

d=0
for a,b,c in list(s):
    if li[a]<(li[b]+li[c]):
        if li[b]<(li[a]+li[c]):
            if li[c]<(li[b]+li[a]):
                d=d+1
print(d)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
li=[int(x) for x in input().split()]
from itertools import combinations
l = list(range(n))
s = combinations(l,3)
s=list(s)
d=0
for a,b,c in s:
    if li[a]<(li[b]+li[c]):
        if li[b]<(li[a]+li[c]):
            if li[c]<(li[b]+li[a]):
                d=d+1
            else:
                pass
        else:
            pass
        
    else:
        pass
print(d)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
li=[int(x) for x in input().split()]
from itertools import combinations
l = list(range(n))
s = combinations(l,3)
s=list(s)
d=0
for a,b,c in s:
    if li[a]<(li[b]+li[c]) and li[b]<(li[a]+li[c]) and li[c]<(li[b]+li[a]):
        d=d+1
    else:
        pass
print(d)

Submission status: Time Limit Exceeded

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

l.sort()
ans=0
import itertools
# (1,2,3),(1,2,4),---,(7,8,9)
for seq in itertools.combinations(range(len(l)),3):
    if l[seq[0]]+l[seq[1]]>l[seq[2]]:ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools   # accumulate, compress, permutations(nPr), combinations(nCr)
# import bisect      # bisect_left(insert位置), bisect_right(slice用)
# import math        # factorical（階乗) # hypot(距離)
# import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
from math import gcd # Python3.6以降
# --------------------------------------------------------------

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

cnt = 0

for i in itertools.combinations(bo,3):
    if i[0]<i[1]+i[2] and i[1]<i[2]+i[0] and i[2]<i[0]+i[1]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# 問題：https://atcoder.jp/contests/abc143/tasks/abc143_d

n = int(input())
l = list(map(int, input().strip().split()))
res = 0
for i in range(2, n):
    a = l[i]
    for j in range(1, i):
        b = l[j]
        for k in range(j):
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

comb = combinations(l, 3)
ans = 0

for a, b, c in comb:
    if a < b+c and b < c+a and c < a+b:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
str_line = input().split(" ")
num_line = [int(n) for n in str_line]

num_line.sort()
#print(num_line)
result = 0

for i in range(num - 2):
    for j in range(i + 1, num - 1):
        k = j + 1        
        c = 0
        while (c==0)and(k < num) :
            if(num_line[i] + num_line[j] > num_line[k]):
                result += 1
                k += 1
            else:
                c = 1
        
            
print(result)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
str_line = input().split(" ")
num_line = [int(n) for n in str_line]

num_line.sort()
#print(num_line)
result = 0

for i in range(num - 2):
    for j in range(i + 1, num - 1):
        for k in range(j + 1, num):
            if(num_line[i] + num_line[j] > num_line[k]):
                result += 1
            
print(result)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = 0
for i in range(a-2):
  for j in range(i+1,a-1):
    for k in range(j+1,a):
      if b[i] < b[j]+b[k] and b[j] < b[k]+b[i] and b[k] < b[i]+b[j]:
        c += 1
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))
A = 0
for i in C:
	a = i[0]
	b = i[1]
	c = i[2]
	if a < b + c and b < c + a and c < a + b:
	 A += 1
print(A)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

b = list(itertools.combinations(l, 3))
for j in range(len(b)):
  c = b[j]
  if c[1] < c[2] + c[0] and c[2] < c[1] + c[0] and c[0] < c[2] + c[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):
    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[k]+L[i] and L[k]<L[i]+L[j]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/08/27

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  L=list(map(int,pin().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
  print(ans)
  return 

main()

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/08/27

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  L=list(map(int,pin().split()))
  ans=0
  for i in range(N):
    for j in range(i+1,N):
      for k in range(j+1,N):
        if abs(L[i]-L[j])<L[k] and L[k]<L[i]+L[j]:
          ans+=1
  print(ans)
  return 

main()

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):
#     L_count[L[i]] += 1

for i in range(N-1):
    for j in reversed(range(i + 2, N)):
        for k in range(i + 1, j):
            if 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 = list(map(int, input().split()))
L.sort()

L_count = [0] * (max(L)+1)

ans = 0

for i in range(N):
    L_count[L[i]] += 1

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

triangle = itertools.combinations(l, 3)

cnt = 0

for i in triangle:
  if max(i)*2 < sum(i):
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
Alist = list(map(int,input().split()))
Alist.sort()
Answer = 0
Amax = Alist[-1]
def judge(a,b,c):
    if a < b+c:
        return True
    else:
        return False
for i in range(0,N-2):
    for j in range(i+1,N-1):
        c = Alist[i]
        b = Alist[j]
        if judge(Amax,b,c) == True:
            Answer += (N-j)-1
        else:
            kins = -1
            for k in range(j+1,N):
                a = Alist[kins]
                if judge(a,b,c) == True:
                    Answer += N-(j+1)-k+2
                    break
                else:
                    kins -= 1
print(Answer)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
l=list(map(int,input().split()))
c=itertools.combinations(l,3)
ans=0
for i in c:
  if 2*max(i) < i[0]+i[1]+i[2]:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from bisect import bisect_left

n = int(input())
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
    l_a = ld.popleft()
    for b in range(a + 1, n - 1):
        cnt += bisect_left(l[b + 1 :], l_a + l[b])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

input()
l = sorted(map(int, input().split()))
print(sum(a + b > c for a, b, c in combinations(l, 3)))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

n = int(input())
l = sorted(map(int, input().split()))
cnt = 0
for a in range(n - 2):
    for b in range(a + 1, n - 1):
        cnt += bisect_left(l[b + 1 :], l[a] + l[b])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = sorted(map(int, input().split()))
cnt = 0
for a in range(n - 2):
    for b in range(a + 1, n - 1):
        for c in range(b + 1, n):
            if l[a] + l[b] > l[c]:
                cnt += 1
            else:
                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 range(i + 1, n - 1):
        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:
n=int(input())
l=sorted(map(int, input().split()))
count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        l1=l[j+1:]
        p=l[i]+l[j]
        l1.append(p)
        l1.sort()
        count+=l1.index(p)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=sorted(map(int, input().split()))
count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for h in range(j+1,n):
            if l[h]<l[i]+l[j]:
                count+=1
            else:
                pass
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
l = list(int(i) for i in input().split())

cnt = 0

for bars in combinations(l, 3):
    a,b,c = bars[0], bars[1], bars[2]
    if a < b + c and b < a + c and c < b + a:
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(n-1, -1, -1):
    for j in range(i-1, -1, -1):
        imin = 0
        imax = j-1

        while imin <= imax:
            mid = (imin + imax)//2
            if l[mid] + l[j] >= l[i]+1:
                imax = mid-1
            else:
                imin = mid+1

        cnt += j-imin

print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n - 2):
    a = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        c_min = b - a
        c_max = a + b
        if c_max > c_min + 1:
            l = L[j+1:]
            i_min = bisect.bisect_right(l, c_min)
            i_max = bisect.bisect_left(l, c_max)
            ans += i_max-i_min
print(ans)

Submission status: Time Limit Exceeded

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

d = dict()
ans_set = dict()
for a in range(n-1):
    for b in range(a+1, n):
        d[(a, b)] = l[a] + l[b]

for k, v in d.items():
    c = 0
    a, b = k
    while True:
        if c >= n or l[c] >= v:
            break
        if c != a and c != b:
            if l[a] < l[b]+l[c] and l[b] < l[c]+l[a]:
                ans_set[tuple(sorted((a, b, c)))] = 1
        c+= 1
print(len(ans_set))

Submission status: Time Limit Exceeded

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

if n <= 2:
    print(0)
else:
    cnt = 0

    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                l = sorted([li[i], li[j], li[k]])

                if l[0] + l[1] > l[2]:
                    cnt += 1

    print(cnt)

Submission status: Time Limit Exceeded

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

l.sort(reverse=True)
ans=0

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

Submission status: Time Limit Exceeded

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

l.sort(reverse=True)
ans=0

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n=int(input())
a=list(map(int,input().split()))
c=0
for x in combinations(a,3):
    if x[0]!=x[1] and x[1]!=x[2] and x[2]!=x[0]:
        if x[0]<x[1]+x[2] and x[1]<x[0]+x[2] and x[2]<x[0]+x[1]:
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
ans = 0
for c in range(N):
    for cc in range(c + 1, N):
        for ccc in range(cc + 1, N):
            ab = L[c]
            bb = L[cc]
            cb = L[ccc]
            if ab < (bb + cb) and bb < (ab + cb) and cb < (ab + bb):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#それゆけにぶたんまん
n = int(input())
l = sorted(list(map(int,input().split())))

ans = 0
for i in range(n):
    for j in range(i+1,n):
        #jより大きい整数kでl[k]<l[i]+l[j]を満たす最大のk
        le = j
        ri = n
        while ri-le>1:
            m = (ri+le)//2
            if l[m]<l[i]+l[j]:
                le = m
            else:
                ri = m
        ans += le-j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#愚直にn^3
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):
            len = l[i]+l[j]+l[k]
            ma = max(l[i],max(l[j],l[k]))
            rest = len-ma
            if ma < rest:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 小さいのを2つ選んで最後の1つをにぶたん
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ok, ng = j, n
        while (ng - ok) > 1:
            mid = (ng + ok) // 2
            if l[i] + l[j] > l[mid]:
                ok = mid
            else:
                ng = mid
        ans += ok - j
print(ans)

Submission status: Time Limit Exceeded

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

def solve(L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                cnt += a+b > L[k]
    return cnt
print(solve(L))

Submission status: Time Limit Exceeded

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

@njit
def solve(N, L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                cnt += a+b > L[k]
    return cnt
print(solve(N, L))

Submission status: Time Limit Exceeded

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

@njit
def solve(N, L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                if a+b > L[k]:
                    cnt += 1
    return cnt
print(solve(N, L))

Submission status: Time Limit Exceeded

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

#@njit
def solve(N, L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                if a+b > L[k]:
                    cnt += 1
    return cnt
print(solve(N, L))

Submission status: Time Limit Exceeded

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

@njit
def solve(N, L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                c = L[k]
                if b > c and a < b+c:
                    cnt += 1
    return cnt
print(solve(N, L))

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):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        for k in range(j+1, N):
            c = L[k]
            if b > c and a < b+c:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
for l in L:
    l = list(l)
    m = max(l)
    l.remove(m)
    if m < sum(l):
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

cmb = list(combinations(L,3))
ans = 0

for v in cmb:
    a = v[0]
    b = v[1]
    c = v[2]
    
    if a < b + c and b < c+a and c < a+b:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

import numba as nb

input = sys.stdin.readline


@nb.njit("i8(List(i8, reflected=True),i8)", cache=True)
def binary_search(a, key):
    """Meguru type binary search"""
    ok = -1
    ng = len(a)

    def is_ok(a, key, idx):
        if a[idx] < key:
            return True
        else:
            return False

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(a, key, mid):
            ok = mid
        else:
            ng = mid

    return ok


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

    L.sort()
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            x = binary_search(L, L[a] + L[b])
            ans += (x - b)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def binary_search(a, key, low, high):
    ok = low
    ng = high
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if a[mid] < key:
            ok = mid
        else:
            ng = mid
    return ok


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

    L.sort()
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            x = binary_search(L, L[a] + L[b], low=0, high=N)
            ans += (x - b)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def binary_search(a, key, low, high):
    ok = low
    ng = high
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if a[mid] < key:
            ok = mid
        else:
            ng = mid
    return ok


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

    L.sort()
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            x = binary_search(L, L[a] + L[b], low=b, high=N)
            ans += (x - b)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

l = sorted(l, reverse=False)
#logging.debug(l)
ans = 0
#import itertools
#for j in itertools.combinations(l, 3):
#    logging.debug(j)
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
#            if b - a >= c:
#                logging.debug("{},{},{},×".format(a,b,c))
#                continue
            if l[k] >= l[i] + l[j]:
#                logging.debug("{},{},{},ばつ".format(a,b,c))
                break
#            logging.debug("{},{},{},○".format(a,b,c))
            ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

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

l = sorted(l, reverse=False)
#logging.debug(l)
ans = 0
#import itertools
#for j in itertools.combinations(l, 3):
#    logging.debug(j)
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            a, b, c = l[i],l[j],l[k]
#            if b - a >= c:
#                logging.debug("{},{},{},×".format(a,b,c))
#                continue
            if c >= a + b:
#                logging.debug("{},{},{},ばつ".format(a,b,c))
                break
#            logging.debug("{},{},{},○".format(a,b,c))
            ans += 1
        
print(ans)