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):
            for k in range(j+1, n):
                if l[i] + l[j] > l[k]:
                        cnt += 1
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys
    import collections
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(n-2):
        for j in range(i+1, n-1):
            ma = l[i] + l[j]
            p = bisect.bisect_left(l, ma)
            if j < p:
                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 = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if l[i] + l[j] > l[k]:
                    if (i, j, k) not in d:
                        cnt += 1
                        d[i, j, k]
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys
    import collections
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(n-2):
        for j in range(i+1, n-1):
            ma = l[i] + l[j]
            p = bisect.bisect_left(l, ma)
            if j < p:
                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 = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            a, b = [l[i], l[j]]
            tl = [a + b, abs(a - b)]
            mi = min(tl) + 1
            ma = min(max(tl) - 1, a - 1)
            for k in range(i-1, -1, -1):
                if l[k] < mi:
                    break
                elif mi <= l[k] <= ma:
                    ttl = sorted([i, j, k])
                    if (ttl[0], ttl[1], ttl[2]) not in d:
                        d[(ttl[0], ttl[1], ttl[2])]
                        cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys
    import collections
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(n-2):
        for j in range(i+1, n-1):
            ma = l[i] + l[j]
            p = bisect.bisect_left(l, ma)
            if j < p:
                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 = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            a, b = [l[i], l[j]]
            tl = [a + b, abs(a - b)]
            mi = min(tl) + 1
            ma = max(tl) - 1
            for k in range(i-1, -1, -1):
                #print(mi, ma, l[k])
                if l[k] < mi:
                    break
                elif mi <= l[k] <= ma:
                    ttl = sorted([i, j, k])
                    #print(ttl)
                    if (ttl[0], ttl[1], ttl[2]) not in d:
                        d[(ttl[0], ttl[1], ttl[2])]
                        cnt += 1
                    #print(ttl)
    print(cnt)


if __name__ == '__main__':
    slove()


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


if __name__ == '__main__':
    slove()