Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def hoge(A,B):
    sum = 0
    for i in range(B):
        sum += A
        A -= 1
    return sum

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

L.sort(reverse=True)

List = deque()
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(hoge(N-2,i),len(List)):
        if List[j] > L[i]:
            Sum += 1

print(Sum)

Fixed submission:
import bisect

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

Sum = 0
L.sort(reverse=False)

for i in reversed(range(2,N)):
    for j in reversed(range(1,i)):
        hoge = 0
        hoge = j - bisect.bisect(L, L[i] - L[j])
        if hoge < 0:
            hoge = 0
        Sum += hoge

print(Sum)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

L.sort(reverse=True)

List = deque()
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(len(List)):
        if List[j] > L[i]:
            Sum += 1

    for j in range(N-2-i):
        List.popleft()

print(Sum)

Fixed submission:
import bisect

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

Sum = 0
L.sort(reverse=False)

for i in reversed(range(2,N)):
    for j in reversed(range(1,i)):
        hoge = 0
        hoge = j - bisect.bisect(L, L[i] - L[j])
        if hoge < 0:
            hoge = 0
        Sum += hoge

print(Sum)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

L.sort(reverse=True)

List = deque()
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(len(List)):
        if List[j] > L[i]:
            Sum += 1

    for j in range(N-2-i):
        List.popleft()

print(Sum)



Fixed submission:
import bisect

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

Sum = 0
L.sort(reverse=False)

for i in reversed(range(2,N)):
    for j in reversed(range(1,i)):
        hoge = 0
        hoge = j - bisect.bisect(L, L[i] - L[j])
        if hoge < 0:
            hoge = 0
        Sum += hoge

print(Sum)

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

L.sort(reverse=True)

List = []
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(len(List)):
        if List[j] > L[i]:
            Sum += 1

    del List[0:N - i - 2]

print(Sum)



Fixed submission:
import bisect

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

Sum = 0
L.sort(reverse=False)

for i in reversed(range(2,N)):
    for j in reversed(range(1,i)):
        hoge = 0
        hoge = j - bisect.bisect(L, L[i] - L[j])
        if hoge < 0:
            hoge = 0
        Sum += hoge

print(Sum)

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

L.sort(reverse=True)

List = []
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    for j in range(len(List)):
        if List[j] > L[i]:
            Sum += 1

    del List[0:N - i - 2]

print(Sum)



Fixed submission:
import bisect

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

Sum = 0
L.sort(reverse=False)

for i in reversed(range(2,N)):
    for j in reversed(range(1,i)):
        hoge = 0
        hoge = j - bisect.bisect(L, L[i] - L[j])
        if hoge < 0:
            hoge = 0
        Sum += hoge

print(Sum)