Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = sorted(list(map(int, input().rstrip('\n').split())))
    cnt = 0
    for i, iv in enumerate(l[:n-2]):
        for j, jv in enumerate(l[i+1:n-1]):
            t = iv + jv
            for k, kv in enumerate(l[i+j+2:n]):
                if t > kv:
                    cnt += 1
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            p = bisect.bisect_left(l, t)
            cnt += (p - j - 1)
    print(cnt)


if __name__ == '__main__':
    slove()

Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = collections.deque(sorted(list(map(int, input().rstrip('\n').split()))))
    cnt = 0
    for i in range(n-2):
        p = l.popleft()
        for j in range(n-i-1):
            t = p + l[j]
            for k in range(j+1, n-i-1):
                if t > l[k]:
                    cnt += 1
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            p = bisect.bisect_left(l, t)
            cnt += (p - j - 1)
    print(cnt)


if __name__ == '__main__':
    slove()

Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = sorted(tuple(map(int, input().rstrip('\n').split())))
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            for k in range(j+1, n):
                if t > l[k]:
                    cnt += 1
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            p = bisect.bisect_left(l, t)
            cnt += (p - j - 1)
    print(cnt)


if __name__ == '__main__':
    slove()

Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            for k in range(j+1, n):
                if t > l[k]:
                    cnt += 1
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            p = bisect.bisect_left(l, t)
            cnt += (p - j - 1)
    print(cnt)


if __name__ == '__main__':
    slove()