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


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i, a in enumerate(L):
        if i > N-2:
            break
        for j, b in enumerate(L):
            if j > N-1:
                break
            if j <= i:
                continue
            # print(a, b)
            c_right = bleft(L, a+b)
            # print(c_right)
            if c_right == 0:
                continue
            now_seq = L[j+1:c_right]
            c_left = bright(now_seq, b-a)
            if c_left == N:
                continue
            ans += len(now_seq) - c_left
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
import bisect


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i, a in enumerate(L):
        if i > N-2:
            break
        for j, b in enumerate(L):
            if j > N-1:
                break
            if j <= i:
                continue
            c_right = bleft(L[j+1:], a+b)
            ans += c_right
    print(ans)

if __name__ == '__main__':
    main()

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


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            # print(a, b)
            c_right = bleft(L, a+b)
            # print(c_right)
            if c_right == 0:
                continue
            now_seq = L[j+1:c_right]
            c_left = bright(now_seq, b-a)
            if c_left == N:
                continue
            ans += len(now_seq) - c_left
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
import bisect


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i, a in enumerate(L):
        if i > N-2:
            break
        for j, b in enumerate(L):
            if j > N-1:
                break
            if j <= i:
                continue
            c_right = bleft(L[j+1:], a+b)
            ans += c_right
    print(ans)

if __name__ == '__main__':
    main()

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


input = sys.stdin.readline

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

bleft = bisect.bisect_left
bright = bisect.bisect
ans = 0

for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        # print(a, b)
        c_right = bleft(L, a+b)
        # print(c_right)
        if c_right == 0:
            continue
        now_seq = L[j+1:c_right]
        c_left = bright(now_seq, b-a)
        if c_left == N:
            continue
        ans += len(now_seq) - c_left
print(ans)


Fixed submission:
import sys
import bisect


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i, a in enumerate(L):
        if i > N-2:
            break
        for j, b in enumerate(L):
            if j > N-1:
                break
            if j <= i:
                continue
            c_right = bleft(L[j+1:], a+b)
            ans += c_right
    print(ans)

if __name__ == '__main__':
    main()