Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(str(input()))

R = []
G = []
B = []

for i in range(n):
    if s[i] == 'R':
        R.append(i)
    elif s[i] == 'G':
        G.append(i)
    elif s[i] == 'B':
        B.append(i)
c = 0
for r in R:
    for g in G:
        for b in B:
            [i,j,k] = sorted([r,g,b])
            if j-i != k-j:
                c = c+1
print(c)

Fixed submission:
n = int(input())
s = list(str(input()))


c = 0
for i in range(n):
    for j in range(i+1, n):
        k = 2*j-i
        if k<n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            c = c+1
            
        

R = 0
G = 0
B = 0

for i in range(n):
    if s[i] == 'R':
        R = R+1
    elif s[i] == 'G':
        G = G+1
    elif s[i] == 'B':
        B = B+1

print(R*G*B-c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(str(input()))

R = []
G = []
B = []

for i in range(n):
    if s[i] == 'R':
        R.append(i)
    elif s[i] == 'G':
        G.append(i)
    elif s[i] == 'B':
        B.append(i)
c = 0
for r in R:
    for g in G:
        for b in B:
            [i,j,k] = sorted([r,g,b])
            if len(set([i,j,k])) == 3 and j-i != k-j:
                c = c+1
print(c)

Fixed submission:
n = int(input())
s = list(str(input()))


c = 0
for i in range(n):
    for j in range(i+1, n):
        k = 2*j-i
        if k<n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            c = c+1
            
        

R = 0
G = 0
B = 0

for i in range(n):
    if s[i] == 'R':
        R = R+1
    elif s[i] == 'G':
        G = G+1
    elif s[i] == 'B':
        B = B+1

print(R*G*B-c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(str(input()))

R = []
G = []
B = []

for i in range(n):
    if s[i] == 'R':
        R.append(i)
    elif s[i] == 'G':
        G.append(i)
    elif s[i] == 'B':
        B.append(i)
c = 0
for r in R:
    for g in G:
        for b in B:
            [i,j,k] = sorted([r,g,b])
            if len(set([i,j,k])) == 3 and j-i != k-j:
                c = c+1
print(c)

Fixed submission:
n = int(input())
s = list(str(input()))


c = 0
for i in range(n):
    for j in range(i+1, n):
        k = 2*j-i
        if k<n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            c = c+1
            
        

R = 0
G = 0
B = 0

for i in range(n):
    if s[i] == 'R':
        R = R+1
    elif s[i] == 'G':
        G = G+1
    elif s[i] == 'B':
        B = B+1

print(R*G*B-c)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())


def distance(i,j):
    d1 = abs(i-j)
    d2 = abs(i-x)+1+abs(j-y)
    d3 = abs(i-y)+1+abs(j-x)    
    d = min(d1,d2,d3)
    return d

d = [0]*(n-1)
for i in range(1, n+1):
    for j in range(i+1,n+1):
        d[distance(i,j)-1] = d[distance(i,j)-1] + 1

for i in d:
    print(i)

Fixed submission:

n, x, y = map(int, input().split())

d = [0]*(n-1)
for i in range(1, n+1):
    for j in range(i+1,n+1):
        c = min(j-i, abs(i-x)+1+abs(j-y))
        d[c-1] = d[c-1] + 1

for i in d:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):


n, x, y = map(int, input().split())


def distance(i,j):
    d1 = abs(i-j)
    d2 = abs(i-x)+1+abs(j-y)
    d3 = abs(i-y)+1+abs(j-x)    
    d = min(d1,d2,d3)
    return d

c = []
for i in range(1, n+1):
    for j in range(i+1,n+1):
        c.append(distance(i,j))

d = [0]*(n-1)
for i in c:
    d[i-1] = d[i-1] + 1
for i in d:
    print(i)

Fixed submission:

n, x, y = map(int, input().split())

d = [0]*(n-1)
for i in range(1, n+1):
    for j in range(i+1,n+1):
        c = min(j-i, abs(i-x)+1+abs(j-y))
        d[c-1] = d[c-1] + 1

for i in d:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())


def distance(i,j):
    d1 = abs(i-j)
    d2 = abs(i-x)+1+abs(j-y)
    d3 = abs(i-y)+1+abs(j-x)    
    d = min(d1,d2,d3)
    return d

c = []
for i in range(1, n+1):
    for j in range(i+1,n+1):
        c.append(distance(i,j))

for i in range(1,n):
    d = 0
    for j in c:
        if j == i:
            d = d + 1
    print(d)

Fixed submission:

n, x, y = map(int, input().split())

d = [0]*(n-1)
for i in range(1, n+1):
    for j in range(i+1,n+1):
        c = min(j-i, abs(i-x)+1+abs(j-y))
        d[c-1] = d[c-1] + 1

for i in d:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())

inf = 100000000
G = [[inf for i in range(n)] for j in range(n)]

for i in range(n-1):
    G[i][i] = 0
    G[i][i+1] = 1
    G[i+1][i] = 1
    G[x-1][y-1] = 1
    G[y-1][x-1] = 1
    
v = [False]*n #visited
d = [0]*n #shortest distance

def getsmallindex():
    index = 0
    mn = inf
    for i in range(n):
        if d[i] < mn and v[i] == False:
            mn = d[i]
            index = i
    return index

def dijkstra(start):
    for i in range(n):
        d[i] = G[start][i]
    v[start] = True
    for i in range(n-1):
        current = getsmallindex()
        v[current] = True
        for j in range(n):
            if v[j] == False:
                if d[current] + G[current][j] < d[j]:
                    d[j] = d[current] + G[current][j]

s = [0]*n 
for i in range(n):
    v = [False]*n #visited
    d = [0]*n #shortest distance
    dijkstra(i)
    for k in range(1,n):
        for j in range(i,n):
            if d[j] == k:
                s[k] = s[k] + 1
    
for i in range(1,n):
    print(s[i])

        

Fixed submission:

n, x, y = map(int, input().split())

d = [0]*(n-1)
for i in range(1, n+1):
    for j in range(i+1,n+1):
        c = min(j-i, abs(i-x)+1+abs(j-y))
        d[c-1] = d[c-1] + 1

for i in d:
    print(i)
Buggy python submission (verdict: Runtime Error):

n = int(input())
a = list(map(int, input().split()))

c = [0]*n

for i in range(n):
    c[a[i]] = c[a[i]] + 1
    
total = 0
for x in c:
    total = total + x*(x-1)//2

for i in range(n):
    print(total - c[a[i]] + 1)

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

c = [0]*n

for i in range(n):
    c[a[i]-1] = c[a[i]-1] + 1
    
total = 0
for x in c:
    total = total + x*(x-1)//2

for i in range(n):
    print(total - c[a[i]-1] + 1)

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

d = [[0]*n for _ in range(n)]

for i in range(n):
    b = list(a)
    b[i] = 0
    for j in range(n):        
        d[i][b[j]] = d[i][b[j]]+1
    
for i in range(n):
    c = 0
    for j in range(n):
        c = c + d[i][j]*(d[i][j]-1)//2
    print(c)

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

c = [0]*n

for i in range(n):
    c[a[i]-1] = c[a[i]-1] + 1
    
total = 0
for x in c:
    total = total + x*(x-1)//2

for i in range(n):
    print(total - c[a[i]-1] + 1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = list(map(int, input().split()))

e = [(i+1)/2 for i in p]

sume = [0 for _ in range(n)]
for i in range(n):
    if i == 0:
        sume[i] = e[i]
    else:
        sume[i] = sume[i-1]+e[i]

ans = []
for i in range(n-k):
    ans.append(sume[i+k]-sume[i])    
    
print(max(ans))
    

Fixed submission:

n, k = map(int, input().split())
p = list(map(int, input().split()))

e = [(i+1)/2 for i in p]

sume = [0 for _ in range(n)]
for i in range(n):
    if i == 0:
        sume[i] = e[i]
    else:
        sume[i] = sume[i-1]+e[i]

ans = []

if n == k:
    ans.append(sume[-1])
else:
    for i in range(n-k):
        ans.append(sume[i+k]-sume[i])

print("%.12f"%max(ans))
Buggy python submission (verdict: Runtime Error):


n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

# t_sub = #sub string
ban = []
st = []
score1 = 0
score2 = 0

for i in t:
    if i == 'r' :
        st.append('p')
    elif i == 's' :
        st.append('r')
    else:
        st.append('s')
            
def score(l, m):
    c = 0       
    for i in range(len(l)):
        if l[i] != m[i]:
            if l[i] == 'r' :
                c += r
            elif l[i] == 's' :
                c += s
            elif l[i] == 'p' :
                c += p
    return c
           
                
st1 = st
for i in range(k):
    st1_sub = st1[i::k]
    st2_sub = st2[i::k]
    t_sub = t[i::k]
    
    for j in range(len(st1_sub)-1):
        if st1_sub[j+1] == st1_sub[j]:
            st1_sub[j+1] = t_sub[j+1]
            st2_sub[j] = t_sub[j]
    if score(st1_sub, t_sub) > score(st2_sub, t_sub):
        st[i::k] = st1_sub
    else:
        st[i::k] = st2_sub

print(score(st,t))


Fixed submission:


n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())


st = [0 for _ in range(n)]
for i in range(n):
    if i < k: 
        if t[i] == 'r' :
            st[i] = 'p'
        elif t[i] == 's' :
            st[i] = 'r'
        elif t[i] == 'p':
            st[i] = 's'
    else:
        if t[i] == 'r' and st[i-k] != 'p':
            st[i] = 'p'
        elif t[i] == 's' and st[i-k] != 'r':
            st[i] = 'r'
        elif t[i] == 'p'and st[i-k] != 's':
            st[i] = 's'
        
score = 0
for i in st:
    if i == 'r' :
        score += r
    elif i == 's' :
        score += s
    elif i == 'p' :
        score += p

print(score)
Buggy python submission (verdict: Runtime Error):
import itertools

import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    H, W, K = map(int, input().split())
    C = []
    for _ in range(H):
        C.append(list(map(str, input().split())))
    _run(H, W, K, C)


if __name__ == "__main__":
    _main()


Fixed submission:
import itertools

import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    H, W, K = map(int, input().split())
    C = [str(input()) for _ in range(H)]
    _run(H, W, K, C)


if __name__ == "__main__":
    _main()

Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    H, W, K = map(int, input().split())
    C = [list(map(int, input().split())) for _ in range(H)]
    _run(H, W, K, C)


if __name__ == "__main__":
    _main()


Fixed submission:
import itertools

import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    H, W, K = map(int, input().split())
    C = [str(input()) for _ in range(H)]
    _run(H, W, K, C)


if __name__ == "__main__":
    _main()
Buggy python submission (verdict: Time Limit Exceeded):
def _print_sum(cache):
    sum_value = 0
    for v, indices in cache.items():
        sum_value += v * len(indices)
    print(sum_value)


def _main(N, A_list, Q, BC_list):
    cache = {}
    values = set()
    for i, a in enumerate(A_list):
        cache.setdefault(a, []).append(i)
        values.add(a)

    for b, c in BC_list:
        indices = cache.get(b, [])
        cache[b] = []
        cache.setdefault(c, []).extend(indices)
        _print_sum(cache)


def _entry():
    N = int(input())
    A_list = list(map(int, input().split()))
    Q = int(input())
    BC_list = []
    for i in range(Q):
        B, C = map(int, input().split())
        BC_list.append((B, C))
    _main(N, A_list, Q, BC_list)


if __name__ == "__main__":
    _entry()


Fixed submission:
def _calc_sum(cache):
    sum_value = 0
    for v, indices in cache.items():
        sum_value += v * len(indices)
    return sum_value


def _main(N, A_list, Q, BC_list):
    cache = {}
    for i, a in enumerate(A_list):
        cache.setdefault(a, []).append(i)

    sum_value = _calc_sum(cache)

    for b, c in BC_list:
        indices = cache.get(b, [])
        cache[b] = []
        sum_value -= b * len(indices)
        cache.setdefault(c, []).extend(indices)
        sum_value += c * len(indices)
        print(sum_value)


def _entry():
    N = int(input())
    A_list = list(map(int, input().split()))
    Q = int(input())
    BC_list = []
    for i in range(Q):
        B, C = map(int, input().split())
        BC_list.append((B, C))
    _main(N, A_list, Q, BC_list)


if __name__ == "__main__":
    _entry()
Buggy python submission (verdict: Runtime Error):
A, B = [x for x in input().split()]

A = int(A)
B = int(round(float(B) * 100))

print(A*B // 100

Fixed submission:
inp = input().split()

A = int(inp[0])
_B = float(inp[1])
B = round(_B * 100)

res = int(A*B // 100)

print(str(res))
Buggy python submission (verdict: Runtime Error):

d = []
A = []
for i in range(K):
    _d = int(input())
    d.append(_d)
    _a = [int(x) for x in input().split()]
    A.append(_a)

res = []
for i in range(1, N+1):
    res.append(i)

for a in A:
    for _a in a:
        if _a in res:
            res.remove(_a)
print(len(res))


Fixed submission:
N, K = [int(x) for x in input().split()]

d = []
A = []
for i in range(K):
    _d = int(input())
    d.append(_d)
    _a = [int(x) for x in input().split()]
    A.append(_a)

res = []
for i in range(1, N+1):
    res.append(i)

for a in A:
    for _a in a:
        if _a in res:
            res.remove(_a)
print(len(res))
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

num = X // 100

res = 0

for a in range(num+1):
    for b in range(num-a+1):
        for c in range(num-(a+b)+1):
            for d in range(num-(a+b+c)+1):
                for e in range(num-(a+b+c+d)+1):
                    for f in range(num-(a+b+c+d+e)+1):
                        if a*100 + b*101 + c*102 + d*103 + e*104 + f*105 == X:
                            res = 1
                            break

print(res)


Fixed submission:
X = int(input())

if X >= 2000:
    print(1)

else:
    num = X // 100
    res = 0

    for a in range(num+1):
        for b in range(num-a+1):
            for c in range(num-(a+b)+1):
                for d in range(num-(a+b+c)+1):
                    for e in range(num-(a+b+c+d)+1):
                        for f in range(num-(a+b+c+d+e)+1):
                            if a*100 + b*101 + c*102 + d*103 + e*104 + f*105 == X:
                                res = 1
                                break

    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(x) for x in input().split()]

res = ""
for i in range(N):
    res += str(a.index(i+1)+1) + " "

print(res)


Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]

l = {}
for i in range(N):
    l[i] = a[i]

sorted_l = sorted(l.items(), key=lambda x: x[1])

res = ""
for key, value in sorted_l:
    res += str(key + 1) + " "


print(res)
Buggy python submission (verdict: Runtime Error):
w = input()
weather = ["Sunny", "Cloudy", "Rainy"]

index = weather.index(w)
index += 1
if index == 2:
    index = 0

print(weather[index])


Fixed submission:
w = input()
weather = ["Sunny", "Cloudy", "Rainy"]

index = weather.index(w)
index += 1
if index == 3:
    index = 0

print(weather[index])
Buggy python submission (verdict: Runtime Error):
N, K, Q = input().split()
N = int(N)
K = int(K)
Q = int(Q)

A = []
for i in range(Q):
    A.append(int(input()))

people = []
for i in range(N):
    people.append(K-Q)

for i in A:
    people[i+1] += 1

for i in people:
    if i <= 0:
        print("No")
    else:
        print("Yes")


Fixed submission:
N, K, Q = input().split()
N = int(N)
K = int(K)
Q = int(Q)

A = []
for i in range(Q):
    A.append(int(input()))

people = []
for i in range(N):
    people.append(K - Q)

for i in A:
    people[i-1] += 1

for i in people:
    if i <= 0:
        print("No")
    else:
        print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = input().split()
N = int(N)
K = int(K)
Q = int(Q)

A = []
for i in range(Q):
    A.append(int(input()))

people = []
for i in range(N):
    people.append(K)

for index in A:
    for i, p in enumerate(people):
        if i != index - 1:
            people[i] -= 1

for i in people:
    if i <= 0:
        print("No")
    else:
        print("Yes")


Fixed submission:
N, K, Q = input().split()
N = int(N)
K = int(K)
Q = int(Q)

A = []
for i in range(Q):
    A.append(int(input()))

people = []
for i in range(N):
    people.append(K - Q)

for i in A:
    people[i-1] += 1

for i in people:
    if i <= 0:
        print("No")
    else:
        print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, M = list(map(int, input().split()))
A = list(map(lambda x: -int(x), input().split()))

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

print(-sum(A))


Fixed submission:
import heapq

N, M = list(map(int, input().split()))
A = list(map(lambda x: -int(x), input().split()))

heapq.heapify(A)

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

print(-sum(A))

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

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

print(sum(A))


Fixed submission:
import heapq

N, M = list(map(int, input().split()))
A = list(map(lambda x: -int(x), input().split()))

heapq.heapify(A)

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

print(-sum(A))

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

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

print(sum(A))


Fixed submission:
import heapq

N, M = list(map(int, input().split()))
A = list(map(lambda x: -int(x), input().split()))

heapq.heapify(A)

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

print(-sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = input().split()
N = int(N)
M = int(M)
A = list(map(int, input().split()))


def discount(x, y):
    return int(x / (2 ** y))

A.sort()

for i in range(M):
    if i == 0:
        res = sum(A) - A[N-1] + discount(A[N-1], M)
    else:
        _res = sum(A)
        for j in range(i+1):
            _res -= A[N-1-j]
            _res += discount(A[N-1-j], M-1-j)
        res = min(res, _res)

print(res)


Fixed submission:
import heapq

N, M = list(map(int, input().split()))
A = list(map(lambda x: -int(x), input().split()))

heapq.heapify(A)

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

print(-sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

length = 0 

for i in range(N):
    l1 = i
    l2 = i + 1
    _word = S[l1:l2]
    _S = S[l2:]
    while _word in _S and l1 + len(_word) <= l2:
        l2 += 1
        _word = S[l1:l2]
        _S = S[l2:]
    length = max(len(_word)-1, length)

print(length)


Fixed submission:
N = int(input())
S = input()

length = 0 

for i in range(N):
    l1 = i
    l2 = i + length
    _word = S[l1:l2]
    _S = S[l2:]
    while _word in _S and l1 + len(_word) <= l2:
        l2 += 1
        _word = S[l1:l2]
        _S = S[l2:]
    length = max(len(_word)-1, length)

print(length)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = []
for i in range(N):
    A.append(int(input()))

list_max = max(A)

import copy

for i in range(N):
    if A[i] != list_max:
        print(list_max)
    else:
        _tmp = copy.copy(A)
        _tmp.pop(i)
        print(max(_tmp))

Fixed submission:
N = int(input())

A = []
for i in range(N):
    A.append(int(input()))

_A = sorted(A)

list_max = _A[N-1]
list_second_max = _A[N-2]

import copy

for i in range(N):
    if A[i] != list_max:
        print(list_max)
    else:
        print(list_second_max)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = []
for i in range(N):
    A.append(int(input()))

import copy

for i in range(N):
    _tmp = copy.copy(A)
    _tmp.pop(i)
    print(max(_tmp))

Fixed submission:
N = int(input())

A = []
for i in range(N):
    A.append(int(input()))

_A = sorted(A)

list_max = _A[N-1]
list_second_max = _A[N-2]

import copy

for i in range(N):
    if A[i] != list_max:
        print(list_max)
    else:
        print(list_second_max)
Buggy python submission (verdict: Runtime Error):
import numpy as np

def swip(a, b):
    tmp = c[a]
    c[a] = c[b]
    c[b] = tmp

def c_change(a):
    if c[a] == 'W':
        c[a] = 'R'
    else:
        c[a] = 'W'

n = int(input())
c = np.array(list(input()))

# done = 0
count = 0
i = 0

n_white = np.count_nonzero(c=='W')
n_red = np.count_nonzero(c=='R')

while True:
    i += 1
    if n_white:
        min_white = np.where(c == 'W')[0].tolist()[0]
        max_red = np.where(c == 'R')[0].tolist()[-1]
        if min_white < max_red:
            swip(min_white, max_red)
            count += 1
        else:
            break
    else:       # no white stones
        break

print(count)

Fixed submission:
import numpy as np

n = int(input())
c = np.array(list(input()))

count = 0

n_white = np.count_nonzero(c=='W')
n_red = np.count_nonzero(c=='R')

if n_red:
    if n_white:
        p_white = np.where(c == 'W')[0].tolist()
        p_red = np.where(c == 'R')[0].tolist()
        num = min(len(p_white), len(p_red))
        i = 0
        while (i < num):
            if p_white[i] < p_red[-1-i]:
                count += 1
            i += 1

print(count)