Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [int(i) for i in input().split()]
if 2 * max(l) - sum(l) < 0:
    print("Yes")
else:
    print("No")

Fixed submission:
s = int(input())
a = [s]
i = 1
while True :
    if a[i-1] % 2 == 0:
        t = int((a[i-1])/2)
    else:
        t = int((a[i-1])*3+1)
        
    i +=1 
    
    if t in a:
        print(i)
        break  
    a.append(t)
Buggy python submission (verdict: Runtime Error):
d = int(input())

if d == 25:
    pritn("Christmas")
elif d == 24:
    print("hristmas Eve")
elif d == 23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")


Fixed submission:
d = int(input())
 
if d == 25:
    print("Christmas")
elif d == 24:
    print("Christmas Eve")
elif d == 23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")
Buggy python submission (verdict: Runtime Error):
a,b,x = map(int,input().split())

if a >= x and a+b <=x:
    print("YES")
else:
    print("NO")

Fixed submission:
s = str(input())
if "a" in s and "b" in s and "c" in s:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
x = [int(input()) for i in range(4)]
print(min(x[0],x[1]) + min(x[2],x[3]))

Fixed submission:
a,b,c = map(int,input().split())
if a + b >= c:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [2,1]

if n == 1:
    print(1)

else:
    for i in range(2,n+1):
        l.append(int(l[i-1] +l[i-2]))
	print(l[n])


Fixed submission:
n = int(input())
l = [2,1]

if n == 1:
    print(1)

else:
    for i in range(2,n+1):
        l.append(int(l[i-1] +l[i-2]))
    print(l[n])

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [2,1]

if n == 1:
    print(1)

else:
    for i in range(2,n+1):
        l.append(int(l[i-1] +l[i-2]))
	print(l[n])


Fixed submission:
n = int(input())
l = [2,1]

if n == 1:
    print(1)

else:
    for i in range(2,n+1):
        l.append(int(l[i-1] +l[i-2]))
    print(l[n])
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
if abs(n-m) != 0 and abs(n-m) != 1 :
    print(0)
else:
    x = 1
    for i in range(1,min(n,m)+1):
        x = x * i

    if abs(n-m) == 0:
        print((2 * x * x)%(10**9+7))
    else:
        print((x * x * max(n,m))%(10**9+7))

Fixed submission:
import math
n,m = map(int,input().split())
if abs(n-m) != 0 and abs(n-m) != 1 :
    print(0)
else:
    x = math.factorial(min(m,n))

    if abs(n-m) == 0:
        print((2 * x * x)%(10**9+7))
    else:
        print((x * x * max(n,m))%(10**9+7))
Buggy python submission (verdict: Runtime Error):
s = str(input())

a = 0
z = 0

for i in range(len(s)):
    if s[i] = "A":
        a = min(a,i)

    elif s[i]  = "Z":
        z = max(z,i)

print(z - a + 1)

Fixed submission:
s = str(input())

a = 199999
z = 0

for i in range(len(s)):
    if s[i] == "A":
        a = min(a,i)

    elif s[i]  == "Z":
        z = max(z,i)

print(z - a + 1)
Buggy python submission (verdict: Runtime Error):
Coodinate, K, Distance = map(int, input().split())

dp = [0]*(K+1)
dp[0] = Coodinate
#dp[1] = min( abs(dp[0]+Coodinate), abs(dp[0]-coodinate) )
count = 0
for i in range(1,K+1):
    dp[i] = min( abs(dp[i-1]+Distance), abs(dp[i-1]-Distance) )
    #if dp.count(dp[i]) == 2:
    #    break
    #else:
    #    count += 1
#print(count)
#print(dp)
print(dp[K])


Fixed submission:
first_place, K, Distance = map(int, input().split())
first_place = abs(first_place)
test = first_place
if first_place - Distance*K > 0:
    print(first_place -Distance*K)
else:
    for i in range(1,K+1):
        test -= Distance
        if test <= 0:
            a = i
            #print(a)
            break
    if (K-a)%2 == 0 or K-a == 0:
        print(abs(first_place - Distance*a))
    else:
        print(abs(first_place - Distance*(a-1)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)
for i in range(M):
    a = A.index(max(A))
    A[a] = int(A[a]/2)

print(sum(A))

Fixed submission:
import sys
import heapq
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = (-1)*A[i]

heapq.heapify(A)

for i in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, int(a/2))

print(abs(sum(A)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in range(M):
    a = A.index(max(A))
    A[a] = int(A[a]/2)

print(sum(A))


Fixed submission:
import sys
import heapq
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = (-1)*A[i]

heapq.heapify(A)

for i in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, int(a/2))

print(abs(sum(A)))
Buggy python submission (verdict: Runtime Error):
import sys
input =sys.stdin.readline 
number, weight = input().rstrip().split()
number = int(number)
weight = int(weight)

items = (tuple(map(int,input().rstrip().split())) for _ in range(number))
dp = [[0]*(weight+1) for _ in range(number+1)]

for i in range(number):
    for j in range(weight+1):
        if j < items[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-items[i][0]] + items[i][1])

print(dp[number][weight])

Fixed submission:
import sys
 
input = sys.stdin.readline
 
 
def main():
    N, W = map(int, input().split())
    wv = [None] * N
    for i in range(N):
        wv[i] = tuple(map(int, input().split()))
 
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i, (w, v) in enumerate(wv, start=1):
        dp_i = dp[i]
        dp_im = dp[i - 1]
        for j in range(1, W + 1):
            if j < w:
                dp_i[j] = dp_im[j]
            else:
                a = dp_im[j - w] + v
                b = dp_im[j]
                if a > b:
                    dp_i[j] = a
                else:
                    dp_i[j] = b
 
    ans = dp[-1][-1]
    print(ans)
 
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input =sys.stdin.readline 
number, weight = input().rstrip().split()
number = int(number)
weight = int(weight)

items = [list(map(int,input().rstrip().split())) for _ in range(number)]
#print(items)
dp = [[0]*(weight+1) for _ in range(number+1)]

for i in  range(number):
    for j in range(weight+1):
        if j < items[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-items[i][0]] + items[i][1])

print(dp[number][weight])


Fixed submission:
import sys
 
input = sys.stdin.readline
 
 
def main():
    N, W = map(int, input().split())
    wv = [None] * N
    for i in range(N):
        wv[i] = tuple(map(int, input().split()))
 
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i, (w, v) in enumerate(wv, start=1):
        dp_i = dp[i]
        dp_im = dp[i - 1]
        for j in range(1, W + 1):
            if j < w:
                dp_i[j] = dp_im[j]
            else:
                a = dp_im[j - w] + v
                b = dp_im[j]
                if a > b:
                    dp_i[j] = a
                else:
                    dp_i[j] = b
 
    ans = dp[-1][-1]
    print(ans)
 
 
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


ans = 1
for i in range(2,int(math.sqrt(g))):
    while g%i == 0:
        g=g//i
        isdevided = True
    if isdevided:
        ans += 1
        isdevided = False
    if g == 1:
        break

print(ans)

Fixed submission:
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


arr = []
temp = g
for i in range(2, int(-(-g**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])

print(len(arr)+1)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


ans = 1
for i in range(2,g):
    while g%i == 0:
        g=g//i
        isdevided = True
    if isdevided:
        ans += 1
        isdevided = False

print(ans)


Fixed submission:
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


arr = []
temp = g
for i in range(2, int(-(-g**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])

print(len(arr)+1)

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

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

g = math.gcd(a,b)


ans = 1
for i in range(2,g):
    while g%i == 0:
        g=g//i
        isdevided = True
    if isdevided:
        ans += 1
        isdevided = False

print(ans)


Fixed submission:
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


arr = []
temp = g
for i in range(2, int(-(-g**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])

print(len(arr)+1)

Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())

counter = 0
primes = [2, 3]

for n in range(5, min(a,b), 2):
    isprime = True
    for i in range(1, len(primes)):
        counter += 1
        if primes[i] ** 2 > n:
            break
        counter += 1
        if n % primes[i] == 0:
            isprime = False
            break
    if isprime:
        primes.append(n)

ans = 1
for i in primes:
    if a%i == 0 and b%i == 0:
        ans += 1

print(ans)

Fixed submission:
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


arr = []
temp = g
for i in range(2, int(-(-g**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])

print(len(arr)+1)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if (a-b)%2 == 1:
  print("IMPOSSIBLE")
  
else:
  print((a+b)/2)

Fixed submission:
a,b = (int(x) for x in input().split())


if (a-b)%2 == 1:
  print("IMPOSSIBLE")

else:
  print(int((a+b)/2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))

a=0
result=0

for i in range(n-1):
  if A[i] > A[i+1]:
    a = A[i] - A[i+1]
    result += a
    
print(result)

Fixed submission:
n = int(input())

SUM = sum(list(map(int, str(n))))

if SUM % 9 == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans = ans*A[i]
if ans > 10**18:
    print(-1)
else:
    print(int(ans))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1
 
if p > U:
    print(-1)
else:
    print(p)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans = ans*A[i]
if ans > 10**18:
    print(-1)
else:
    print(int(ans[N-1]))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1
 
if p > U:
    print(-1)
else:
    print(p)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans = ans*A[i]
if ans > 10**18:
    print(-1)
else:
    print(int(ans[N-1]))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1
 
if p > U:
    print(-1)
else:
    print(p)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
import numpy as np
B = np.array(A,dtype='object')
ans = np.cumprod(B)
if int(ans[N-1]) > 10**18:
    print(-1)
else:
    print(int(ans[N-1]))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1
 
if p > U:
    print(-1)
else:
    print(p)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
import numpy as np
B = np.array(A,dtype='float64')
ans = np.cumprod(B)
if ans[N-1] > 10**18:
    print(-1)
else:
    print(int(ans[N-1]))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1
 
if p > U:
    print(-1)
else:
    print(p)
Buggy python submission (verdict: Runtime Error):
n = int(input())
sum = 0
for i in range(n):
    if i%5!=0 and i%3=0:
        sum = sum + 1
print(sum)

Fixed submission:
n = int(input())
sum = 0
for i in range(1,n+1):
    if i%5!=0 and i%3!=0:
        sum = sum + i
print(sum)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))

sum = 0
for i in range(a):
    sum = sum + a[i]
sum_divided = sum/(4*m)
cnt = 0
for i in range(a):
    if a[i] >= sum_divided:
        cnt = cnt + 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))

sum = 0
for i in range(n):
    sum = sum + a[i]
sum_divided = sum/(4*m)
cnt = 0
for i in range(n):
    if a[i] >= sum_divided:
        cnt = cnt + 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))

sum = 0
for i in range(a):
    sum = sum + a[i]
sum_divided = sum/(4*m)
cnt = 0
for i in range(a):
    if a[i] >= sum_divided:
        cnt = cnt + 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))

sum = 0
for i in range(n):
    sum = sum + a[i]
sum_divided = sum/(4*m)
cnt = 0
for i in range(n):
    if a[i] >= sum_divided:
        cnt = cnt + 1
if cnt >= m:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N,a,b = map(int,input().split())
MOD = 10**9+7
def combination(n,r):
    if(r<0) or (n<r):
        return 0
    r = min(r,n-r)
    return fact[n]*factinv[r]*factinv[n-r]%MOD
fact = [1,1]
factinv = [1,1]
inv = [0,1]
for i in range(2,N+1):
    fact.append((fact[-1]*i)%MOD)
    inv.append((-inv[MOD%i]*(MOD//i)%MOD))
    factinv.append((factinv[-1]*inv[-1]%MOD))
result = pow(2,N,MOD) - 1
nashi = combination(N,a) + combination(N,b)
if result - nashi < 0:
    print(result - nashi + MOD)
else:
    print(result - nashi)

Fixed submission:
from functools import reduce
N,a,b = map(int,input().split())
MOD = 10**9+7
def f(r):
    nPr = reduce(lambda x,y: x * y % MOD,range(N,N-r,-1))
    r_fact = reduce(lambda x,y: x * y % MOD,range(1,r+1))
    return nPr * pow(r_fact,MOD-2,MOD) % MOD
result = pow(2,N,MOD) - f(a) - f(b) - 1
result %= MOD
print(result)
Buggy python submission (verdict: Runtime Error):
h,a = map(int,input().split())
print(int(h/a+1)


Fixed submission:
h,a = map(int,input().split())
if h%a == 0:
    result = int(h/a)
else:
    result = int(h/a) + 1
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [100010]*N
dps = set()
dp[0] = 0
if K>N:
    print(h[N-1]-h[0])
    exit()
for i in range(1,N):
    for j in range(1,K+1):
        dps.add(dp[i-j]+abs(h[i]-h[i-j]))
    dp[i] = min(dps)
    dps.clear()
print(dp[N-1])

Fixed submission:
import numpy as np
N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp = np.zeros(N, dtype=int)
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = np.min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]
import numpy as np
dp = np.full(10**5,10**18,dtype=np.int64)
dp[0]=0
for w,v in wv:
    np.minimum(dp[v:],dp[:-v]+w,out=dp[v:])
print(np.where(dp<=W).max())

Fixed submission:
N,W = map(int,input().split())
import numpy as np
dp = np.full(N*1000 +1,W+1,dtype=np.int64)
dp[0]=0
for _ in range(N):
    w,v = map(int,input().split())
    dp[v:] = np.minimum(dp[:-v] + w, dp[v:])
print(np.max(np.where(dp <= W)))

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]
import numpy as np
dp = np.zeros(W+1)
for w,v in wv:
    np.maximum(dp[w:],dp[:-w]+v,out=dp[w:])
print(int(dp.max()))

Fixed submission:
N,W = map(int,input().split())
import numpy as np
dp = np.full(N*1000 +1,W+1,dtype=np.int64)
dp[0]=0
for _ in range(N):
    w,v = map(int,input().split())
    dp[v:] = np.minimum(dp[:-v] + w, dp[v:])
print(np.max(np.where(dp <= W)))

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]
import numpy as np
dp = np.zeros(W+1,dtype=np.int64)
for w,v in wv:
    np.maximum(dp[w:],dp[:-w]+v,out=dp[w:])
print(dp.max())

Fixed submission:
N,W = map(int,input().split())
import numpy as np
dp = np.full(N*1000 +1,W+1,dtype=np.int64)
dp[0]=0
for _ in range(N):
    w,v = map(int,input().split())
    dp[v:] = np.minimum(dp[:-v] + w, dp[v:])
print(np.max(np.where(dp <= W)))
Buggy python submission (verdict: Runtime Error):
X = int(input())
A = int(input())
B = int(input())
C = int(input())
cnt = 0
for i in range(A):
    for j in range(B):
        for k in range(C):
            if (i+j+h) == X:
                cnt = cnt + 1
print(cnt)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i+100*j+50*k) == X:
                cnt = cnt + 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
X = int(input())
A = int(input())
B = int(input())
C = int(input())
cnt = 0
for(i in range(A)):
    for(j in range(B)):
        for(k in range(C)):
            if(i+j+h == X):
                cnt = cnt + 1
print(cnt)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i+100*j+50*k) == X:
                cnt = cnt + 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N, Y = map(int,input().split())
y = Y/1000
ans_a = -1
ans_b = -1
for i in range(1,2001):
    for j in range(1,2001):
        if i*9 + j*4 + N == y:
            ans_a = i
            ans_b = j
if ans_a == -1:
    N = -1
print(str(ans_a)+' '+str(ans_b)+' '+str(N-ans_a-ans_b)

Fixed submission:
N, Y = map(int,input().split())
y = Y/1000
ans_a = -1
ans_b = -1
for i in range(N+1):
    for j in range(N-i+1):
        if i*9 + j*4 + N == y:
            ans_a = i
            ans_b = j
if ans_a == -1:
    N = -3
print(str(ans_a)+' '+str(ans_b)+' '+str(N-ans_a-ans_b))
Buggy python submission (verdict: Time Limit Exceeded):
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def isMultiple(s, m):
    tmp = 0
    for i in range(len(s)):
        tmp = (tmp * 10 + int(s[i])) % m
        if tmp == 0:
            return i
    return -1


k = int(readline())
acc = "7" * 10000000
if k % 2 == 0:
    ans = -1
else:

    ans = isMultiple(acc, k) + 1

print(ans)

Fixed submission:
#! /usr/bin/env python3

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def isMultiple(s, m):
    tmp = 0
    for i in range(len(s)):
        tmp = (tmp * 10 + int(s[i])) % m
        if tmp == 0:
            return i
    return -1


k = int(readline())
acc = "7" * 50000000
if k % 2 == 0:
    ans = -1
else:

    ans = isMultiple(acc, k)
    if ans != -1:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
C = readline().decode().rstrip()

w_idx = []
r_idx = []
for i, c in enumerate(C):
    if c == 'W':
        w_idx.append(i)
    else:
        r_idx.append(i)

m = r_idx[len(r_idx) // 2 - 1]

if (len(w_idx) == 0) | (len(r_idx) == 0):
    print(0)
    sys.exit()

cnt = 0
for w in w_idx:
    if w < m:
        cnt += 1

print(cnt)

Fixed submission:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
C = readline().decode().rstrip()

l, r = 0, N - 1
cnt = 0

while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        l += 1
        r -= 1
        cnt += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
C = readline().decode().rstrip()

w_idx = []
r_idx = []
for i, c in enumerate(C):
    if c == 'W':
        w_idx.append(i)
    else:
        r_idx.append(i)

if (len(w_idx) == 0) | (len(r_idx) == 0):
    print(0)
    sys.exit()

cnt = 0

while w_idx[0] < r_idx[-1]:

    w_acc = w_idx.pop(0)
    r_acc = r_idx.pop(-1)
    w_idx.append(r_acc)
    r_idx.append(w_acc)
    w_idx.sort()
    r_idx.sort()
    cnt += 1

print(cnt)

Fixed submission:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
C = readline().decode().rstrip()

l, r = 0, N - 1
cnt = 0

while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        l += 1
        r -= 1
        cnt += 1

print(cnt)