Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

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_left(l[j+1:], l[j]+l[i])
    
print(ans)

Fixed submission:
from bisect import bisect_left

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):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    #temp1 = bisect_left(l[j+1:], l[j]-l[i])
    #temp2 = bisect_left(l[j+1:], l[j]+l[i])
    #print(temp1)
    #print(temp2)
    ans += bisect_left(l[j+1:], l[j]+l[i])
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    temp1 = bisect.bisect_left(l[j+1:], l[j]-l[i])
    temp2 = bisect.bisect_left(l[j+1:], l[j]+l[i])
    #print(temp1)
    #print(temp2)
    ans += (temp2-temp1)
    
print(ans)

Fixed submission:
from bisect import bisect_left

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):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    #temp1 = bisect_left(l[j+1:], l[j]-l[i])
    #temp2 = bisect_left(l[j+1:], l[j]+l[i])
    #print(temp1)
    #print(temp2)
    ans += bisect_left(l[j+1:], l[j]+l[i])
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
ans = 0

for i in range(n-2):
  for j in range(i+1, n-1):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    ans +=  len(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    
print(ans)

Fixed submission:
from bisect import bisect_left

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):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    #temp1 = bisect_left(l[j+1:], l[j]-l[i])
    #temp2 = bisect_left(l[j+1:], l[j]+l[i])
    #print(temp1)
    #print(temp2)
    ans += bisect_left(l[j+1:], l[j]+l[i])
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
ans = 0

for i in range(n-2):
  for j in range(i+1, n-1):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    ans +=  len(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    
print(ans)

Fixed submission:
from bisect import bisect_left

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):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    #temp1 = bisect_left(l[j+1:], l[j]-l[i])
    #temp2 = bisect_left(l[j+1:], l[j]+l[i])
    #print(temp1)
    #print(temp2)
    ans += bisect_left(l[j+1:], l[j]+l[i])
    
print(ans)