Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import itertools
import math
N = int(input())
S = list(input())

R = [0]*N
G = [0]*N
B = [0]*N

for i in range(N):
    if S[i] == 'R':
        R[i] += 1
    elif S[i] == 'G':
        G[i] += 1
    else:
        B[i] += 1

for i in range(N-1):
    R[i+1] += R[i]
    G[i+1] += G[i]
    B[i+1] += B[i]
ans = 0
#print(R,G,B)
for i in range(N-2):
    for j in range(i+1,N-1):
        if len(set([S[i],S[j]])) == 2:
            s = list(set(['R','G','B']) ^ set([S[i],S[j]]))[0]
            if s == 'R':
                ans += R[N-1] - R[j]
                if 2*j-i<=N-1 and S[2*j-i] == 'R':
                    ans -= 1
            if s == 'G':
                ans += G[N-1] - G[j]
                if 2*j-i <= N-1 and S[j+j-i] == 'G':
                    ans -= 1
            if s == 'B':
                ans += B[N-1] - B[j]
                if 2*j-i <= N-1 and S[j+j-i] == 'B':
                    ans -= 1
print(ans)


Fixed submission:
# coding: utf-8
import itertools
import math
import sys
#input→sys.stdin.readline半分の時間に
input=sys.stdin.readline
N = int(input())
S = list(input())

R = [0]*N
G = [0]*N
B = [0]*N

for i in range(N):
    if S[i] == 'R':
        R[i] += 1
    elif S[i] == 'G':
        G[i] += 1
    else:
        B[i] += 1

for i in range(N-1):
    R[i+1] += R[i]
    G[i+1] += G[i]
    B[i+1] += B[i]
ans = 0
#print(R,G,B)
for i in range(N-2):
    for j in range(i+1,N-1):
        if len(set([S[i],S[j]])) == 2:
            s = list(set(['R','G','B']) ^ set([S[i],S[j]]))[0]
            if s == 'R':
                ans += R[N-1] - R[j]
                if 2*j-i<=N-1 and S[2*j-i] == 'R':
                    ans -= 1
            if s == 'G':
                ans += G[N-1] - G[j]
                if 2*j-i <= N-1 and S[j+j-i] == 'G':
                    ans -= 1
            if s == 'B':
                ans += B[N-1] - B[j]
                if 2*j-i <= N-1 and S[j+j-i] == 'B':
                    ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    while True:
        N_ = abs(N-K)
        if N_ < N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)
else:
    print('jj')

Fixed submission:
#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    N = N % K
    while True:
        N_ = abs(N-K)
        if N_ < N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)

Buggy python submission (verdict: Time Limit Exceeded):
#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    while True:
        N_ = abs(N-K)
        if N_ < N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)
else:
    print('jj')

Fixed submission:
#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    N = N % K
    while True:
        N_ = abs(N-K)
        if N_ < N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)

Buggy python submission (verdict: Time Limit Exceeded):
#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    while True:
        N_ = abs(N-K)
        if N_ <= N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)
else:
    print('jj')

Fixed submission:
#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    N = N % K
    while True:
        N_ = abs(N-K)
        if N_ < N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

x, y, a, b, c = map(int,input().split())
L = []
Pa = list(map(int,input().split()))
Pb = list(map(int,input().split()))
Pc = list(map(int,input().split()))
Pa.sort(reverse = True)
Pb.sort(reverse = True)
Pc.sort(reverse = True)

ca = 0
cb = 0
cc = 0
flg1 = True
flg2 = True
ans = 0
for i in range(x+y):
    if ca == x:
        flg1 = False
        ca = 0
        Pa[ca] = 0
    if cb == y:
        flg2 = False
        cb = 0
        Pb[cb] = 0
    if Pa[ca] == max(Pa[ca], Pb[cb], Pc[cc]) and flg1:
        ans += Pa[ca]
        ca += 1
    elif Pb[cb] == max(Pa[ca], Pb[cb], Pc[cc]) and flg2:
        ans += Pb[cb]
        cb += 1
    else:
        ans += Pc[cc]
        cc += 1

print(ans)

Fixed submission:
# coding: utf-8

x, y, a, b, c = map(int,input().split())
L = []
Pa = list(map(int,input().split()))
Pb = list(map(int,input().split()))
Pc = list(map(int,input().split()))
Pa.sort(reverse = True)
Pb.sort(reverse = True)
Pc.sort(reverse = True)

ca = 0
cb = 0
cc = 0
flg1 = True
flg2 = True
flg3 = True
ans = 0
for i in range(x+y):
    if ca == x:
        flg1 = False
        ca = 0
        Pa[ca] = 0
    if cb == y:
        flg2 = False
        cb = 0
        Pb[cb] = 0
    if cc == c:
        flg3 = False
        cc = 0
        Pc[cc] = 0
    if Pa[ca] == max(Pa[ca], Pb[cb], Pc[cc]) and flg1:
        ans += Pa[ca]
        ca += 1
    elif Pb[cb] == max(Pa[ca], Pb[cb], Pc[cc]) and flg2:
        ans += Pb[cb]
        cb += 1
    elif Pc[cc] == max(Pa[ca], Pb[cb], Pc[cc]) and flg3:
        ans += Pc[cc]
        cc += 1
        #print("###")

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = list(input())

Q = int(input())

cnt = 0
for i in range(Q):
    l = list(map(str,input().split()))
    if int(l[0]) == 1:
        cnt += 1
    else:
        if int(l[1]) == 1:
            if cnt % 2 == 1:
                S.append(l[2])
            else:
                S.insert(0,l[2])
        else:
            if cnt % 2 == 1:
                S.insert(0,l[2])
            else:
                S.append(l[2])

if cnt % 2 == 1:
    S = S[::-1]
print(''.join(S))

Fixed submission:
from collections import deque

S = deque(list(input()))

Q = int(input())

cnt = 0
for i in range(Q):
    l = list(map(str,input().split()))
    if int(l[0]) == 1:
        cnt += 1
    else:
        if int(l[1]) == 1:
            if cnt % 2 == 1:
                S.append(l[2])
            else:
                S.appendleft(l[2])
        else:
            if cnt % 2 == 1:
                S.appendleft(l[2])
            else:
                S.append(l[2])

if cnt % 2 == 1:
    S = list(S)[::-1]
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

S = input()
Q = int(input())

for i in range(Q):
    l = list(input().split()) 
    if l[0] == '1':
        S = S[::-1]
    else:
        if l[1] == '1':
            S = l[2] + S
        else:
            S += l[2]
print(S)

Fixed submission:
from collections import deque

S = deque(list(input()))

Q = int(input())

cnt = 0
for i in range(Q):
    l = list(map(str,input().split()))
    if int(l[0]) == 1:
        cnt += 1
    else:
        if int(l[1]) == 1:
            if cnt % 2 == 1:
                S.append(l[2])
            else:
                S.appendleft(l[2])
        else:
            if cnt % 2 == 1:
                S.appendleft(l[2])
            else:
                S.append(l[2])

if cnt % 2 == 1:
    S = list(S)[::-1]
print(''.join(S))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N,k=map(int,input().split())

for i in range(N):
    if k**i>N:
        idx=i
        break
print(idx)

Fixed submission:
# coding: utf-8
N,k=map(int,input().split())
idx=1
for i in range(N):
    if k**i>N:
        idx=i
        break
print(idx)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N,a,b=map(int,input().split())
def pow(x, n):
        ans = 1
        while(n > 0):
            if(bin(n & 1) == bin(1)):
                ans = ans*x
            x = x*x
            n = n >> 1 #ビットシフト
        return ans
        
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans=pow(2,N)-1
ans-=cmb(N,a,mod)
ans-=cmb(N,b,mod)

print(ans)

Fixed submission:
# coding: utf-8
n,a_,b_=map(int,input().split())
l=[min(a_,n-a_),min(b_,n-b_)]
a,b=min(l),max(l)
mod=10**9+7
def pow_k(x,n):
    k=1
    #kは漏れたやつ
    while n>1:
        if n%2==1:
            k*=x
            n-=1
            k=k%mod
        x**=2
        x=x%mod
        n//=2
    
    return (k * x) % mod
    
#ans=pow_k(2,1000000000)
def modcomb(n,r,mod):
    X, Y =  1, 1
    r = min(r, n-r)
    for i in range(1,r+1):
        X = X * (n-i+1) % mod
        Y = Y * i % mod
    
    return (X * pow_k(Y, mod-2) % mod) % mod
ans=pow_k(2,n)-1-modcomb(n,a,mod)-modcomb(n,b,mod)
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline
N,a_,b_=map(int,input().split())
l=[min(a_,N-a_),min(b_,N-b_)]
a=min(l)
b=max(l)
#print(a,b)
cmb=1
mod=10**9+7
for i in range(1,a+1):
    cmb*=N-(a-i)
    cmb=cmb//i
    cmb=cmb%mod
ans=-1-cmb
for i in range(a+1,b+1):
    cmb*=N-(b-i)
    cmb=cmb//i
    cmb=cmb%mod

ans-=cmb

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x
ans+=pow_k(2,N)
print(ans%mod)

Fixed submission:
# coding: utf-8
n,a_,b_=map(int,input().split())
l=[min(a_,n-a_),min(b_,n-b_)]
a,b=min(l),max(l)
mod=10**9+7
def pow_k(x,n):
    k=1
    #kは漏れたやつ
    while n>1:
        if n%2==1:
            k*=x
            n-=1
            k=k%mod
        x**=2
        x=x%mod
        n//=2
    
    return (k * x) % mod
    
#ans=pow_k(2,1000000000)
def modcomb(n,r,mod):
    X, Y =  1, 1
    r = min(r, n-r)
    for i in range(1,r+1):
        X = X * (n-i+1) % mod
        Y = Y * i % mod
    
    return (X * pow_k(Y, mod-2) % mod) % mod
ans=pow_k(2,n)-1-modcomb(n,a,mod)-modcomb(n,b,mod)
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import fractions
N=int(input())
A=list(map(int,input().split()))
#def lcm(x,y):
 #   l=x*y/fractions.gcd(x,y)
  #  return l
l=A[0]
for i in range(N-1):
    l=int((A[i+1]*l)/fractions.gcd(A[i+1],l))
ans=0
for i in range(N):
    ans+=l//A[i]
print(ans%(10**9+7))

Fixed submission:
# coding: utf-8
# Your code here!
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
l=lcm_list(A)
ans=0

for i in range(N):
    ans+=(l//A[i])
print(ans%(10**9+7))

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import fractions
N=int(input())
A=list(map(int,input().split()))
def lcm(x,y):
    l=x*y/fractions.gcd(x,y)
    return l
l=A[0]
for i in range(N-1):
    l=int(A[i+1]*l/fractions.gcd(A[i+1],l))
ans=0
for i in range(N):
    ans+=l//A[i]
print(ans%(10**9+7))

Fixed submission:
# coding: utf-8
# Your code here!
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
l=lcm_list(A)
ans=0

for i in range(N):
    ans+=(l//A[i])
print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

N, S, K = map(int,input().split())
if S == 10**9:
    A = [S-1] * (N-K) + [S] * K
else:
    A = [S+1] * (N-K) + [S] * K

print(A)

Fixed submission:
# coding: utf-8
# Your code here!
N,K,S=map(int,input().split())
ans=[]
p=N-K

if S!=10**9:
    for i in range(N-K):
        ans.append(str(S+1))
    for i in range(K):
        ans.append(str(S))
else:
    for i in range(N-K):
        ans.append(str(1))
    for i in range(K):
        ans.append(str(S))
#print(ans)
#ans=' '.join(ans)

#print(len(ans))


#print(" ".join([str(n) for n in ans]))
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
r,s,p=map(int,input().split())
t=[i for i in input()]
tmp=0
for i in range(K):
    if t[i]=='s':
        tmp+=r
    elif t[i]=='p':
        tmp+=s
    else:
        tmp+=p   
    #print(tmp)
    #print('制約なしで勝ち')
flg=0
for i in range(K,N):
    if t[i]!=t[i-K]:
        if t[i]=='s':
            tmp+=r
            #print('グーで勝ち')
        elif t[i]=='p':
            tmp+=s
            #print('チョキで勝ち↓')
        else:
            tmp+=p
            #print('パーで勝ち')
    else:
        t[i]='w'*i
        #print('かぶった（1回目）')
        
            
    #print(tmp)
#print('ans='+str(tmp))
print(tmp)

Fixed submission:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
r,s,p=map(int,input().split())
t=[i for i in input()]
tmp=0
for i in range(K):
    if t[i]=='s':
        tmp+=r
    elif t[i]=='p':
        tmp+=s
    else:
        tmp+=p   
    #print(tmp)
    #print('制約なしで勝ち')
flg=0
for i in range(K,N):
    if t[i]!=t[i-K]:
        if t[i]=='s':
            tmp+=r
            #print('グーで勝ち')
        elif t[i]=='p':
            tmp+=s
            #print('チョキで勝ち↓')
        else:
            tmp+=p
            #print('パーで勝ち')
    else:
        t[i]='w'
        #print('かぶった（1回目）')
        
            
    #print(tmp)
#print('ans='+str(tmp))
print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import math
#n, k, s = map(int,input().split())
n = int(input())
A = list(map(int,input().split()))
ans = 0
MOD=10**9+7
for i in range(n-1):
    for j in range(i+1, n):
        ans += A[i] ^ A[j]
        ans %= MOD
print(ans)

Fixed submission:
# coding: utf-8
import math
#n, k, s = map(int,input().split())
n = int(input())
A = list(map(int,input().split()))
ans = 0
MOD=10**9+7
L0 = [0] * 60
L1 = [0] * 60
for i in range(n):
    b = A[i]
    #print(b)
    b = format(b, '060b')
    #print(b)
    for j in range(60):
        if b[60 - j  -1] == "1":
            L1[j] += 1
        else:
            L0[j] += 1
#print(L0)
#print(L1)

for i in range(60):
    ans += L0[i] * L1[i] * 2**i
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a=list(map(int,input().split()))
ans=2020202020
for i in range(1,N):
    mae=sum(a[:i])
    ato=sum(a)-mae
    ans=min(ans,abs(mae-ato))
print(ans)

Fixed submission:
N = int(input())
a=list(map(int,input().split()))
ans=2020202020
s=sum(a)
mae=a[0]
for i in range(1,N):
    mae+=a[i]
    ato=s-mae
    if mae-ato>0:
        ans=min(abs(sum(a[:i])-sum(a[i:])),abs(sum(a[:i+1])-sum(a[i+1:])))
        break
    else:
        ans=min(ans,abs(mae-ato))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a=list(map(int,input().split()))
gos=[0]*(N-1)
ans=max(a)
for i in range(1,N):
    mae=sum(a[:i])
    ato=sum(a)-mae
    ans=min(ans,abs(mae-ato))
print(ans)

Fixed submission:
N = int(input())
a=list(map(int,input().split()))
ans=2020202020
s=sum(a)
mae=a[0]
for i in range(1,N):
    mae+=a[i]
    ato=s-mae
    if mae-ato>0:
        ans=min(abs(sum(a[:i])-sum(a[i:])),abs(sum(a[:i+1])-sum(a[i+1:])))
        break
    else:
        ans=min(ans,abs(mae-ato))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a=list(map(int,input().split()))
gos=[0]*(N-1)
for i in range(1,N):
    mae=sum(a[:i])
    ato=sum(a)-mae
    gos[i-1]=(abs(mae-ato))
print(min(gos))

Fixed submission:
N = int(input())
a=list(map(int,input().split()))
ans=2020202020
s=sum(a)
mae=a[0]
for i in range(1,N):
    mae+=a[i]
    ato=s-mae
    if mae-ato>0:
        ans=min(abs(sum(a[:i])-sum(a[i:])),abs(sum(a[:i+1])-sum(a[i+1:])))
        break
    else:
        ans=min(ans,abs(mae-ato))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a=list(map(int,input().split()))
gos=[]
for i in range(1,N):
    mae=sum(a[:i])
    ato=sum(a)-mae
    gos.append((abs(mae-ato)))
print(min(gos))

Fixed submission:
N = int(input())
a=list(map(int,input().split()))
ans=2020202020
s=sum(a)
mae=a[0]
for i in range(1,N):
    mae+=a[i]
    ato=s-mae
    if mae-ato>0:
        ans=min(abs(sum(a[:i])-sum(a[i:])),abs(sum(a[:i+1])-sum(a[i+1:])))
        break
    else:
        ans=min(ans,abs(mae-ato))
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
L=[]
for i in range(1,int(math.sqrt(N))):
  if N%i==0:
    L.append(i+int(N/i)-2)
  else:
    pass
print(min(L))

Fixed submission:
import math
N=int(input())
L=[]
for i in range(1,int(math.sqrt(N))+1):
  if N%i==0:
    L.append(i+int(N/i)-2)
  else:
    pass
print(min(L))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input(),split())

if a <= b*2:
  print(0)
else:
  print(a-b*2)

Fixed submission:
a,b = map(int,input().split())
 
if a <= b*2:
  print(0)
else:
  print(a-b*2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
l=list(map(int,input().split()))
ans=0
N_=int((N*(N-1))/2)
for i in range(N_-1):
  life=0
  for j in range(i+1,N_):
    life+=l[i]*l[j]
  ans+=life
print(ans)

Fixed submission:
N = int(input())
l=list(map(int,input().split()))
ans=0
N_=int((N*(N-1))/2)
for i in range(N-1):
  life=0
  for j in range(i+1,N):
    life+=l[i]*l[j]
  ans+=life
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S=sorted(list(map(input())))
cnt=0
for i in range(N-1):
  if S[i]!=S[i+1]:
    cnt+=1
    
print(cnt)

Fixed submission:
import copy

N = int(input())
S = list(input())
l = copy.deepcopy(S)

for i in range(N-1):
  if S[i] == S[i+1]:
    l[i]=0
  
l_=[i for i in l if i!=0]
print(len(l_))

Buggy python submission (verdict: Runtime Error):
N = int(input())
S=sorted(list(map(input())))
cnt=0
for i in range(N-1):
  if S[i]==S[i+1]:
    cnt+=1
    
print(cnt)

Fixed submission:
import copy

N = int(input())
S = list(input())
l = copy.deepcopy(S)

for i in range(N-1):
  if S[i] == S[i+1]:
    l[i]=0
  
l_=[i for i in l if i!=0]
print(len(l_))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import itertools
N=int(input())
L=list(map(int,input().split()))
ans=0
l=list(itertools.combinations(L,3))
#print(max(l[0]))
kumi=len(l)
for i in range(kumi):
    l[i]=list(l[i])
    a=max(l[i])
    l[i].remove(a)
    if a<sum(l[i]):
        ans+=1
print(ans)

Fixed submission:
from bisect import bisect_right
 
N = int(input())
L = sorted(list(map(int, input().split())))
 
ans = 0
for i in range(1, N-1):
    for j in range(i+1, N):
        ans += max(0, i - bisect_right(L, L[j] - L[i]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            l=[L[i],L[j],L[k]]
            #print(l)
            m=max(l)
            l.remove(m)
            if m<sum(l):
                ans+=1
print(ans)

Fixed submission:
from bisect import bisect_right
 
N = int(input())
L = sorted(list(map(int, input().split())))
 
ans = 0
for i in range(1, N-1):
    for j in range(i+1, N):
        ans += max(0, i - bisect_right(L, L[j] - L[i]))
print(ans)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right
 
N = int(input())
L = sorted(list(map(int, input().split())))
 
ans = 0
for i in range(1, N-1):
    for j in range(i+1, N):
        ans += max(0, i - bisect_right(L, L[j] - L[i]))
print(ans)
from bisect import bisect_right

N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(1, N-1):
    for j in range(i+1, N):
        ans += max(0, i - bisect_right(L, L[j] - L[i]))
print(ans)


Fixed submission:
from bisect import bisect_right
 
N = int(input())
L = sorted(list(map(int, input().split())))
 
ans = 0
for i in range(1, N-1):
    for j in range(i+1, N):
        ans += max(0, i - bisect_right(L, L[j] - L[i]))
print(ans)
Buggy python submission (verdict: Runtime Error):
#coding utf-8
import fractions
import math
a, b = map(int,input().split())
ans = 0
g = math.gcd(a,b)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = len(factorization(g)) + 1
if a == 1 or b == 1:
    ans = 1
print(ans)

Fixed submission:
#coding utf-8
import fractions
import math
a, b = map(int,input().split())
ans = 0
g = fractions.gcd(a,b)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = len(factorization(g)) + 1
if a == 1 or b == 1:
    ans = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K,Q = map(int,input().split())
K=K-Q
 
a=[]
for i in range(Q):
  a.append(int(input()))
cnt=[K-Q]*N
for i in range(1,N+1):
  cnt[i-1] += a.count(i)
  if cnt[i] > 0:
    print("Yes")
  else:
    print("No")

Fixed submission:
# coding: utf-8
# Your code here!

N, K, Q = map(int,input().split())
L = [0]*N
for i in range(Q):
    a = int(input())
    L[a-1] += 1

for i in range(N):
    if Q - L[i] < K:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Runtime Error):
N,K,Q = map(int,input().split())
K=K-Q

a=[]
for i in range(Q):
  a.append(int(input()))
cnt=[K-Q]*N
for i in range(1,N+1):
  a.count(i) += cnt[i-1]
  if cnt[i] > 0:
    print("Yes")
  else:
    print("No")

Fixed submission:
# coding: utf-8
# Your code here!

N, K, Q = map(int,input().split())
L = [0]*N
for i in range(Q):
    a = int(input())
    L[a-1] += 1

for i in range(N):
    if Q - L[i] < K:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())
a=[]
for i in range(Q):
  a.append(int(input()))

for i in range(1,N+1):
  if a.count(i) >= (Q-K+1):
    print("Yes")
  else:
    print("No")

Fixed submission:
# coding: utf-8
# Your code here!

N, K, Q = map(int,input().split())
L = [0]*N
for i in range(Q):
    a = int(input())
    L[a-1] += 1

for i in range(N):
    if Q - L[i] < K:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
    N,M=map(int,input().split())
    A=sorted(list(map(int,input().split())))
    for i in range(M):
        A[N-1]=int(A[N-1]/2)
        A.sort()
    print(sum(A))
if __name__ == '__main__':
    main()

Fixed submission:
import heapq
N,M=map(int,input().split())
A =  [-int(x) for x in input().split()]
A.sort()
for i in range(M):
    rem=A[0]
    heapq.heappush(A,int(rem/2))
    heapq.heappop(A)
    
print(-sum(A))

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

for i in range(M):
  A[N-1]=int(A[N-1]/2)
  A.sort()
print(sum(A))

Fixed submission:
import heapq
N,M=map(int,input().split())
A =  [-int(x) for x in input().split()]
A.sort()
for i in range(M):
    rem=A[0]
    heapq.heappush(A,int(rem/2))
    heapq.heappop(A)
    
print(-sum(A))
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
print(math,factorial(N))

Fixed submission:
N=int(input())
print(N**3)