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

for i in range(N):
  for j in range(i+1,N):
    summation = L[i] + L[j]
    subtract  = L[j] - L[i]
    D=L.copy()
    del D[j]
    del D[i]
    #E=[ D[k] for k in range(N) if k!= i and k!= j ]
    #求めるものはjよりも長くsummationよりも小さいもの
    ##summationより小さいかを二分探索
    high = N-3
    low = j-2
    if D[0] >= summation:
      upper = 0 #1つも満たさない
      #print(L[i],L[j],D,upper)
    elif D[-1] < summation:
      upper = N-1-j #すべてOK
    else:
      while high > low+1:
        mid =(high + low) // 2
        if D[mid] >= summation: #大きすぎ
          high = mid
          # mid = low
        else: #小さすぎかちょうど
          low = mid
          # mid =high 
      upper = high +1-j
    #print("summation",summation,D,upper)
    count += upper #-lower
print(count)  

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):
        a = L[i]
        b = L[j]
        idx = bisect_left(L, a + b)
        ans += idx - 1 - j
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
L=list(map(int,input().split()))
L.sort()
count = 0

for i in range(N):
  for j in range(i+1,N):
    summation = L[i] + L[j]
    subtract  = L[j] - L[i]
    D=L.copy()
    del D[j]
    del D[i]
    #E=[ D[k] for k in range(N) if k!= i and k!= j ]
    ##summationより小さいかを二分探索
    high = N-3
    low = 0
    if D[0] >= summation:
      upper = 0 #1つも満たさない
      #print(L[i],L[j],E,upper)
    elif D[-1] < summation:
      upper = N-2 #N-2個すべてOK
    else:
      while high > low+1:
        mid =(high + low) // 2
        if D[mid] >= summation: #大きすぎ
          high = mid
          # mid = low
        else: #小さすぎかちょうど
          low = mid
          # mid =high 
      upper = high
    #print("summation",summation,E,upper)
    ##subtractより大きいかを二分探索
    high = N-3
    low = 0
    if D[0] > subtract:
      lower = 0 #N-2個すべてOK
    elif D[-1] <= subtract:
      lower = N-2 #1つも満たさない
    else:
      while high > low+1:
        mid =(high + low) // 2
        if D[mid] > subtract: #大きすぎ
          high = mid
          # mid = low
        else: #小さすぎかちょうど
          low = mid 
          # mid =high 
      lower = high
    #print("subtract",subtract,E,lower)
    count += upper - lower
print(count//3)  

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):
        a = L[i]
        b = L[j]
        idx = bisect_left(L, a + b)
        ans += idx - 1 - j
print(ans)

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

for i in range(N):
  for j in range(i+1,N):
    summation = L[i] + L[j]
    subtract  = L[j] - L[i]
    D=L.copy()
    del D[j]
    del D[i]
    #E=[ D[k] for k in range(N) if k!= i and k!= j ]
    ##summationより小さいかを二分探索
    high = N-3
    low = 0
    if D[0] >= summation:
      upper = 0 #1つも満たさない
      #print(L[i],L[j],E,upper)
    elif D[-1] < summation:
      upper = N-2 #N-2個すべてOK
    else:
      while high > low+1:
        mid =(high + low) // 2
        if D[mid] >= summation: #大きすぎ
          high = mid
          # mid = low
        else: #小さすぎかちょうど
          low = mid
          # mid =high 
      upper = high
    #print("summation",summation,E,upper)
    ##subtractより大きいかを二分探索
    high = N-3
    low = 0
    if D[0] > subtract:
      lower = 0 #N-2個すべてOK
    elif D[-1] <= subtract:
      lower = N-2 #1つも満たさない
    else:
      while high > low+1:
        mid =(high + low) // 2
        if D[mid] > subtract: #大きすぎ
          high = mid
          # mid = low
        else: #小さすぎかちょうど
          low = mid 
          # mid =high 
      lower = high
    #print("subtract",subtract,E,lower)
    count += upper - lower
print(count//3)  

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):
        a = L[i]
        b = L[j]
        idx = bisect_left(L, a + b)
        ans += idx - 1 - j
print(ans)