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

L = sorted(L)
ans = 0
H = {}
for i in range(N-1):
    for j in range(i+1, N):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(h[1]+1, N):
        if v <= L[j]:
            break
        ans += 1

print(ans)


Fixed submission:
#!/usr/bin/env python3
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        b_i = bisect.bisect_left(L, L[i]+L[j]) # a+bより小さい数
        ans += b_i - (j+1)
print(ans)

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

L = sorted(L)
ans = 0
H = {}
for i in range(N-1):
    for j in range(i+1, N-1):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(h[1]+1, N):
#        if h[0] == j or h[1] == j: continue
        if v > L[j]:
            ans += 1
        else: break

print(ans)


Fixed submission:
#!/usr/bin/env python3
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        b_i = bisect.bisect_left(L, L[i]+L[j]) # a+bより小さい数
        ans += b_i - (j+1)
print(ans)

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

L = sorted(L)
ans = 0
H = {}
for i in range(N-1):
    for j in range(i+1, N-1):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(h[1]+1, N):
#        if h[0] == j or h[1] == j: continue
        if h[1]>=j: continue
        if v > L[j]:
            ans += 1
        else: break

print(ans)


Fixed submission:
#!/usr/bin/env python3
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        b_i = bisect.bisect_left(L, L[i]+L[j]) # a+bより小さい数
        ans += b_i - (j+1)
print(ans)

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

L = sorted(L)
ans = 0
H = {}
for i in range(N-1):
    for j in range(i+1, N-1):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(N):
#        if h[0] == j or h[1] == j: continue
        if h[1]>=j: continue
        if v > L[j]:
            ans += 1
        else: break

print(ans)


Fixed submission:
#!/usr/bin/env python3
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        b_i = bisect.bisect_left(L, L[i]+L[j]) # a+bより小さい数
        ans += b_i - (j+1)
print(ans)

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

L = sorted(L)
ans = 0
for i in range(N-2):
#    k = i + 2
    for j in range(i+1, N-1):
        for k in range(j+1,N):
#        if L[i]+L[j] <= L[k]: break
#        if L[i]+L[k] <= L[j]: break
#        if L[j]+L[k] <= L[i]: break
            if L[i]+L[j] <= L[k]: break
#            if L[i]+L[k] <= L[j]: break
#            if L[j]+L[k] <= L[i]: break


            ans += 1
#        k += 1

print(ans)


Fixed submission:
#!/usr/bin/env python3
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        b_i = bisect.bisect_left(L, L[i]+L[j]) # a+bより小さい数
        ans += b_i - (j+1)
print(ans)