Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
L = list(map(int, input().split()))
# L = sorted(L)
L = sorted(L, reverse=True)

x = 0

for i in range(len(L)):   
    for j in range(i+1, len(L)):
        l = L[i] - L[j]
        for k in range(j+1, len(L)):
            if L[k] > l:
                x += 1
            else:
                break
print(x)
 

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
L = list(map(int, input().split()))
# L = sorted(L)
L = sorted(L, reverse=True)

x = 0


for i in range(len(L)):   
    for j in range(i+1, len(L)):
        if L[i] < L[j] * 2:
            l = L[i] - L[j]
            for k in range(j+1, len(L)):
                if L[k] > l:
                    x += 1
                else:
                    break
        else:
            break
print(x)
                

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

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

x = 0


for i in range(len(L)):   
    for j in range(i+1, len(L)):
        for k in range(j+1, len(L)):
            if (abs(L[i]-L[j]) < L[k]) and (L[k] < (L[i]+L[j])):
                x += 1
            else:
                break
print(x)
            

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

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

x = 0


for i in range(len(L)):   
    for j in range(i+1, len(L)):
        for k in range(j+1, len(L)):
            if (abs(L[i]-L[j]) < L[k]) and (L[k] < (L[i]+L[j])):
                x += 1
print(x)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

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

x = 0


for i in range(len(L)):
    
    for j in range(i+1, len(L)):
        if L[i] > 2 * L[j]:
            break
        for k in range(j+1, len(L)):
            if L[i] > L[j] + L[k]:
                break
            
            if (L[k] < L[i] + L[j]):
                if (L[i] < L[j] + L[k]):
                    if  (L[j] < L[k] + L[i]):
                        x += 1

print(x)



Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

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

x = 0

from itertools import combinations

for l in combinations(L, 3):
    if (l[0] < l[1] + l[2])\
        and (l[1] < l[2] + l[0])\
        and (l[2] < l[0] + l[1]):
        x += 1
print(x)


Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

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

x = [1 if (L[i] < L[j] + L[k])
        and (L[j] < L[k] + L[i])
        and (L[k] < L[i] + L[j])
       else 0
     for i in range(len(L)) for j in range(i+1, len(L)) for k in range(j+1, len(L))
  ]

print(sum(x))


Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

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

x = 0

for i in range(len(L)):
    for j in range(i+1, len(L)):
        for k in range(j+1, len(L)):
            if (L[k] < L[i] + L[j]):
                if (L[i] < L[j] + L[k]):
                    if  (L[j] < L[k] + L[i]):
                        x += 1
            else:
                break
        
print(x)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

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


x = 0

for i in range(len(L)):
    for j in range(i+1, len(L)):
        for k in range(j+1, len(L)):
            if (L[i] < L[j] + L[k]):
                if (L[j] < L[k] + L[i]):
                    if  (L[k] < L[i] + L[j]):
                        x += 1
        
print(x)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):

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


x = 0

for i in range(len(L)):
    for j in range(i+1, len(L)):
        for k in range(j+1, len(L)):
            if (L[i] < L[j] + L[k]) and\
               (L[j] < L[k] + L[i]) and\
               (L[k] < L[i] + L[j]):
                   x += 1
        
print(x)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)