Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
L = map(int, raw_input().split())

L.sort()

sum = 0

for i in range(N):
    a = L[i]
    for j in range(i+1,N):
        b = L[j]
        for k in range(j+1,N):
            c = L[k]
            if c >= a+b:
                break
#            print "a,b,c = ", a,b,c                                                                                                                     
            sum = sum + 1

print sum

Fixed submission:
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    L = sorted(L)

    for i in range(N):
        a = L[i]
        for j in range(i+1, N):
            b = L[j]
            target = a+b

            c = bisect.bisect_left(L, target)
            ans = ans + (c-j-1)

    print (ans)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
L = map(int, raw_input().split())

L.sort(reverse=True)

sum = 0

for i in range(N):
    a = L[i]
    for j in range(i+1,N):
        b = L[j]
        for k in range(j+1,N):
            c = L[k]
            if a < b+c:
                sum = sum + 1
            else:
                break

print sum


Fixed submission:
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    L = sorted(L)

    for i in range(N):
        a = L[i]
        for j in range(i+1, N):
            b = L[j]
            target = a+b

            c = bisect.bisect_left(L, target)
            ans = ans + (c-j-1)

    print (ans)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
L = map(int, raw_input().split())

L.sort(reverse=True)

sum = 0

for i in range(N):
    a = L[i]

    for j in range(i+1,N):
        b = L[j]
        if 2*b < a:
            break

        c = 0
        start = j
        end = N
        while start != end-1:
            k = (end + start)/2
            c = L[k]
            if  c > a-b:
                start = k
            else:
                end = k

        if start == end-1:
            sum = sum + (start-j)

print sum


Fixed submission:
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    L = sorted(L)

    for i in range(N):
        a = L[i]
        for j in range(i+1, N):
            b = L[j]
            target = a+b

            c = bisect.bisect_left(L, target)
            ans = ans + (c-j-1)

    print (ans)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
L = map(int, raw_input().split())

L.sort(reverse=True)

sum = 0

for i in range(N):
    a = L[i]

    for j in range(i+1,N):
        b = L[j]
        if 2*b < a:
            break

        for k in range(j+1,N):
            c = L[k]
            if a < b+c:
                sum = sum + 1
            else:
                break

print sum

Fixed submission:
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    L = sorted(L)

    for i in range(N):
        a = L[i]
        for j in range(i+1, N):
            b = L[j]
            target = a+b

            c = bisect.bisect_left(L, target)
            ans = ans + (c-j-1)

    print (ans)
if __name__ == "__main__":
    main()