Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=list(input())
cnt=0
for i in range(N):
    for j in range(i+1,N):
        if S[i]!=S[j]:
            for k in range(j+1,N):
                if S[j]!=S[k] and S[i]!=S[k] and (j-i!=k-j):
                    cnt+=1
print(cnt)

Fixed submission:
N=int(input())
S=input()
cnt=S.count("R")*S.count("G")*S.count("B")
for i in range(N):
    for j in range(i+1,N):
        k=2*j-i
        if k<N and S[i]!=S[j]!=S[k]!=S[i]:
            cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=list(input())
cnt=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if S[i]!=S[j]!=S[k] and S[i]!=S[k] and (j-i!=k-j):
                cnt+=1
print(cnt)

Fixed submission:
N=int(input())
S=input()
cnt=S.count("R")*S.count("G")*S.count("B")
for i in range(N):
    for j in range(i+1,N):
        k=2*j-i
        if k<N and S[i]!=S[j]!=S[k]!=S[i]:
            cnt-=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,A,B,C=map(int,input().split())
p=sorted(list(map(int,input().split())))[::-1][:X]
q=sorted(list(map(int,input().split())))[::-1][:Y]
r=sorted(list(map(int,input().split())))[::-1]
pq=sorted(p+q)
for R in r:
    for i in range(len(pq)):
        if pq[i]<R:
            pq[i]=R
            break
print(sum(pq))

Fixed submission:
X,Y,A,B,C=map(int,input().split())
p=sorted(list(map(int,input().split())))[::-1][:X]
q=sorted(list(map(int,input().split())))[::-1][:Y]
r=list(map(int,input().split()))
ans=sorted(p+q+r)[::-1][:X+Y]
print(sum(ans))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=["a"]
S="abcdefghijklmn"
for i in range(N-1):
    B=[]
    for a in A:
        for s in S[:len(set(a))+1]:
            B.append(a+s)
print("\n".join(B))

Fixed submission:
N=int(input())
A=["a"]
S="abcdefghijklmn"
for i in range(N-1):
    B=[]
    for a in A:
        for s in S[:len(set(a))+1]:
            B.append(a+s)
    A=B[::]
print("\n".join(A))
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
S="b"*A+"r"*B
ans=(N//(A+B))*A+S[:N%(A+B)].count("b")
print(ans)

Fixed submission:
N,A,B=map(int,input().split())
ans=N//(A+B)*A
ans+=min(N%(A+B),A)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
for i in range(Q):
    q=list(input().split())
    if q[0]=="1":
        S=S[::-1]
    else:
        if q[1]=="1":
            S=q[2]+S
        else:
            S=S+q[2]
print(S)


Fixed submission:
S=input()
Q=int(input())
T=""
for i in range(Q):
    q=input().split()
    if q[0]=="1":
        T,S=S,T
    else:
        if q[1]=="1":
            T+=q[2]
        else:
            S+=q[2]
print(T[::-1]+S)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[]
Word=set()
for i in range(N):
    s=input()
    Word.add(s)
    S.append(s)
Word=list(Word)
ans=[[0]*2 for i in range(len(Word))]
maxcnt=0
for k in range(len(Word)):
    ans[k][0]=Word[k]
    ans[k][1]=S.count(Word[k])
    maxcnt=max(maxcnt,ans[k][1])
ans=sorted(ans)
for i in range(len(Word)):
    if ans[i][1]==maxcnt:
        print(ans[i][0])

Fixed submission:
from collections import*
n,*s=open(0)
cnt=Counter(s).most_common()
ans=sorted(a*(b==cnt[0][1])for a,b in cnt)
for i in ans:
    print(i,end="")
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P=list(map(int,input().split()))
ans=0
for i in range(N-K+1):
    kitai=0
    for j in range(K):
        kitai+=((P[i+j]+1)/2)
    ans=max(ans,kitai)
print(ans)

Fixed submission:
N,K=map(int,input().split())
P=list(map(int,input().split()))
mx=sm=sum(P[:K])
for i in range(N-K):
    sm=sm+P[i+K]-P[i]
    mx=max(mx,sm)
print((mx+K)/2)
Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
mxa=max(a for a,b in ab)
dp=[0]*(N+mxa)
for i in range (N+mxa):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(min(dp[H:]))

Fixed submission:
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(min(dp[H:]))
Buggy python submission (verdict: Runtime Error):
import math
A,B=map(int,input().split())
print((A*B)//math.gcd(A,B))


Fixed submission:
from fractions import gcd
A,B=map(int,input().split())
print((A*B)//gcd(A,B))
Buggy python submission (verdict: Runtime Error):
X=int(input())
N=X//100
M=X%100
A=[0,1,2,3,4,5]
dp=[[0]*(M+1) for i in range(N+1)]
dp[0][0]=1
for i in range(N):
    for k in range(M+1):
        dp[i+1][k]|=dp[i][k]
        if k>=A[i]:
            dp[i+1][k]|=dp[i][k-A[i]]
print(dp[N][M])

Fixed submission:
X=int(input())
d,m=divmod(X,100)
print(1 if m<=(d*5) else 0)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(1,N+1):
    ans.append(A.index(i)+1)
print(*ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
ans=[0]*N
for i in range(N):
    ans[A[i]-1]=i+1
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
cnt=0
S=[input() for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if sorted(S[i])==sorted(S[j]):
            cnt+=1
print(cnt)

Fixed submission:
N=int(input())
cnt=0
dict={}
for i in range(N):
    s="".join(sorted(input()))
    if s in dict:
        cnt+=dict[s]
        dict[s]+=1
    else:
        dict[s]=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
from math import gcd
A,B,C,D=map(int,input().split())
A-=1
S=B-B//C-B//D+B//((C*D)//gcd(C,D))
T=A-A//C-A//D+A//((C*D)//gcd(C,D))
print(S-T)

Fixed submission:
from fractions import gcd
A,B,C,D=map(int,input().split())
A-=1
S=B-B//C-B//D+B//((C*D)//gcd(C,D))
T=A-A//C-A//D+A//((C*D)//gcd(C,D))
print(S-T)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
dp=[0]*(N)
for _ in range(M):
    L,R=map(int,input().split())
    for j in range(L-1,R):
        dp[j]+=1
print(dp.count(M))

Fixed submission:
N,M=map(int,input().split())
l=0
r=float("Inf")
for i in range(M):
    L,R=map(int,input().split())
    l=max(l,L)
    r=min(r,R)
print(max(r-l+1,0))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=list(map(int,input().split()))
for i in range(M):
    B,C=map(int,input().split())
    A.extend([C]*B)
A=sorted(A)[::-1]
print(sum(A[:N]))

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
BC.sort(key=lambda x:-x[1])
for B,C in BC:
    A.extend([C]*B)
    if len(A)>N*2:
        break
A.sort(reverse=True)
print(sum(A[:N]))
Buggy python submission (verdict: Runtime Error):
S=[int(input()) for _ in range(5)]
T=[]
for i in range(5):
    if S[i]%10!=0:
        T.append(10-S[i]%10)
print(sum(S)+sum(T)-max(T))

Fixed submission:
S=[int(input()) for _ in range(5)]
T=[]
for i in range(5):
    T.append((10-S[i])%10)
print(sum(S)+sum(T)-max(T))
Buggy python submission (verdict: Time Limit Exceeded):
Mx = 9999999999999

H, N = map(int,input().split())
L = [list(map(int,input().split())) for i in range(N)]

D = [Mx] * 40000

D[0] = 0

for i in range(H+1):
    for spell in L:
        if D[i] + spell[1] < D[i+spell[0]]:
            D[i+spell[0]] = D[i] + spell[1]

print(min(D[H:]))

Fixed submission:
import sys
Mx = 999999999

H, N = map(int,sys.stdin.readline().split())
L = [list(map(int,sys.stdin.readline().split())) for i in range(N)]

D = [Mx] * 40000

D[0] = 0

for i in range(H+1):
    for spell in L:
        if D[i] + spell[1] < D[i+spell[0]]:
            D[i+spell[0]] = D[i] + spell[1]

sys.stdout.write(str(min(D[H:])))
Buggy python submission (verdict: Runtime Error):
import sys

from math import pi

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(get_ints())
def input(): return sys.stdin.readline().strip().split()

r = int(input())
print(2*pi*r)

Fixed submission:
import sys


from math import pi

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(get_ints())
def input(): return sys.stdin.readline().strip()

r = int(input())
print(2*pi*r)

Buggy python submission (verdict: Runtime Error):
import sys

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(get_ints())
def input(): return sys.stdin.readline().strip().split()

r = int(input())
print(2*pi*r)

Fixed submission:
import sys


from math import pi

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(get_ints())
def input(): return sys.stdin.readline().strip()

r = int(input())
print(2*pi*r)

Buggy python submission (verdict: Runtime Error):
import sys
from math import pi
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(get_ints())
def input(): return sys.stdin.readline().strip().split()

r = int(input())
print(2*pi*r)

Fixed submission:
import sys


from math import pi

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(get_ints())
def input(): return sys.stdin.readline().strip()

r = int(input())
print(2*pi*r)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
inf = float("inf")
# sys.setrecursionlimit(1000000)

from bisect import bisect_left,bisect_right
# import numpy as np

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())
Arr = get_array()
Arr.sort()

ans = 0
for i in range(n):
    for j in range(i+1,n):
        new = Arr[i]+Arr[j]
        ans+=bisect_left(Arr[j+1 : ], new)
print(ans)

Fixed submission:
import sys
inf = float("inf")
from bisect import bisect_left,bisect_right

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())
Arr = get_array()
Arr.sort()

ans = 0
for i in range(n):
    for j in range(i+1,n):
        new = Arr[i]+Arr[j]
        ans+=bisect_left(Arr[j+1:], new)
print(ans)
Buggy python submission (verdict: Runtime Error):
#
# Yet I'm feeling like
# 	There is no better place than right by your side
# 		I had a little taste
# 			And I'll only spoil the party anyway
# 				'Cause all the girls are looking fine
# 					But you're the only one on my mind

import sys
# import re
inf = float("inf")
# sys.setrecursionlimit(1000000)

# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod,MOD=1000000007,998244353
# vow=['a','e','i','o','u']
# dx,dy=[-1,1,0,0,-1,1,-1,1],[0,0,1,-1,1,1,-1,-1]

# import operator as op
# from functools import reduce
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd,log10,atan,tan
# from bisect import bisect_left,bisect_right,insort_left
# import numpy as np
# import queue
# from copy import deepcopy
# import random

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
Arr=get_array()
result=[]
for i in range(n):
    result.append((Arr[i],i))
result.sort()
ans=[]
for i in result:
    ans.append(i[1]+1)
print(*ans)

Fixed submission:
import sys
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
Arr=get_array()
result=[]
for i in range(n):
  result.append((Arr[i],i+1))
result.sort()
ans=[]
for i in result:
  ans.append(i[1])
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys,math
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
S = list(input())

ANS = 0

for i in range(N):
    f = S[i]
    for j in ['R','G','B']:
        if j==f:
            continue
        #残りの二文字のどっちかに一致するものを探す
        for k in range(i+1,N):
            elm = S[k]
            if elm!=j:
                continue
            s = elm
            #距離
            dist = k-i
            for l in range(k+1,N):
                if S[l]!=s and S[l]!=f:
                    if dist != l-k:
                        ANS += 1
print(ANS)

Fixed submission:
import sys,math
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
S = list(input())

ANS = 0
dp = [None]*N
r,g,b = 0,0,0
for i in range(N):
    elm = S[i]
    if elm=='R':
        r += 1
    elif elm=='G':
        g += 1
    else:
        b += 1
    dp[i] = [r,g,b]

TTL = dp[-1]
for i in range(N):
    f = S[i]
    for j in ['R','G','B']:
        if j==f:
            continue

        for k in range(i+1,N):
            elm = S[k]
            if elm!=j:
                continue
            for l in ['R','G','B']:
                if l==f or l==elm:
                    continue

                if l=='R':
                    d = 0
                elif l=='G':
                    d = 1
                else:
                    d = 2
                ANS += TTL[d] - dp[k][d]

                if k+k-i<N and S[k+k-i]==l:
                    ANS -= 1
print(ANS)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]

N,X,Y = map(int,input().split(' '))
M = -(-(X+Y)//2)
ANS = []
for i in range(N):
    for j in range(i+1,N):
        d = j-i
        dd = abs(X-1-i)+1+abs(Y-1-j)
        ANS.append(min(d,dd))
ANS.sort()
L = len(ANS)
cnt = 0
ans = [0]*(N-1)
while cnt != L:
    k = ANS[cnt]
    ans[k-1] += 1
    cnt += 1
for i in range(N-1):
    print(ans[i])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]

N,X,Y = map(int,input().split(' '))
M = -(-(X+Y)//2)
ANS = []
for i in range(N):
    for j in range(i+1,N):
        d = j-i
        dd = abs(X-1-i)+1+abs(Y-1-j)
        ANS.append(min(d,dd))
ANS.sort()
L = len(ANS)
cnt = 0
ans = [0]*(N-1)
while cnt != L:
    k = ANS[cnt]
    ans[k-1] += 1
    cnt += 1
for i in range(N-1):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W = map(int,input().split(' '))
A = W//2+1
if W==1 or H==1:
    print(1)
    exit()
if H%2==0:
    print(W*H//2)
else:
    print(W*(H-1)//2+A)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
S = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
L = S.split(', ')
N = int(input())
print(L[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]

H,N = map(int,input().split(' '))

A = [None]*N
B = [None]*N
for i in range(N):
    a,b = list(map(int, input().split()))
    A[i] = a
    B[i] = b

INF = float('inf')
dp = [INF]*(H+1)
dp[H] = 0

for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(H,0,-1):
        aft = j - a
        if aft<=0:
            dp[0] = min(dp[0],dp[j]+b)
        else:
            dp[aft] = min(dp[aft],dp[j]+b)
print(dp[0])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]

H,N = map(int,input().split(' '))

A = [None]*N
B = [None]*N
for i in range(N):
    a,b = list(map(int, input().split()))
    A[i] = a
    B[i] = b

INF = float('inf')
dp = [INF]*(H+1)
dp[H] = 0

for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(H,0,-1):
        aft = j - a
        if aft<=0:
            dp[0] = min(dp[0],dp[j]+b)
        else:
            dp[aft] = min(dp[aft],dp[j]+b)
print(dp[0])

Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]

H,N = map(int,input().split(' '))

A = [None]*N
B = [None]*N
for i in range(N):
    a,b = list(map(int, input().split()))
    A[i] = a
    B[i] = b

INF = float('inf')
dp = [INF]*(H+1)
dp[H] = 0

for i in raneg(N):
    a = A[i]
    b = B[i]
    for j in range(H,0,-1):
        aft = j - a
        if aft<=0:
            dp[0] = min(dp[0],dp[j]+b)
        else:
            dp[aft] = min(dp[aft],dp[j]+b)
print(dp[0])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]

H,N = map(int,input().split(' '))

A = [None]*N
B = [None]*N
for i in range(N):
    a,b = list(map(int, input().split()))
    A[i] = a
    B[i] = b

INF = float('inf')
dp = [INF]*(H+1)
dp[H] = 0

for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(H,0,-1):
        aft = j - a
        if aft<=0:
            dp[0] = min(dp[0],dp[j]+b)
        else:
            dp[aft] = min(dp[aft],dp[j]+b)
print(dp[0])
Buggy python submission (verdict: Runtime Error):

import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
S = list(input())
dp = {}
st = [None]*9
ok = []
l = [None]*N
las = 0
for i in range(N-1,-1,-1):
    s = S[i]
    st[int(s)] = i
    l[i] = las
    if s in dp:
        dp[s].append(i)
    else:
        dp[s] = [i]
        las += 1

ans = 1
for i in range(0,9):
    if st[i]==None:
        continue
    start = st[i] #iが初めて出てくる位置
    for j in range(1,10):
        k = str(j)
        if not k in dp:
            continue
        middle = dp[k]
        ok = len(dp)-1
        ng = 0
        while ok-ng>1:
            m = (ok+ng)//2
            if middle[m]>start:
                ng = m
            else:
                ok = m
        ans *= l[ok]
print(ans)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
S = input()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    _idx = 0
    flag = True
    for n in num:
        ind = S[_idx:].find(n)
        if ind==-1:
            flag = False
            break
        else:
            _idx = _idx + ind+1
    if flag:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys,math
def input():
    return sys.stdin.readline()[:-1]


a,b,x = map(int,input().split(' '))

t = x/(a**2)
half = b/2
if t<half:
    a_2 = x/b
    b_2 = b
else:
    a_2 = a
    b_2 = (b-t)*2
c = (a_2**2+b_2**2)**0.5
cos1 = ((a_2**2)+(c**2)-(b_2**2))/(2*a_2*c)
print(math.degrees(math.acos(cos1)))

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]


N = int(input())
cnt = 0
n = N//2+1
k = int(N**0.5)+1
b = 0
for i in range(k,1,-1):
    if N%i==0:
        b = N//i
        a = i
        print(a+b-2)
        exit()
else:
    print(N-1)
Buggy python submission (verdict: Runtime Error):
import sys,math
def input():
    return sys.stdin.readline()[:-1]


a,b,x = map(int,input().split(' '))

t = x/(a**2)
half = b/2
if t<half:
    a_2 = x/b
    b_2 = b
else:
    a_2 = a
    b_2 = (b-t)*2
c = (a_2**2+b_2**2)**0.5
cos1 = (a_2**2+c**2-b_2**2)/(2*a*c)
print(math.degrees(math.acos(cos1)))

Fixed submission:
import sys,math
def input():
    return sys.stdin.readline()[:-1]


a,b,x = map(int,input().split(' '))

t = x/(a**2)
half = b/2
if t<half:
    a_2 = ((x/a)/b)*2
    b_2 = b
else:
    a_2 = a
    b_2 = (b-t)*2
c = (a_2**2+b_2**2)**0.5
cos1 = ((a_2**2)+(c**2)-(b_2**2))/(2*a_2*c)
print(math.degrees(math.acos(cos1)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
pre_a = -1
for i in range(N-1,1,-1):
    tmp = 0
    a = l[i]
    lm = a//2
    for j in range(i-1,0,-1):
        b = l[j]
        if b<=lm:
            continue
        a_b = a+b
        for k in range(j):
            c = l[k]
            if (b+c>a):
                tmp += j-k
                break
    cnt += tmp
    pre_a = a
print(cnt)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
pre_a = -1
for i in range(N-1,1,-1):
    tmp = 0
    a = l[i]
    lm = a//2
    pre_k = 0
    for j in range(i-1,0,-1):
        b = l[j]
        if b<=lm:
            continue
        a_b = a+b
        for k in range(pre_k,j):
            c = l[k]
            if (b+c>a):
                tmp += j-k
                pre_k = k
                break
    cnt += tmp
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
pre_a = -1
for i in range(N-1,1,-1):
    tmp = 0
    a = l[i]
    lm = a//2
    for j in range(i-1,0,-1):
        b = l[j]
        if b<=lm:
            continue
        a_b = a+b
        for k in range(j):
            c = l[k]
            if (b+c>a):
                tmp += j-k
                break
    cnt += tmp
    pre_a = a
print(cnt)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
pre_a = -1
for i in range(N-1,1,-1):
    tmp = 0
    a = l[i]
    lm = a//2
    pre_k = 0
    for j in range(i-1,0,-1):
        b = l[j]
        if b<=lm:
            continue
        a_b = a+b
        for k in range(pre_k,j):
            c = l[k]
            if (b+c>a):
                tmp += j-k
                pre_k = k
                break
    cnt += tmp
print(cnt)