TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
import sys
import math

n = int(sys.stdin.readline().rstrip("\n"))
c = list(sys.stdin.readline().rstrip("\n"))
ans = 0
left, right = 0, len(arr) - 1

while(left < right):
    while(c[left] == 'R'):
        left += 1
        if left >= n:
            break
    while(c[right] == 'W'):
        right -= 1
        if right < 0:
            break
    if (left < right):
        c[left], c[right] = c[right], c[left]
        ans += 1
    else:
        break

print(ans)

import sys
import math

n = int(sys.stdin.readline().rstrip("\n"))
c = list(sys.stdin.readline().rstrip("\n"))
ans = 0
left, right = 0, n-1

while(left < right):
    while(c[left] == 'R'):
        left += 1
        if left >= n:
            break
    while(c[right] == 'W'):
        right -= 1
        if right < 0:
            break
    if (left < right):
        c[left], c[right] = c[right], c[left]
        ans += 1
    else:
        break

print(ans)

Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
s = input()
w = s.count('W')
an1 = s[-w:].count('R')
an2 = s[:w].count('R')

print(min(an1, an2))

n = int(input())
s = input()
w = s.count('w')
print( s[-w:].count('R') if w != 0 else 0)

n = int(input())
s = input()
w = s.count('W')
if w == 0:
  print(0)
else:
  print(s[-w:].count('R'))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
cs = input()
r = cs.count("R")
print(cs[:r].count("R"))


ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
cs = input()
r = cs.count("R")
print(cs[r:].count("R"))


Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n=int(input())
word=input()
line=[]
for i in range(n):
    if(word[0]=='R'):
        line.append(1)
    else:
        line.append(0)
    word=word[1:]
x=0
y=n-1
ans=0
while(1):
    while(1):
        print(22222222)
        if(line[x]==0):
            break
        if(x>=y):
            break
        x+=1
    while(1):
        print(3333333333)
        if(line[y]==1):
            break
        if(x>=y):
            break
        y-=1
    if(x>=y):
        break
    tmp=line[x]
    line[x]=line[y]
    line[y]=tmp
    print(ans)
    ans=ans+1
print(ans)

n=int(input())
word=input()
line=[]
for i in range(n):
    if(word[0]=='R'):
        line.append(1)
    else:
        line.append(0)
    word=word[1:]
x=0
y=n-1
ans=0
while(1):
    while(1):
        if(line[x]==0):
            break
        if(x>=y):
            break
        x+=1
    while(1):
        if(line[y]==1):
            break
        if(x>=y):
            break
        y-=1
    if(x>=y):
        break
    tmp=line[x]
    line[x]=line[y]
    line[y]=tmp
    ans=ans+1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
import re

def checkFunction(c):
    print(c)
    c = re.sub('W+$','',c)
    if (not 'WR' in c):
        return 0
    if c.index('WR') + 2 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))

def checkFunction(c):
    count = 0

    while True:
        print(count, c)
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        while c[-1] == 'W':
            c = c[:-1]

        if c.index('R') == len(c) - 1:
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

N = int(input())
c= input()

print(checkFunction(c))


def checkFunction(c):
    # print(c)
    while True:
        if c[0] == 'R':
            c = c[1:]
        else:
            break
    while True:
        if c[-1] == 'W':
            c = c[:-1]
        else:
            break
    if (not 'WR' in c):
        return 0
    if c.index('R') + 1 != len(c):
        c2 = c.replace('WR', 'RR',1)[:-1]
        return checkFunction(c2) + 1
    return 1


N = int(input())
c= input()

print(checkFunction(c))



def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
C = input()
t = sum(c == 'R' for c in C)
print(sum(c == 'R' for c in C[:t]))

k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    s = i = 0
    while True:
        i += 1
        s = (s*10 + 7) % k
        if s % k == 0:
            print(i)
            break

n = int(input())
C = input()
print(C[:C.count('R')].count("W"))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
c = input()

w = [0]*(n+1)
r = [0]*(n+1)
for i in range(0,n):
  w[i+1] = w[i]
  r[n-i-1] = r[n-i]
  if c[i]=='W':
    w[i+1] += 1
  if c[n-i-1]=='R':
    r[n-i-1] += 1

print([w[i]+r[i]-min(w[i],r[i]) for i in range(0,n+1)])

n = int(input())
c = input()

w = [0]*(n+1)
r = [0]*(n+1)
for i in range(0,n):
  w[i+1] = w[i]
  r[n-i-1] = r[n-i]
  if c[i]=='W':
    w[i+1] += 1
  if c[n-i-1]=='R':
    r[n-i-1] += 1

print(min([w[i]+r[i]-min(w[i],r[i]) for i in range(0,n+1)]))


Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
k = list(input())
ws = 0
rs = 0
moves = 0
for i in range(0, n-1):
    if k[i] == "W":
        ws += 1
    else :
        rs += 1
if ws == 0 or rs == 0:
    print(0)
if rs < ws:
    for i in range(0, rs-1):
        if k[i] == "W":
            moves += 1
else:
    for i in range(n-1, ws):
        if k[i] == "R":
            moves += 1
print(moves)

n = int(input())
l = input()

rs = l.count("R")
print(l[:rs].count("W"))

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N = int(input())

C = input()

if N % 2 == 0:
  mid = N//2
else:
  mid = N//2+1

Wcount = C.count("W", 0, mid)
if C[mid-1] == "W":
  Wcount -= 1
print(Wcount)

N = int(input())

C = input()

if N % 2 == 0:
  mid = N//2
else:
  mid = N//2+1

Rcount = C.count("R")
rcount = C.count("R", 0, Rcount)
print(Rcount-rcount)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
c = input()

red = [i for i, x in enumerate(c) if x == 'R']
white = [i for i, x in enumerate(c) if x == 'W']

if len(white) == 0:
    print(0)
elif len(red) == 0:
    print(len(white) - 1)
else:
    red.sort(reverse=True)
    count = 0
    while(1):
        if red[0] > white[0]:
            red.pop(0)
            red.append(white[0])
            white.pop(0)
            count += 1
            break
        
    print(count)

n = int(input())
c = input()

red = [i for i, x in enumerate(c) if x == 'R']
white = [i for i, x in enumerate(c) if x == 'W']

if len(white) == 0 or len(red) == 0:
    print(0)
    
else:
    red.sort(reverse=True)
    red_p = 0
    white_p = 0
    
    count = 0
    while(1):
        if white_p >= len(white):
            break
        elif red[red_p] < white[white_p]:
            break
        else:
            red_p += 1
            red.append(white[white_p])
            white_p += 1
            count += 1
            
    print(count)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N = int(input())
half_N = int(N/2)
words = list(input())
ct_R = words.count('R')
ct_W = words.count('W')

if ct_W == ct_R:
  jhw = words[0:half_N]

  print(jhw.count('W'))
  
if ct_W <= ct_R:
    jhw = words[ct_R:-1]
    print(jhw.count('R'))
    
if ct_W >= ct_R:
    jhw = words[0:ct_R]
    print(jhw.count('R'))


N = int(input())
words = list(input())
ct_R = words.count('R')
ct_W = words.count('W')
a = words[0:ct_R]
W_in_a_count = a.count('W')
print(W_in_a_count)


Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
s1 = input()
s2 = s1[::-1]
i1 = 0
i2 = 0
ans = 0
while i1 < n:
  if s1[i1]=='W':
    while i2 < n:
      if s2[i2]=='R':
        ans += 1
        i2 += 1
        break
      elif i1+i2 >= n-2:
        break
      else:
        i2 += 1
  i1 += 1
  if i1+i2 >= n-2:
    break
    
print(ans)

n = int(input())
s1 = input()
s2 = s1[::-1]
i1 = 0
i2 = 0
ans = 0
while i1 < n:
  if s1[i1]=='W':
    while i2 < n:
      if s2[i2]=='R':
        ans += 1
        i2 += 1
        break
      elif i1+i2 >= n-2:
        break
      else:
        i2 += 1
  if i1+i2 >= n-2:
    break
  i1 += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N = int(input())
S = input()

c = Counter(S)
S_target = 'R' * c['R'] + 'W' * c['W']

ans = 0
for a, b in zip(S, S_target):
    if b == 'W':
        break
    if a != b:
        ans += 1
print(ans)


from collections import Counter

class Levenshtein:

    def initArray(self,str1,str2):
        distance = []
        for i in range(len(str1)+1):
            distance.append([0]*(len(str2)+1))
            distance[i][0] = i
        for j in range(len(str2)+1):
            distance[0][j] = j
        return distance

    def editDist(self,str1,str2,distance):
        dist = [0]*3
        for i in range(1,len(str1)+1):
            for j in range(1,len(str2)+1):
                dist[0] = distance[i-1][j-1] if str1[i-1]==str2[j-1] else distance[i-1][j-1]+1
                dist[1] = distance[i][j-1]+1
                dist[2] = distance[i-1][j]+1
                distance[i][j]=min(dist)
        return distance[i][j]

    def __init__(self,str1,str2):
        self.str1 = str1
        self.str2 = str2
        Levenshtein.distance = self.initArray(str1,str2)
        Levenshtein.dist = self.editDist(str1,str2,Levenshtein.distance)

N = int(input())
S = input()

c = Counter(S)
S_target = 'R' * c['R'] + 'W' * c['W']
print(S_target)

leven = Levenshtein(S, S_target)
print(leven.dist // 2)

from collections import Counter

N = int(input())
S = input()

c = Counter(S)
S_target = 'R' * c['R'] + 'W' * c['W']

ans = 0
for a, b in zip(S, S_target):
    if b == 'W':
        break
    if a != b:
        ans += 1
print(ans)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
    for c in C[r:]:
        _counter[c] = _counter.get(c, 0) + 1
    _r = _counter.get(R, 0)

    ans = _r
    print(ans)
if __name__ == '__main__':
    main()


from queue import deque
def main():
    R, W = "R", "W"
    N = int(input())
    C = input()

    counter = dict()
    for c in C:
        counter[c] = counter.get(c, 0) + 1
    r = counter.get(R, 0)

    _counter = dict()
    for c in C[r:]:
        _counter[c] = _counter.get(c, 0) + 1
    _r = _counter.get(R, 0)

    ans = _r
    print(ans)
if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
ans = 0
n = int(input())
c = input()
print(c)
check  = c[0]
count = 0
flag=0
for i in c:
    if(i=="R"):
        count+=1
for i,k in enumerate(c):
    print(check,k)
    if check=="W" and k=="R":
        ans+=1
        check = "W"
        if i<count:
            flag+=1
    else:
        check  = k
print(ans-flag)
    

ans = 0
n = int(input())
c = input()
#print(c)
check  = c[0]
count = 0
flag=0
for i in c:
    if(i=="R"):
        count+=1
for i,k in enumerate(c):
#    print(check,k)
    if check=="W" and k=="R":
        ans+=1
        check = "W"
        if i<count:
            flag+=1
    else:
        check  = k
print(ans-flag)
    

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n=int(input())
s=input().strip()
R=s.count('R')
t=0
for i in range(R):
    if s[i]=='W':
        t=t+1
u=R-(n-R-t)
f=max(t,u)
if R==0 or R==n or t==R:
    f=0
print(f)
    

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

l, r = 0, N - 1
cost = 0
while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        # R...W
        cost += 1
        l += 1
        r -= 1

print(cost)


Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n=int(input())
c=input()
r=c.count('R')
w=c.count('W')
rch=c[:r].count('W')
wch=c[r:].count('R')
print(min(rch,wch))
print(r,w,rch,wch)

n=int(input())
c=input()
r=c.count('R')
w=c.count('W')
rch=c[:r].count('W')
wch=c[r:].count('R')
print(min(rch,wch))

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
c = list(input())



ans1 = 0
for i in range(len(c)):
    if c[-(i+1)] == "R":
        break
ans1 = min(c[0:(n-i-1)].count("R"),c[0:(n-i-1)].count("W"))
ans2 = 0
right = 0
for i in range(len(c)):
    if i >= (n-right-1):
        break
    if c[i] == "W":
        for j in range(right,len(c)):
            if c[-(j+1)] == "R":
                right = j
                ans2 += 1
                break
print(min(ans1,ans2))

n = int(input())
c = list(input())

ans = 0
right = n-1
for i in range(n):
    if c[i] == "W":
        for j in range(right,-1,-1):
            if j <= i:
                print(ans)
                exit()
            if c[j] == "R":
                ans += 1
                right = j-1
                break
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
import datetime
import string
import re
import math

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

count = 0
begin = 0
end = len(str) - 1
while True:
    if begin < len(str):
        while str[begin] == 'W':
            begin += 1
            if begin == len(str):
                break

    if end >= 0:
        while str[end] == 'R':
            end -= 1
            if end == -1:
                break

    if begin < end:
        str[begin] = 'R'
        str[end] = 'W'
        begin += 1
        end -= 1
        count += 1
    elif begin == len(str) and end != -1:
        if str[end + 1] == 'R':
            str[end] = 'W'
            end -= 1
            count += 1
        else:
            end -= 1
    elif begin != len(str) and end == -1:
        if str[begin - 1] == 'W':
            str[begin] = 'R'
            begin += 1
            count += 1
        else:
            begin += 1
    else:
        print(count)
        break

import datetime
import string
import re
import math

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

count = 0
begin = 0
end = len(str) - 1
while True:
    if begin < len(str):
        while str[begin] == 'W':
            begin += 1
            if begin == len(str):
                break

    if end >= 0:
        while str[end] == 'R':
            end -= 1
            if end == -1:
                break

    if begin < end:
        str[begin] = 'R'
        str[end] = 'W'
        begin += 1
        end -= 1
        count += 1
    elif begin >= len(str) and end > -1:
        if end != len(str) - 1:
            if str[end + 1] == 'R':
                str[end] = 'W'
                end -= 1
                count += 1
            else:
                end -= 1
        else:
            end -= 1
    elif begin < len(str) and end <= -1:
        if begin != 0:
            if str[begin - 1] == 'W':
                str[begin] = 'R'
                begin += 1
                count += 1
            else:
                begin += 1
        else:
            begin += 1
    else:
        print(count)
        break

Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N = int(input())
c = str(input())

a = 0
b = 0

for i in range(N):
    if s[i] == 'R':
        a = a + 1
ans = max(a,b)
for i in range(N):
    if s[i] == 'R':
        a = a - 1
    else:
        b = b + 1
    now = max(a,b)
    ans = min(ans, now)
print(ans)


N = int(input())
s = str(input())

a = 0
b = 0

for i in range(N):
    if s[i] == 'R':
        a = a + 1
ans = max(a,b)
for i in range(N):
    if s[i] == 'R':
        a = a - 1
    else:
        b = b + 1
    now = max(a,b)
    ans = min(ans, now)
print(ans)


Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N = int(input())
S = input()
r_c = 0
ch = 0
for i in S:
  if i == "R":
    r_c += 1
for i in range(r_c):
  if i == "W"
    ch += 1
print(ch)

N = int(input())
S = input()
r_c = 0
ch = 0
for i in S:
  if i == "R":
    r_c += 1
for i in range(r_c):
  if S[i] == "W":
    ch += 1
print(ch)

Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n  = int(input())
c = list(input())


rcnt = c.count('R')
wcnt = c.count('W')

ans = 0
if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    cnt = 0
    for i in range(rcnt):
        if c[i] == 'R':
            cnt += 1
    
    print(cnt)


n  = int(input())
c = list(input())


rcnt = c.count('R')
wcnt = c.count('W')

ans = 0
if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    cnt = 0
    for i in range(rcnt):
        if c[i] == 'R':
            cnt += 1
    
    print(rcnt - cnt)


Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
'import zlib
print(eval(zlib.decompress(b\\'x\xda\xf3\xd3I\xb6\xcd\xcc+(-\xd1\xd0\xd4\x81\xd2\xd6\x05E\x99y%\x1a\xc9\xd1V\xc9z\xc9\xf9\xa5@\xa6z\x90\xbaf,\x8c\x1d\xae\xae\xa9\t\x00\xf0]\x11O\\')))'

N,c=input(),input()
print(c[:c.count('R')].count('W'))

Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N = int(input())
c = str(input())

w = c.count("W")
r = c.count("R")

ans = r

if w == 0:
    print(0)
else:
    if c[0]=="R":
        for i in range(N):
            if c[i] == "W":
                ans -= i
                print(ans)
                break
    elif c[0]=="W":
        for k in range(N):
            if c[k] == "W" and c[k+1] == "W":
                ans -= k-1
                print(ans)
                break

N = int(input())
c = str(input())

w = c.count("W")
r = c.count("R")

ans = r

if w == 0:
    print(0)
else:
    if c[0]=="R":
        for i in range(N):
            if c[i] == "W":
                ans -= i
                print(ans)
                break
            break
 

N = int(input())
c = str(input())

w = c.count("W")
r = c.count("R")

cnt = 0

for i in range(r):
    if c[i] == "W":
        cnt += 1

print(cnt)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
balls = list(input())

backindex = len(balls) - 1
frontindex = 0
actions = 0

while frontindex < backindex:
  if balls[frontindex] == 'W':
    while backindex > frontindex:
      if balls[backindex] == 'R':
        balls[frontindex] = 'R'
        balls[backindex] = 'W'
        actions += 1
        break
      backindex -= 1
  frontindex += 1

print(actions)

balls = list(input())

backindex = len(balls) - 1
frontindex = 0
actions = 0

while frontindex != backindex:
  if balls[frontindex] == 'W':
    while backindex > frontindex:
      if balls[backindex] == 'R':
        balls[frontindex] = 'R'
        balls[backindex] = 'W'
        actions += 1
        break
      backindex -= 1
  frontindex += 1

print(actions)

n = input()
balls = list(input())

backindex = len(balls) - 1
frontindex = 0
actions = 0

while frontindex < backindex:
  if balls[frontindex] == 'W':
    while backindex > frontindex:
      if balls[backindex] == 'R':
        balls[frontindex] = 'R'
        balls[backindex] = 'W'
        actions += 1
        break
      backindex -= 1
  frontindex += 1

print(actions)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N = int(input())
stones = input()
count_R = stones.count('R')

if N == count_R:
    answer = 0
elif N - count_R > count_R:
    answer = count_R
else:
    answer = count_R - 1

print(answer)



N = int(input())
stones = input()

total_count_R = stones.count('R')
left_count_R = stones[:total_count_R].count('R')

answer = total_count_R - left_count_R

print(answer)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break
    
print(min(C.count("R"),C.count("W")))

N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break

for i in range(1,N):
    if C[-i]=="W":
        C=C[:-i+1]
        break    
    

print(min(C.count("R"),C.count("W")))

N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break
for i in range(N):
    if C[-i]=="R":
        C=C[:-i]
        break    
    

print(min(C.count("R"),C.count("W")))

N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break

if C[-1]=="R":
    for i in range(1,N):
        if C[-i]=="W":
            C=C[:-i+1]
            break    
    

print(min(C.count("R"),C.count("W")))

N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break
for i in range(N):
    if C[-i]=="W":
        C=C[:-i+1]
        break    
    

print(min(C.count("R"),C.count("W")))

N=int(input())
C=input()

ans=2000001
for i in range(N+1):
    WL=C[:i].count("W")
    RL=C[:i].count("R")
    WR=C[i:].count("W")
    RR=C[i:].count("R")
    
    if  ans>max(WR,RL):
        ans=max(WR,RL)
print(ans)

N=int(input())
C=input()

W=0
R=C.count("R")
ans=R
for i in range(N):
    
    if C[i]=="R":
        R-=1
    else:
        W+=1
    if  ans>max(W,R):
        ans=max(W,R)
print(ans)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
N = int(input())
rw = list(input())

rw_after=sorted(rw)
print(rw_after)

count=0
for i in range(N):
    if rw[i] != rw_after[i]:
        count+=1
print(int(count/2))


N = int(input())
rw = list(input())

rw_after=sorted(rw)

count=0
for i in range(N):
    if rw[i] != rw_after[i]:
        count+=1
print(int(count/2))


Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
Cc = copy.copy(Cn)
if (Cn[0] == "R"):
    Rflg = True
else:
    Rflg = False
ans = 0
K = N-1    
allw = False
for i in range(N):
    if Rflg and Cc[i] == "R":
        continue
    else:
        Rflg = True
    if Cc[i] == "W":
        for j in range(K, i, -1):
            if Cc[j] == "R":
#                 print("change")
                ans += 1
                Cc[i], Cc[j] = Cc[j], Cc[i]
                K = j
#                 print(Cc)
                break
        else:
            allw = True

    else:
#         print("replace")
        ans += 1
        Cc[i] = "W"
#         print(Cc)
    if allw:
        break

import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations

# input = sys.stdin.readline
N = int(input())
Cn = list(input())

Cc = copy.copy(Cn)
if (Cn[0] == "R"):
    Rflg = True
else:
    Rflg = False
ans = 0
K = N-1    
allw = False
for i in range(N):
    if Rflg and Cc[i] == "R":
        continue
    else:
        Rflg = True
    if Cc[i] == "W":
        for j in range(K, i, -1):
            if Cc[j] == "R":
#                 print("change")
                ans += 1
                Cc[i], Cc[j] = Cc[j], Cc[i]
                K = j
#                 print(Cc)
                break
        else:
            allw = True

    else:
#         print("replace")
        ans += 1
        Cc[i] = "W"
#         print(Cc)
    if allw:
        break

print(ans)


















Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
m = input()
runlength = []
count = 1
for i in range(len(m)):
    if i == n-1:
        runlength.append([m[i],count])
        break
    if m[i] ==  m[i+1]:
        count += 1
    elif m[i] != m[i+1]:
        runlength.append([m[i],count])
        count = 1


count = 0


for i,j in runlength:
    if i == "W":
        count += j

count -= 1
print(count)

n = input()
m = input()
maxr = m.count("R")
maxw = m.count("W")

min_move = len(m)
max_r = m.count("R")
max_w = m.count("W")
right = 0
left = 0
for i in range(len(m)):
    if m[i] == "W":
        left += 1
    else:
        max_r -= 1
    if max(left,max_r) < min_move:
        min_move = max(left,max_r)
if maxw == 0 or maxr == 0:
    print(0)
else:
    print(min_move)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
from collections import deque
N=int(input())
C=list(input())

qw=deque(list())
qr=deque(list())

ans=0
for i in range(N//2):
    if C[i]=='W':
        qw.append(i)
    if C[-(i+1)]=='R':
        qr.append(-(i+1))
    if len(qw)>0 and len(qr)>0:
        ans+=1
        l=qw.popleft()
        r=qr.popleft()
        C[l],C[r]=C[r],C[l]

if len(qw)>0:
    l=qw.popleft()
    if C[l+1]=='R':
        C[l+1]='W'
        ans+=1
elif len(qr)>0:
    r=qr.popleft()
    if C[r-1]=='W':
        C[r-1]='R'
        ans+=1

if (C[N//2-1]==C[N//2]==C[N//2+1]) or (C[N//2]=='R' and C[N//2-1]=='R' and C[N//2+1]=='W') or (C[N//2]=='W' and C[N//2-1]=='R' and C[N//2+1]=='R'):
    print(ans)
else:
    print(ans+1)



N=int(input())
C=list(input())
ans=0

w=0
r=0
for i in range(N//2):
    print(i,C[i])
    if C[i]=='W':
        w+=1
    if C[i-2]=='R':
        r+=1

if w==0 or r==0:
    ans=0
else:
    ans=max(w,r)

print(ans)


N=int(input())
C=list(input())

white=[0]*(N+1)
red=[0]*(N+1)

for i in range(N):
    if C[i]=="W":
        white[i+1]=white[i]+1
        red[i+1]=red[i]
    else:
        white[i+1]=white[i]
        red[i+1]=red[i]+1

if white[-1]==N or red[-1]==N:
    print(0)
    exit()

ans=float("inf")
for i in range(1,N):
    wcnt=white[i]
    rcnt=red[-1]-red[i]
    m=max(wcnt,rcnt)
    ans=min(m,ans)

print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
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))

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))

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)

Verdicts: Runtime Error

Runtime Error

Accepted