Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        s = j + 1
        while s < n and l[i] + l[j] > l[s]:
            s += 1
        counter += s-j-1
print(counter)

Fixed submission:
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n):
    s = i + 2
    for j in range(i+1,n):        
        while (s < n and l[i] + l[j] > l[s]):
            s += 1
        counter += s-j-1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        s = j + 1
        while s < n and l[i] + l[j] > l[s]:
            s += 1
        counter += s-j-1
print(counter)

Fixed submission:
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n):
    s = i + 2
    for j in range(i+1,n):        
        while (s < n and l[i] + l[j] > l[s]):
            s += 1
        counter += s-j-1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    L = list(map(int, input().split()))
    L.sort()
    counter = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            result = 0
            left = j+1
            right = n-1
            while L[i]+L[j] > L[left]:
                if right - left <= 1:
                    if L[i]+L[j] > L[right]:
                        result = right - j
                    else:
                        result = left - j
                    break
                mid = (left+right)//2
                if L[i]+L[j] > L[mid]:
                    left = mid
                else:
                    right = mid
            counter += result
    print(counter)
if __name__ == '__main__':
    main()

Fixed submission:
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n):
    s = i + 2
    for j in range(i+1,n):        
        while (s < n and l[i] + l[j] > l[s]):
            s += 1
        counter += s-j-1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))
L.sort()

def binary_s(left, right, a, b):
    result = 0
    while L[a]+L[b] > L[left]:
        if right - left <= 1:
            if L[a]+L[b] > L[right]:
                result = right - b
            else:
                result = left - b
            break
        mid = (left+right)//2
        if L[a]+L[b] > L[mid]:
            left = mid
        else:
            right = mid
    return result
counter = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        counter += binary_s(j+1, n-1, i, j)
print(counter)

Fixed submission:
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n):
    s = i + 2
    for j in range(i+1,n):        
        while (s < n and l[i] + l[j] > l[s]):
            s += 1
        counter += s-j-1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))
L.sort()

def binary_s(left, right, a, b):
    result = 0
    while L[a]+L[b] > L[left]:
        if right - left <= 1:
            if L[a]+L[b] > L[right]:
                result = right - max(a, b)
            else:
                result = left - max(a, b)
            break
        mid = (left+right)//2
        if L[a]+L[b] > L[mid]:
            left = mid
        else:
            right = mid
    return result
counter = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        counter += binary_s(j+1, n-1, i, j)
print(counter)

Fixed submission:
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n):
    s = i + 2
    for j in range(i+1,n):        
        while (s < n and l[i] + l[j] > l[s]):
            s += 1
        counter += s-j-1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
def solve(x, y, z):
    if x < y+z and y < z+x and z < x+y:
        return True
    else:
        return False
counter = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for s in range(j+1,n):
            if solve(l[i],l[j],l[s]):
                counter += 1
            else:
                break
print(counter)

Fixed submission:
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n):
    s = i + 2
    for j in range(i+1,n):        
        while (s < n and l[i] + l[j] > l[s]):
            s += 1
        counter += s-j-1
print(counter)