Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    res = 0
    for i, li in enumerate(L[:-2]):
        flag = False
        k_before = i+2
        for j, lj in enumerate(L[i+1:-1], i+1):
            for k, lk in enumerate(L[k_before:], k_before):
                if lk-lj >= li:
                    res += k-j-1
                    k_before = max(k, j+2)
                    break
            else:
                res += (len(L)-j)*(len(L)-j-1)//2
                flag = True
            if flag:
                break
    print(res)


Fixed submission:
import bisect


if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            ans += bisect.bisect_left(L, L[i]+L[j])-j-1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            k = 0
            for k, lk in enumerate(L[i+j+2+k:]):
                if lk-lj >= li:
                    res += k
                    break
            else:
                res += k + 1
    print(res)


Fixed submission:
import bisect


if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            ans += bisect.bisect_left(L, L[i]+L[j])-j-1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            res_k = 0
            for k, lk in enumerate(L[i+j+2+res_k:]):
                if lk-lj >= li:
                    res_k += k
                    break
            else:
                res += k + 1
            res += res_k
    print(res)


Fixed submission:
import bisect


if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            ans += bisect.bisect_left(L, L[i]+L[j])-j-1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            res_k = 0
            for k, lk in enumerate(L[i+j+2+res_k:]):
                if lk-lj >= li:
                    res_k += k
                    break
            else:
                res += k + 1
            res += res_k
    print(res)


Fixed submission:
import bisect


if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            ans += bisect.bisect_left(L, L[i]+L[j])-j-1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            for k, lk in enumerate(L[i+j+2:]):
                if lk-lj >= li:
                    res += k
                    break
            else:
                res += k + 1
    print(res)


Fixed submission:
import bisect


if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            ans += bisect.bisect_left(L, L[i]+L[j])-j-1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            sub = abs(li-lj)
            res += sum(sub < lk < li+lj for lk in L[i+j+2:])
    print(res)



Fixed submission:
import bisect


if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            ans += bisect.bisect_left(L, L[i]+L[j])-j-1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            res += sum(li < lj + lk and lj < lk + li and lk < li + lj for lk in L[i+j+2:])
    print(res)



Fixed submission:
import bisect


if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            ans += bisect.bisect_left(L, L[i]+L[j])-j-1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            for k, lk in enumerate(L[i+j+2:]):
                if li < lj + lk and lj < lk + li and lk < li + lj:
                    res += 1
    print(res)


Fixed submission:
import bisect


if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            ans += bisect.bisect_left(L, L[i]+L[j])-j-1
    print(ans)