Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]
        x = (a+1) - b
        y = (b+1) - a
        z = max(x,y)
        a = j+1
        b = n-1
        c = (a+b) // 2
        while a <= b:
            if l[c] == z:
                a += 1
            elif l[c] > z:
                a = c + 1
            elif l[c] < z:
                b = c - 1
            else:
                pass
            c = (a+b) // 2
        ans += c-j
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]
        x = (a+1) - b
        y = (b+1) - a
        z = max(x,y)
        a = j+1
        b = n-1
        c = (a+b) // 2
        while a <= b:
            if l[c] == z:
                a += 1
            elif l[c] > z:
                a = c + 1
            elif l[c] < z:
                b = c - 1
            else:
                pass
            c = (a+b) // 2
        ans += c-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if l[c]<l[a]+l[b]:
                if l[b]<l[a]+l[c]:
                    if l[a]<l[b]+l[c]:
                        ans += 1
            else:
                break
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]
        x = (a+1) - b
        y = (b+1) - a
        z = max(x,y)
        a = j+1
        b = n-1
        c = (a+b) // 2
        while a <= b:
            if l[c] == z:
                a += 1
            elif l[c] > z:
                a = c + 1
            elif l[c] < z:
                b = c - 1
            else:
                pass
            c = (a+b) // 2
        ans += c-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if l[a]<l[b]+l[c] and l[b]<l[a]+l[c] and l[c]<l[a]+l[b]:
                ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]
        x = (a+1) - b
        y = (b+1) - a
        z = max(x,y)
        a = j+1
        b = n-1
        c = (a+b) // 2
        while a <= b:
            if l[c] == z:
                a += 1
            elif l[c] > z:
                a = c + 1
            elif l[c] < z:
                b = c - 1
            else:
                pass
            c = (a+b) // 2
        ans += c-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if l[a]<l[b]+l[c] and l[b]<l[a]+l[c] and l[c]<l[a]+l[b]:
                ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]
        x = (a+1) - b
        y = (b+1) - a
        z = max(x,y)
        a = j+1
        b = n-1
        c = (a+b) // 2
        while a <= b:
            if l[c] == z:
                a += 1
            elif l[c] > z:
                a = c + 1
            elif l[c] < z:
                b = c - 1
            else:
                pass
            c = (a+b) // 2
        ans += c-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    a = l[i]
    x = i
    for j in range(i+1,n-1):
        b = l[j]
        y = j
        for k in range(j+1,n):
            if x == k or y == k:
                continue
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]
        x = (a+1) - b
        y = (b+1) - a
        z = max(x,y)
        a = j+1
        b = n-1
        c = (a+b) // 2
        while a <= b:
            if l[c] == z:
                a += 1
            elif l[c] > z:
                a = c + 1
            elif l[c] < z:
                b = c - 1
            else:
                pass
            c = (a+b) // 2
        ans += c-j
print(ans)