Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
c = [char for char in c]

r_idx, w_idx = [], []
for j in range(n):
    if c[j] == "R":
        r_idx.append(j)
    elif c[j] == "W":
        w_idx.append(j)

ans = 0
for i in range(len(c) - len(w_idx)):
    if i in w_idx:
        ans += 1

print(ans)

Fixed submission:
n = int(input())
c = input()
c = [char for char in c]

ans = 0
for i in range(c.count("R")):
    if c[i] == "W":
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
c = [char for char in c]

def op1(l, id1, id2):
    temp = l[id1]
    l[id1] = l[id2]
    l[id2] = temp
    return l

r_idx, w_idx = [], []
for j in range(n):
    if c[j] == "R":
        r_idx.append(j)
    elif c[j] == "W":
        w_idx.append(j)

ans = 0
for i in range(min(len(r_idx), len(w_idx))):
    c = op1(c, w_idx[i], r_idx[-i - 1])
    ans += 1
    if not "W" in "".join(c).rstrip("W"):
        break
if "W" in "".join(c).rstrip("W"):
    ans += "".join(c).rstrip("W").count("W")
print(ans)

Fixed submission:
n = int(input())
c = input()
c = [char for char in c]

ans = 0
for i in range(c.count("R")):
    if c[i] == "W":
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
c = input()
c = [char for char in c]

def op1(l, id1, id2):
    temp = l[id1]
    l[id1] = l[id2]
    l[id2] = temp
    return l

r_idx, w_idx = [], []
for j in range(n):
    if c[j] == "R":
        r_idx.append(j)
    elif c[j] == "W":
        w_idx.append(j)

ans = 0
for i in range(min(len(r_idx), len(w_idx))): # i is number of op1
    c_i = c[:]
    c_i = op1(c_i, w_idx[j], r_idx[-j - 1])
    ans[i] += 1
if "W" in "".join(c_i).rstrip("W"):
    ans[i] += "".join(c_i).rstrip("W").count("W")
print(min(ans))

Fixed submission:
n = int(input())
c = input()
c = [char for char in c]

ans = 0
for i in range(c.count("R")):
    if c[i] == "W":
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
c = input()
c = [char for char in c]

def op1(l, id1, id2):
    temp = l[id1]
    l[id1] = l[id2]
    l[id2] = temp
    return l

r_idx, w_idx = [], []
for j in range(n):
    if c[j] == "R":
        r_idx.append(j)
    elif c[j] == "W":
        w_idx.append(j)

ans = 0
else:
    for i in range(min(len(r_idx), len(w_idx))): # i is number of op1
        c_i = c[:]
        c_i = op1(c_i, w_idx[j], r_idx[-j - 1])
        ans[i] += 1
    if "W" in "".join(c_i).rstrip("W"):
        ans[i] += "".join(c_i).rstrip("W").count("W")
    print(min(ans))

Fixed submission:
n = int(input())
c = input()
c = [char for char in c]

ans = 0
for i in range(c.count("R")):
    if c[i] == "W":
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
c = [char for char in c]

def op1(l, id1, id2):
    temp = l[id1]
    l[id1] = l[id2]
    l[id2] = temp
    return l

r_idx, w_idx = [], []
for j in range(len(c)):
    if c[j] == "R":
        r_idx.append(j)
    elif c[j] == "W":
        w_idx.append(j)

ans = [0 for _ in range(min(len(r_idx), len(w_idx)))]
if len(ans) == 0:
    print(0)
else:
    for i in range(min(len(r_idx), len(w_idx))): # i is number of op1
        c_i = c[:]
        for j in range(i):
            c_i = op1(c_i, w_idx[j], r_idx[-j - 1])
            ans[i] += 1
        if "W" in "".join(c_i).rstrip("W"):
            ans[i] += "".join(c_i).rstrip("W").count("W")
    print(min(ans))

Fixed submission:
n = int(input())
c = input()
c = [char for char in c]

ans = 0
for i in range(c.count("R")):
    if c[i] == "W":
        ans += 1

print(ans)