Problem:


Score : 400 points

Problem Statement

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

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

a < b + c

b < c + a

c < a + b

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

Constraints

All values in input are integers.

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

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

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

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        s = [x for x in l[j+1:] if x < l[i] + l[j]]
        for c in s:
            if c + l[i] > l[j] and c + l[j] > l[i] :
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0

for a in L:
    L2 = copy.deepcopy(L)
    L2.remove(a)
    for b in L2:
        L3 = copy.deepcopy(L2)
        L3.remove(b)
        for c in L3:
            if a<b+c and b<c+a and c<a+b:
                cnt+=1
print(cnt//6)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(input().split())
L=[]
for a in A:
  L.append(int(a))
L.sort(reverse=True)
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
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(input().split())
L=[]
for a in A:
  L.append(int(a))
L.sort(reverse=True)
count=0
for i in range(N):
  for j in range(1,N):
    for k in range(2,N):
      if i<j and j<k:
        if L[i]<L[j]+L[k]:
          count+=1
        else:
          continue
    else:
        continue
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(input().split())
L=[]
for a in A:
  L.append(int(a))
count=0
for i in range(N):
  for j in range(1,N):
    for k in range(2,N):
      if i<j and j<k:
        if L[i]<L[j]+L[k]:
          if L[j]<L[i]+L[k]:
            if L[k]<L[i]+L[j]:
              count+=1
            else:
              continue
          else:
            continue
        else:
          continue
    else:
        continue
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# 1~9の長さの棒が9本あったとして、
# a = 3, b= 6のとき、c = 5も満たすが、これはa,bを固定し回したとき
# すでにa=3,B=5,c=6で、同じ三角形が洗い出せている
# 上記の重複を防ぐため、b < cという条件が必要


def is_ok(a, b, mid):
    A = sticks[a]
    B = sticks[b]
    C = sticks[mid]
    if B < C and C < A + B:
        return True
    else:
        return False


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

sticks = sorted(ls)  # O(NlogN)

# O(N**2)
# 必要な条件は、b < c < a+b
sticks_len = len(sticks)

count = 0
# rangeの幅を考えよう
for a in range(sticks_len-2):
    for b in range(a+1, sticks_len-1):
        ok = b
        ng = n
        mid = (ok + ng) // 2  # インデックスの平均をとり
        while ng - ok > 1:
            if is_ok(a, b, mid):  # okかngかを判別する
                ok = mid
            else:
                ng = mid
        count += ng - (b+1)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

A.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 A[c] < (A[a] + A[b]):
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
#print(a)
for i in range(n-2):
    for j in range(i+1, n-1):
        l = bisect_right(a, max(abs(a[i] - a[j]), a[j]))
        r = bisect_left(a, abs(a[i] + a[j]))
        #print(a[i], a[j], l, r)
        ans = ans - l + r
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
#print(a)
for i in range(n-1):
    for j in range(i+1, n):
        l = bisect_right(a, max(abs(a[i] - a[j]), a[j]))
        r = bisect_left(a, abs(a[i] + a[j]))
        #print(a[i], a[j], l, r)
        ans = ans - l + r
print(ans)

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def is_triangle(a, b, c):
    return a < b + c and b < c + a and c < a + b

N = int(input())
L = map(int, input().split())
ans = 0

for comb in combinations(L, 3):
    a, b, c = map(int, list(comb))
    if is_triangle(a, b, c):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=list(map(int,input().split()))
 
p=itertools.combinations(L,3)
q=itertools.combinations(L,2)
d={}
for i in q:
  d[i]=i[0]+i[1]
s=0
for i in p:
  x=d[i[0],i[1]]
  y=d[i[1],i[2]]
  z=d[i[0],i[2]]
  if i[0]<y and i[1]<z and i[2]<x:
    s += 1
 
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
L=list(map(int,input().split()))
 
p=itertools.combinations(L,3)
q=itertools.combinations(L,2)
d={}
for i in q:
  if i not in d:
    d[i]=i[0]+i[1]
s=0
for i in p:
  x=d[i[0],i[1]]
  y=d[i[1],i[2]]
  z=d[i[0],i[2]]
  if i[0]<y and i[1]<z and i[2]<x:
    s += 1
 
print(s)

Submission status: Time Limit Exceeded

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

p=itertools.combinations(L,3)

s=0
for i in p:
  if i[0]<i[1]+i[2] and i[1]<i[0]+i[2] and i[2]<i[1]+i[0]:
    s += 1

print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = list(map(list, set(map(tuple, ans))))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = []
for triangle in triangles:
    a = triangle[0]
    b = triangle[1]
    c = triangle[2]
    if c < (a + b):
        ans.append(triangle)

ans = list(map(list, set(map(tuple, ans))))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = []
for triangle in triangles:
    triangle_list = list(triangle)
    a = triangle_list[0]
    b = triangle_list[1]
    c = triangle_list[2]
    if c < (a + b):
        ans.append(triangle_list)

ans = list(map(list, set(map(tuple, ans))))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = []
for triangle in triangles:
    triangle_list = list(triangle)
    triangle_list.sort()
    a = triangle_list[0]
    b = triangle_list[1]
    c = triangle_list[2]
    if c < (a + b):
        ans.append(triangle_list)

ans = list(map(list, set(map(tuple, ans))))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = []
for triangle in triangles:
    triangle_list = list(triangle)
    triangle_list.sort()
    a = triangle_list[0]
    b = triangle_list[1]
    c = triangle_list[2]
    if c < (a + b) and not triangle_list in ans:
        ans.append(triangle_list)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list( map( int, input().split() ) )
comb = [' '.join( str(n) for n in sorted( [L[a],L[b],L[c]] ) ) for a in range(N) for b in range(1+a,N) for c in range(1+b,N) if (L[a] + L[b] > L[c]) and (L[b] + L[c] > L[a]) and (L[c] + L[a] > L[b])]
print( len( set(comb) ) )

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list( map( int, input().split() ) )
comb = []
for n in itertools.combinations(L, 3):
  if (n[0] + n[1] > n[2]) and (n[1] + n[2] > n[0]) and (n[2] + n[0] > n[1]):
        comb.append( ' '.join( str(x) for x in sorted(n) ) )
print( len( set(comb) ) )

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list( map( int, input().split() ) )
comb = []
for a in range(N):
  for b in range(1,N):
    if a == b:
      continue
    for c in range(2,N):
      if b == c or c == a:
        continue
      if (L[a] + L[b] > L[c]) and (L[b] + L[c] > L[a]) and (L[c] + L[a] > L[b]):
        comb.append( ' '.join( str(n) for n in sorted( [L[a],L[b],L[c]] ) ) )
print( len( set(comb) ) )

Submission status: Time Limit Exceeded

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

for i in range(n-2):
    for j in range(i+1, n-1):
        right = n - 1
        rightFlag = 1
        while rightFlag == 1 and right - j >= 1:
            if li[i] - li[j] >= li[right]:
                right -= 1
            else:
                rightFlag = 0
        if rightFlag == 0:
            count += right - j

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 0
for i in range(n - 2):
    x = l[i]
    for j in range(i + 1, n - 1):
        y = l[j]
        for k in range(j + 1, n):
            if x + y <= l[k]:
                break    
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 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]:
                break    
            c += 1
print(c)

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

Submission status: Time Limit Exceeded

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

L = sorted(L)

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]:
				s += 1
			else:
				break
			
print(s)

Submission status: Time Limit Exceeded

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

nL = sorted(L)

for i in range(0, N-2):
	for j in range(i+1, N-1):
		s += sum(x<nL[i]+nL[j] for x in nL[j+1:])
		
print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
s = 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]:
				if L[j]<L[k]+L[i]:
					if L[k]<L[i]+L[j]:
						s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
# import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = sorted(L)
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        # for b in range(a+1, len(L)-1):
            # ct+= bisect.bisect_left(L[b+1:],a_+L[b])
            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],ct))
        ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
    print(ct)

    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:
#!/usr/bin/env python3
import sys
import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        # for b in range(a+1, len(L)-1):
            # ct+= bisect.bisect_left(L[b+1:],a_+L[b])
            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],ct))
        ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
    print(ct)

    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:
#!/usr/bin/env python3
import sys
import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        for b in range(a+1, len(L)-1):
            b_in = bisect.bisect_left(L[b+1:],a_+L[b])
            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],b_in))
            # if len(L[b+1:]) == b_in:
                # c_ = 0
            c_ = b_in
            if c_>0:
                ct+=c_   
        # [(L[b+1:] < a_+L[b]).sum() for b in range(a+1, len(L)-1)]
    print(ct)

    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:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    ct = sum([sum([(L[b+1:] < L[a]+L[b]).sum() for b in range(a+1, len(L)-1)]) for a in range(len(L)-2)])
    print(ct)

    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:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        # for b in range(a+1, len(L)-1):
        #     ct+=(L[b+1:] < a_+L[b]).sum() 
        ct += sum([(L[b+1:] < a_+L[b]).sum() for b in range(a+1, len(L)-1)])
    print(ct)

    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:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        for b in range(a+1, len(L)-1):
            ct+=(L[b+1:] < a_+L[b]).sum() 
            
    print(ct)

    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:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    for a in range(len(L)-2):
        for b in range(a+1, len(L)-1):
            ct+=(L[b+1:] < L[a]+L[b]).sum() 
            
    print(ct)

    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:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    for a in range(len(L)-2):
        for b in range(a+1, len(L)-1):
            ct+=(np.logical_and((L[b] < L[b:]),(L[b:] < L[a]+L[b]))).sum() 
            
    print(ct)

    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:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    for a in range(len(L)-2):
        for b in range(a+1, len(L)-1):
            ct+=(np.logical_and((L[b] < L),(L < L[a]+L[b]))).sum() 
            
    print(ct)

    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:
n=int(input())
l=list(map(int,input().split()))

l.sort()
cnt=0
for ind_a,a in enumerate(l[:-2]):
    for ind_b,b in enumerate(l[ind_a+1:-1]):
        for ind_c,c in enumerate(l[ind_a+ind_b+2:]):
            #print(a,b,c)
            if a+b<=c:
                cnt+=ind_c
                break
        if a+b>c:
            cnt+=ind_c+1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
cnt=0
for ind_a,a in enumerate(l[:-2]):
    for ind_b,b in enumerate(l[ind_a+1:-1]):
        for c in l[ind_a+ind_b+2:]:
            #print(a,b,c)
            if a+b>c and a+c>b and b+c>a:
                #print("yes",a,b,c)
                cnt+=1

print(cnt)

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[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_num = [0] * (10 ** 3 + 1)
ans = 0
for i in l:
    L_num[i] += 1
for i in range(n):
    for j in range(i + 1, n):
        L_num[l[i]] -= 1
        L_num[l[j]] -= 1
        start = abs(l[i] - l[j]) + 1
        end = l[i] + l[j]
        ans += sum(L_num[start:end])
        L_num[l[i]] += 1
        L_num[l[j]] += 1
print(int(ans / 3))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    L=[int(_) for _ in input().split()]
    L.sort()
    ans=0
    for a in range(n-2):
        for b in range(a+1,n-1):
            flag=L[a]+L[b]
            for c in range(b+1,n):
                if L[c]>=flag:
                    break
                ans+=1
    print(ans)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
M = list(map(int, input().split()))
M = sorted(M)
count = 0
for i in range(N):
  a = M[i]
  for j in range(i+1, N):
    b = M[j]
    upper = a+b
    l, r = j, N
    while (r - l) > 1:
      c = (l + r) // 2
      if M[c] < upper:
        l = c
      else:
        r = c  
    #print(count, j, l, r)
    count += l - j
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
M = list(map(int, input().split()))
M = sorted(M)
count = 0
for i in range(N):
  a = M[i]
  for j in range(i+1, N):
    b = M[j]
    upper = a+b
    #はー，二分探索掛けないんごー
    l, r = j, N
    while (r - l) > 1:
      c = (l + r + 1) // 2
      if M[c] < upper:
        l = c
      else:
        r = c  
    #print(count, j, l, r)
    count += l - j
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
M = list(map(int, input().split()))
M = sorted(M)
count = 0
for i in range(N):
  a = M[i]
  for j in range(i+1, N):
    b = M[j]
    lower = b-a
    upper = a+b
    for l in range(j+1, N):
      c = M[l]
      if c < lower:
        continue
      if c >= a+b:
        break
      count += 1
      
print(count)

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):
  a=l[i]
  
  for j in range(i+1,n-1):
    b=l[j]
    k=j
    while k<n and l[k]<a+b:
      k+=1
    ans+=k-j-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N):
    for b in range(a):
        for c in range(b):
            if L[a] < L[b] + L[c] and L[b] < L[c] + L[a] and L[c] < L[a] + L[b]:
                ans += b - c
                break
print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort()
count=0
for j in range(N):
    for k in range(j+1,N):
        for i in reversed(range(k+1, N)):
            if L[j]+L[k]>L[i] and i!=k and i!=j:
                count+=(i-k)
                break

print(count)

Submission status: Time Limit Exceeded

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

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        r = bisect.bisect_left(L, a+b)
        l = max(i, j) + 1
        ans += max(0, r-l)
print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        ans += bisect.bisect_left(L, a+b) - bisect.bisect_right(L, max(a,b))

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for v in itertools.combinations(L,3):
  a,b,c = v[0],v[1],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 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):
        a = bisect.bisect_right(l, l[j]-l[i])
        b = bisect.bisect_left(l, l[i]+l[j])
        a = max(j+1, a)
        b = max(j+1, b)
        ans += b - a

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 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 c >= a + b:
                break
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    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]  # 真ん中の辺の長さ
            ans += bisect_left(l[j+1:], a+b)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
a = tuple(sorted(a))
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    chk = a[i]+a[j]
    for k in range(j+1,n):
      if a[k] >= chk:
        ans += (k-j-1)
        break
      if k == n-1:
        ans += (n-j-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
a = tuple(sorted(a))
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    chk = a[i]+a[j]
    for k in range(j+1,n):
      if a[k] >= chk:
        ans += (k-j-1)
        break
      if k == n-1:
        ans += (n-j-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import combinations as comb
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig
from statistics import mean as avg

sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    L = input([int, N])

    ans = 0
    for l in comb(L, 3):
        a, b, c = l
        if a < b + c and b < c + a and c < a + b:
            ans += 1
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Time Limit Exceeded

Solution code:
#b-c < a < b+c
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n):
    for k in range(i+1,n):
        lower = l[k]-l[i]+1
        upper = l[k]+l[i]-1
        temp = 0
        if lower <= l[i] <= upper:
            temp += 1
        if lower <= l[k] <= upper:
            temp += 1
        left = bisect.bisect_left(l,lower)
        right = bisect.bisect_right(l,upper)
        if k <= left:
            ans += right-left-temp
        elif k <= right:
            ans += right-k-1
        else:
            ans += 0
        #print(l[i],l[k],lower,upper,right,left,temp,ans)
print(ans)