Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        di = [e for e in ls[j+1:] if ls[i]+ls[j] > e]
        p += len(di)
print(p)


Fixed submission:
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
def is_ok(arg,l):
    return ls[arg] < l
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        l = ls[i] + ls[j]
        if is_ok(mid,l):
            ok = mid
        else:
            ng = mid
    return ok
for i in range(n-2):
    for j in range(i+1,n-1):
        ng = n
        ok = j
        m = meguru_bisect(ng, ok)
        p += m-j 
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if ls[k] < ls[i] + ls[j]:
                p += 1
print(p)


Fixed submission:
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
def is_ok(arg,l):
    return ls[arg] < l
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        l = ls[i] + ls[j]
        if is_ok(mid,l):
            ok = mid
        else:
            ng = mid
    return ok
for i in range(n-2):
    for j in range(i+1,n-1):
        ng = n
        ok = j
        m = meguru_bisect(ng, ok)
        p += m-j 
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
for i in range(n):
    for j in range(i):
        if ls[j]*2 <= ls[i]:
            continue
        for k in range(j):
            if ls[i] < ls[k] + ls[j]:
                p += 1
print(p)

Fixed submission:
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
def is_ok(arg,l):
    return ls[arg] < l
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        l = ls[i] + ls[j]
        if is_ok(mid,l):
            ok = mid
        else:
            ng = mid
    return ok
for i in range(n-2):
    for j in range(i+1,n-1):
        ng = n
        ok = j
        m = meguru_bisect(ng, ok)
        p += m-j 
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if ls[k] < ls[i] + ls[j]:
                p += 1
print(p)

Fixed submission:
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
def is_ok(arg,l):
    return ls[arg] < l
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        l = ls[i] + ls[j]
        if is_ok(mid,l):
            ok = mid
        else:
            ng = mid
    return ok
for i in range(n-2):
    for j in range(i+1,n-1):
        ng = n
        ok = j
        m = meguru_bisect(ng, ok)
        p += m-j 
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if ls[j] < ls[i] + ls[k] and ls[k] < ls[i] + ls[j]:
                p += 1
print(p)

Fixed submission:
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
def is_ok(arg,l):
    return ls[arg] < l
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        l = ls[i] + ls[j]
        if is_ok(mid,l):
            ok = mid
        else:
            ng = mid
    return ok
for i in range(n-2):
    for j in range(i+1,n-1):
        ng = n
        ok = j
        m = meguru_bisect(ng, ok)
        p += m-j 
print(p)