Problem: 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.

Submission attempts (in order):
# D

import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0

for i, j in itertools.combination(len(n),2):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)


# D TLE
import bisect

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

L.sort()
value = 0


for i in range(0, len(L)-2)
    for j in range(i, len(L)-1)
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=index

print(value)

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

value = 0
for i in itertools.combinations(L, 3):
    a, b, c = i
    
    if a<b+c:
        if b<c+a:
            if c<a+b:
                value+=1
print(value)

# D

import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0

for i, j in itertools.combinations(len(n),2):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

# D

import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0

for i, j in itertools.combinations(len(l),2):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

N = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

# D TLE
import bisect

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

L.sort()
value = 0


for i in range(0, len(L)-2):
    for j in range(i, len(L)-1):
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=max(0, index)

print(value)


# D TLE
import itertools
import bisect

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

L.sort()
value = 0

for i, j in itertools.combinations(range(len(L-1)), 2):
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=index

print(value)

# D TLE
import bisect

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

L.sort()
value = 0


for i in range(0, len(L)-2):
    for j in range(i, len(L)-1):
        index = bisect.bisect_left(L[j+1:], L[i]+L[j])
        value+=max(0, index)

print(value)

# D

import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0

for i, j in itertools.combinations(range(len(l)),2):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted