Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N-2):  # １番短い棒 #どうせ増えないからＮでも多分大丈夫
  for j in range(i + 1, N-1):  # 真ん中の長さの棒
    ans += bisect_left(L[j+1:], L[i] + L[j]) 

print(ans)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
value = 0
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)  

for i in range(N-2):
  for j in range(i+1,N-1):
    x = L[i]+L[j]
    B = N-1
    A = j
    max_c_index = j
 #   while True:
    while A <= B: #A>Bとなったときに停めるようにすれば簡潔
     # M = A + (B-A)//2
      M = (A+B)//2 #こう書くほうがシンプル
      if L[M] < x:
        max_c_index = M
        A = M+1
      else:
#        B = M
        B = M-1
    value += max_c_index - j
print(value)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
value = 0
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)  

for i in range(N-2):
  for j in range(i+1,N-1):
    x = L[i]+L[j]
    B = N-1
    A = j
    max_c_index = j
    while True:
      M = A + (B-A)//2
      if B-A<=1:
        if L[B] < x:
          max_c_index = B
        value += max_c_index - j
        break
      if L[M] < x:
        max_c_index = M
        A = M       
      else:
        B = M
print(value)


Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
value = 0
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
a_plus_b = [] 
for i in range(1,N-1):
  for j in range(i):
    a_plus_b.append(L[j]+L[i])

for i in range(2,N):
  for j in range(i*(i-1)//2):
    if L[i] < a_plus_b[j]:
      value += 1
print(value)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
R = sorted(L)
var = 0
for i in range(N-2):
  for j in range(N-i-1-1):
    for k in range(N-i-1-j-1):
      if R[i] + R[i+1+j] > R[i+1+j+1+k]:
        var = var+1
      else:
        break
print(var)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
R = sorted(L)
var = 0
for i in range(N-2):
  for j in range(N-i-1-1):
    for k in range(N-i-1-j-1):
      if R[i] + R[i+1+j] > R[i+1+j+1+k]:
        var = var+1
      else:
        break
print(var)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)