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

l.sort(reverse = 1)
ans = 0
flg = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        indL = j
        indR = len(l)-1
        while 1:
            if indL == indR:
                flg = 1
                break
            if l[i] < l[indL] + l[indR]:
                ans += (indR - indL)
                break
            else:
                indR -= 1
        if flg == 1:
            flg = 0
            break
                
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    indL = i+1
    indR = len(l)-1
    while 1:
        if indL == indR:
            break
        if l[i] < l[indL] + l[indR]:
            ans += (indR - indL)
            indL += 1
        else:
            indR -= 1
                
print(ans)

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

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        indL = j
        indR = len(l)-1
        while indL <= indR:
            #print(i,indL,indR)
            if l[i] < l[indL] + l[indR]:
                ans += (indR - indL)
                break
            else:
                indR -= 1
            
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    indL = i+1
    indR = len(l)-1
    while 1:
        if indL == indR:
            break
        if l[i] < l[indL] + l[indR]:
            ans += (indR - indL)
            indL += 1
        else:
            indR -= 1
                
print(ans)

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

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        k = 1
        while 1:
            if k+j >= len(l):
                break
            elif l[i] < l[j] + l[j+k]:
                ans += 1
                k += 1
            else:
                break
                
            
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    indL = i+1
    indR = len(l)-1
    while 1:
        if indL == indR:
            break
        if l[i] < l[indL] + l[indR]:
            ans += (indR - indL)
            indL += 1
        else:
            indR -= 1
                
print(ans)

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

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if l[i]/2 > l[j]:
            break
        for k in range(j+1,n):
            a,b,c = l[i],l[j],l[k]
            #print(i,j,k)
            if a >= b+c:
                break
            else:
                ans += 1
            
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    indL = i+1
    indR = len(l)-1
    while 1:
        if indL == indR:
            break
        if l[i] < l[indL] + l[indR]:
            ans += (indR - indL)
            indL += 1
        else:
            indR -= 1
                
print(ans)