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

ans = 0
i = 0
while i < N-2:
    j = i+1
    while j < N-1:
        a = L[i]
        b = L[j]
        if L[j+1] < a+b:
            cOK = j+1
            cNG = N
            while cOK+1<cNG:
                ci = (cOK +cNG)//2
                if L[ci]<a+b:
                    cOK = ci
                else:
                    cNG = ci
            ans += cOK-j
        j += 1
    i += 1

print(ans)

Fixed submission:
N = int(input())
sticks1 = list(map(int, input().split()))

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            #sticks[i]>sticks[j]>sticks[k]
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
A = np.sort(list(map(int,input().split())))[::-1]
ans = 0
i = 0
while i < N-2:
    j = i+1
    while j < N-1:
        a = A[i]
        b = A[j]
        C = A[j+1:]
        J = (C>a-b)
        if (np.any(J)):
            ans += np.size(C[J])
        j += 1
    i += 1

print(ans)

Fixed submission:
N = int(input())
sticks1 = list(map(int, input().split()))

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            #sticks[i]>sticks[j]>sticks[k]
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
A = np.sort(list(map(int,input().split())))[::-1]
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        a = A[i]
        b = A[j]
        C = A[j+1:]
        J = (C>a-b)
        if (np.any(J)):
            ans += np.size(C[J])

print(ans)

Fixed submission:
N = int(input())
sticks1 = list(map(int, input().split()))

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            #sticks[i]>sticks[j]>sticks[k]
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
A = np.sort(list(map(int,input().split())))[::-1]
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        a = A[i]
        b = A[j]
        C = A[j+1:]
        J = (C<a+b) * (C>a-b)
        if (np.any(J)):
            ans += np.size(C[J])

print(ans)

Fixed submission:
N = int(input())
sticks1 = list(map(int, input().split()))

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            #sticks[i]>sticks[j]>sticks[k]
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)

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

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
fj = fk = True
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if not fj:
            fj=True
            break
        else:
            k=j+1
            while k<N:
                if sticks[i]<sticks[j]+sticks[k]:
                    count += 1
                    k += 1
                    continue
                else:
                    if j+1 == k :
                        fj = False
                    break
      
print(count)

Fixed submission:
N = int(input())
sticks1 = list(map(int, input().split()))

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            #sticks[i]>sticks[j]>sticks[k]
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)

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

#N=len(sticks)
sticks.sort(reverse = True)
count = 0
fj = True
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if not fj:
            fj=True
            break
        else:
            for k in range(j+1,N):
                #stick[i]>j>k
                if sticks[i]<sticks[j]+sticks[k]:
                    count += 1
                else:
                    if j+1 == k :
                        fj = False
                    break
        
print(count)


Fixed submission:
N = int(input())
sticks1 = list(map(int, input().split()))

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            #sticks[i]>sticks[j]>sticks[k]
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)

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

#N=len(sticks)
sticks.sort(reverse = True)
count = 0
fj = fk = True
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if not fj:
            fj=True
            break
        else:
            for k in range(j+1,N):
                #stick[i]>j>k
                if sticks[i]<sticks[j]+sticks[k]:
                    count += 1
                else:
                    if j+1 == k :
                        fj = False
                    break
        
print(count)

Fixed submission:
N = int(input())
sticks1 = list(map(int, input().split()))

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            #sticks[i]>sticks[j]>sticks[k]
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)

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

N=len(sticks)
sticks.sort()
count = 0
for i in range(0,N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if sticks[i]+sticks[j]>sticks[k]:
                count +=1
print(count)

Fixed submission:
N = int(input())
sticks1 = list(map(int, input().split()))

#N=len(sticks)
sticks = sorted(sticks1, reverse=True)
#sticks.sort(reverse = True)
count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            #sticks[i]>sticks[j]>sticks[k]
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)