Buggy python submission (verdict: Time Limit Exceeded):
N=raw_input()
LN=raw_input().split()

n = int(N)
ln = [int(i) for i in LN]

ln.sort()

def bin_search(s,e,t):
    # return minimum i where s <= i < e and ln[i] >= t
    m = (s + e)/2
    if m == s:
        return s

    if t < ln[m]:
        return bin_search(s,m,t)
    else:
        return bin_search(m,e,t)



r = 0
for i in range(n-1, 1, -1):
    a = ln[i]
    for j in range(i-1, 0, -1):
        b = ln[j]
        c = a - b
        if ln[j-1] > c:
            idx = bin_search(0,j,c+1)
            r += j - idx
        else:
            break

print r


Fixed submission:
import bisect

N=int(raw_input())
LN=map(int, raw_input().split())

LN.sort()

r = 0
for i in xrange(N-1, 1, -1):
    a = LN[i]
    for j in xrange(i-1, 0, -1):
        b = LN[j]
        if a > 2*b:
            break
        idx = bisect.bisect_left(LN, a-b+1)
        if idx < j:
            r += j - idx

print r

Buggy python submission (verdict: Time Limit Exceeded):
N=raw_input()
LN=raw_input().split()

n = int(N)
ln = [int(i) for i in LN]

ln.sort()

def bin_search(s,e,t):
    # return minimum i between s <= i < e where ln[i] >= t
    m = (s + e)/2
    if m == s:
        return s

    if t < ln[m]:
        return bin_search(s,m,t)
    else:
        return bin_search(m,e,t)



r = 0
for i in range(n-1, -1, -1):
    a = ln[i]
    for j in range(i-1, -1, -1):
        b = ln[j]
        c = a - b
        if j > 0 and ln[j-1] > c:
            idx = bin_search(0,j,c+1)
            r += j - idx

print r

Fixed submission:
import bisect

N=int(raw_input())
LN=map(int, raw_input().split())

LN.sort()

r = 0
for i in xrange(N-1, 1, -1):
    a = LN[i]
    for j in xrange(i-1, 0, -1):
        b = LN[j]
        if a > 2*b:
            break
        idx = bisect.bisect_left(LN, a-b+1)
        if idx < j:
            r += j - idx

print r

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=raw_input()
LN=raw_input().split()

n = int(N)
ln = [int(i) for i in LN]

ln.sort()

r = []
for i in range(n-1, -1, -1):
    a = ln[i]
    for j in range(i-1, -1, -1):
        b = ln[j]
        if a > 2*b:
            break
        for k in range(j-1, -1, -1):
            # always, a > b > c
            c = ln[k]
            if not a < b + c:
                break
            #if not b < c + a:
            #    break
            #if not c < a + b:
            #    continue
            r.append([a,b,c])

print len(r)
sys.stdout.flush()
sys.exit(0)

Fixed submission:
import bisect

N=int(raw_input())
LN=map(int, raw_input().split())

LN.sort()

r = 0
for i in xrange(N-1, 1, -1):
    a = LN[i]
    for j in xrange(i-1, 0, -1):
        b = LN[j]
        if a > 2*b:
            break
        idx = bisect.bisect_left(LN, a-b+1)
        if idx < j:
            r += j - idx

print r

Buggy python submission (verdict: Time Limit Exceeded):
N=raw_input()
LN=raw_input().split()

n = int(N)
ln = [int(i) for i in LN]

ln.sort()

r = []
for i in range(n-1, -1, -1):
    a = ln[i]
    for j in range(i-1, -1, -1):
        b = ln[j]
        if a > 2*b:
            break
        for k in range(j-1, -1, -1):
            # always, a > b > c
            c = ln[k]
            if not a < b + c:
                break
            #if not b < c + a:
            #    break
            #if not c < a + b:
            #    continue
            r.append([a,b,c])

print len(r)

Fixed submission:
import bisect

N=int(raw_input())
LN=map(int, raw_input().split())

LN.sort()

r = 0
for i in xrange(N-1, 1, -1):
    a = LN[i]
    for j in xrange(i-1, 0, -1):
        b = LN[j]
        if a > 2*b:
            break
        idx = bisect.bisect_left(LN, a-b+1)
        if idx < j:
            r += j - idx

print r

Buggy python submission (verdict: Time Limit Exceeded):
N=raw_input()
LN=raw_input().split()

n = int(N)
ln = [int(i) for i in LN]

c = []
for i in range(n):
    for j in range(i):
        for k in range(j):
            c.append([i,j,k])


r = []
for i in c:
    x, y, z = i
    a = ln[x]
    b = ln[y]
    c = ln[z]
    if not a < b + c:
        continue
    if not b < c + a:
        continue
    if not c < a + b:
        continue
    r.append(i)

print len(r)

Fixed submission:
import bisect

N=int(raw_input())
LN=map(int, raw_input().split())

LN.sort()

r = 0
for i in xrange(N-1, 1, -1):
    a = LN[i]
    for j in xrange(i-1, 0, -1):
        b = LN[j]
        if a > 2*b:
            break
        idx = bisect.bisect_left(LN, a-b+1)
        if idx < j:
            r += j - idx

print r

Buggy python submission (verdict: Time Limit Exceeded):
N=raw_input()
LN=raw_input().split()

n = int(N)
ln = [int(i) for i in LN]

c = [[x, y, z] for x in range(n) for y in range(n) for z in range(n) if x > y and y > z]

r = []
for i in c:
    x, y, z = i
    a = ln[x]
    b = ln[y]
    c = ln[z]
    if not a < b + c:
        continue
    if not b < c + a:
        continue
    if not c < a + b:
        continue
    r.append(i)

print len(r)

Fixed submission:
import bisect

N=int(raw_input())
LN=map(int, raw_input().split())

LN.sort()

r = 0
for i in xrange(N-1, 1, -1):
    a = LN[i]
    for j in xrange(i-1, 0, -1):
        b = LN[j]
        if a > 2*b:
            break
        idx = bisect.bisect_left(LN, a-b+1)
        if idx < j:
            r += j - idx

print r