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):
from collections import Counter
import sys
n = int(input())
c = input()
s = Counter(c)
if s['W'] == 0 or s['R'] == 0 or c.index('R') == 0 and c.index('W') == s['R']:
  print('0')
  sys.exit()
r = s['R']
las_pos=0
count = 0
for i, v in enumerate(c):
  if v == 'R':
    if i - las_pos <= r:
      r = r - (i - las_pos + 1)
      count += (i - las_pos)
      las_pos = i
    else:
      count += r
      break
  if r == 0:
    break
print(count)

import sys
from collections import Counter
n = int(input())
c = list(input())
s = Counter(c)
if s['R'] == 0 or s['W'] == 0:
  print('0')
  sys.exit()
pos_w=0
pos_r=n-1
count = 0
for i in range(pos_w, n):
  if c[i] != 'W':
    continue
  pos_w = i
  for j in range(pos_r, -1, -1):
    if c[j] != 'R':
      continue
    pos_r = j
    if pos_w > pos_r:
      print(count)
      sys.exit()
    c[i] = 'R'
    c[j] = 'W'
    count += 1
    break

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):
X = input()
count_w, n, count = X.count('W'), len(X), 0
for i in range(n - 1, n -1 - count_w, -1):
  count += 1 if X[i] == 'R' else 0
  
print(count)

n, X = int(input()), input()
count_w, count = X.count('W'), 0
for i in range(n - 1, n -1 - count_w, -1):
  count += 1 if X[i] == 'R' else 0
  
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())
arr = list(input())
print(arr)
head = 0
tail = n-1
count = 0
while True:
    while arr[head]=='R' and head<tail:
        head+=1
    while arr[tail]=='W' and head<tail:
        tail-=1
    if arr[head]=='W' and arr[tail]=='R':
        count+=1
    head+=1
    tail-=1
    if head>=tail:
        break
print(count)

n = int(input())
arr = list(input())
head = 0
tail = n-1
count = 0
while True:
    while arr[head]=='R' and head<tail:
        head+=1
    while arr[tail]=='W' and head<tail:
        tail-=1
    if arr[head]=='W' and arr[tail]=='R':
        count+=1
    head+=1
    tail-=1
    if head>=tail:
        break
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())
c = input()
d = c.count('w')
e = c[:d].count('w')
print(d-e)

n = int(input())
c = input()
d = c.count(w)
e = c.count(w)[:d]
print(d-e)

n = int(input())
c = input()
d = c.count('R')
e = c[:d].count('R')
print(d-e)

Verdicts: Wrong Answer

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(str(input()))

count=0
flag=False

for i in range(n):
	if c[i]=="W":
		flag=True
	else:
		if flag==True:
			count+=1
			flag=False
print(count)

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

R=c.count("R")

cnt=0
for i in range(R):
	if c[i]=="R":
		cnt+=1
print(R-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):
N = int(input())
c = input()

c = [c[i] for i in range(N)]

cR = c.count('R')
cW = c.count('W')

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

if all([i == 'R' for i in c[:cR]]):
    print(0)
    exit()

if all([i == 'W' for i in c[:cW]]):
    print(0)
    exit()

cnt = 0

for i in range(N):
        c[listR[-(i+1)]] = 'W'
        c[listW[i]] = 'R'
        cnt += 1
        if all([i == 'R' for i in c[:cR]]):
            print(cnt)
            break


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

cR = c.count('R')
cW = c.count('W')


if all([i == 'R' for i in c[:cR]]):
    print(0)
    exit()

if all([i == 'W' for i in c[cR:cR+cW]]):
    print(0)
    exit()

ans = c[:cR].count('W')

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())
c = list(input())
ans = 0
#print(c)
for i in range(N):
    flag = 0
    if c[i] == "R":
        continue
    elif c[i] == "W":
        #print(c, ans, i, sep=" ",)
        for j in reversed(range(N)):
            if i == j:
                flag = 1
                break
            if c[j] == "R":
                c[i], c[j] = c[j], c[i]
                ans += 1
                print(c, ans, sep=" ")
                break
        else:
            continue
        if flag == 1:
            break

print(ans)

N = int(input())
c = list(input())
ans = 0
cnt = c.count("W")
ans = c[N-cnt:].count("R")
if cnt != 0:
    print(ans)
else:
    print(0)

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 = list(input())
l = 0
r = n-1
c = 0
while l < r:
  for i in range(l, r):
    if s[i] == "W":
      l = i
      break
  else:
    l = r
  for i in range(r, l, -1):
    if s[i] == "R":
      r = i
      break
  else:
    r = l
  if l < r:
    c += 1
print(c)
      
    

n = int(input())
s = list(input())
l = 0
r = n-1
c = 0
while l < r:
  for i in range(l, r):
    if s[i] == "W":
      c += 1
      l = i+1
      break
  else:
    l = r
  for i in range(r, l-1, -1):
    if s[i] == "R":
      r = i-1
      c += 1
      break
  else:
    r = l

print(c//2)
      
    

Verdicts: Time Limit Exceeded

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):
# -*- coding: utf-8 -*-
n = int(input())
cs = input()
r_num = 0
w_num = 0

r_num = cs.count('R')

if r_num == 0 or w_num == 0:
    print(0)
else:
    ans = []
    W = 0
    rl_num = 0
    for c in cs:
        if c == 'R':
            rl_num += 1
        elif c == 'W':
            W += 1  
        R = r_num - rl_num  
        ans.append(max(W, R))

    print(min(ans))


# -*- coding: utf-8 -*-
n = int(input())
cs = input()
r_num = 0
w_num = 0

r_num = cs.count('R')
w_num = cs.count('W')

if r_num == 0 or w_num == 0:
    print(0)
else:
    ans = []
    W = 0
    rl_num = 0
    for c in cs:
        if c == 'R':
            rl_num += 1
        elif c == 'W':
            W += 1
        R = r_num - rl_num
        ans.append(max(W, R))

    print(min(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 bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    c = list(SS())
    c_r = c[::-1]

    
    if 'R' not in c or 'W' not in c:
        print(0)
    else:
        idx_R = c.index('R')
        ans0 = c[idx_R:].count('W')
        idx_W = c_r.index('W')
        ans1 = c_r[idx_W:].count('R')
        print(min(ans0, ans1))

if __name__ == '__main__':
    resolve()


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    c = list(SS())

    
    # WRWWRWRR
    # RRWWRWRW
    # RRRWRWWW
    # RRRRWWWW
    cnt_r = c.count('R')
    ans = max(c[:cnt_r].count('W'), c[cnt_r:].count('R'))
    # print(c[:cnt_r], c[cnt_r:])
    print(ans)

if __name__ == '__main__':
    resolve()


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):
def main():
    N=int(input())
    c=list(input())[::-1]
    
    #x...WR
    #o...RR, RW, WW
    
    
    
    res=0
    cR=c.count('R')
    cW=c.count('W')
    
    l,r=0,N-1
    while True:
        if c[l]=='W':
            if c[r]=='R':
                c[l],c[r]='R','W'
                res+=1
            else:
                r-=1
        else:
            l+=1
        
    print(min(cR,cW,res))
    
 
if __name__ == '__main__':
    main()

def main():
    N=int(input())
    c=list(input())
    
    #x...WR
    #o...RR, RW, WW
    
    
    
    res=0
    cR=c.count('R')
    cW=c.count('W')
    
    l,r=0,N-1
    while l!=r:
        if c[l]=='W':
            if c[r]=='R':
                c[l],c[r]='R','W'
                res+=1
            else:
                r-=1
        else:
            l+=1
        
    print(min(cR,cW,res))
    
 
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):
n = int(input())
c = input()

wi = c.find('W')
ri = c.rfind('R')

if wi == -1 or ri == -1:
    print(0)
else:
    ans = 0
    while wi < ri:
        wi += 1
        wi = c[wi:].find('W')
        ri = c[:ri].rfind('R')
        ans += 1

    print(ans, c)

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

wi = c.find('W')
ri = c.rfind('R')

if wi == -1 or ri == -1:
    print(0)
else:
    ans = 0
    while wi < ri:
        wi += 1
        wi = c[wi:].find('W') + wi
        ri = c[:ri].rfind('R')
        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):
def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    li[i] = "R"
    li[j] = "W"
    ans += 1
  print(ans)


if __name__ == '__main__':
  main()

def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    if li[i] == "W" and li[j] == "R":
      li[i] = "R"
      li[j] = "W"
      ans += 1
    print(li)
  print(ans)


if __name__ == '__main__':
  main()

def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    if li[i] = "W" and li[j] = "R":
      li[i] = "R"
      li[j] = "W"
      ans += 1
  print(ans)    

if __name__ == '__main__':
  main()

def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    if li[i] == "W" and li[j] == "R":
      li[i] = "R"
      li[j] = "W"
      ans += 1
  print(ans)    

if __name__ == '__main__':
  main()

Verdicts: Wrong Answer

Wrong Answer

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

left = 0
right = len(c)-1

count=0
if (right+1)%2==0:
    while (left-1)!=right:
        print(right,left)
        if c[left]=='R':
            left+=1 
        elif c[right]=='W':
            right-=1
        elif c[left]=='W' and c[right]=='R':
            left+=1
            right-=1
            count+=1
else :
    while left!=right:
        if c[left]=='R':
            left+=1 
        elif c[right]=='W':
            right-=1
        elif c[left]=='W' and c[right]=='R':
            left+=1
            right-=1
            count+=1

ans = count
print(ans)

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

left = 0
right = len(c)-1

count=0
if (right+1)%2==0:
    while (left-1)!=right:
        if c[left]=='R':
            left+=1 
        elif c[right]=='W':
            right-=1
        elif c[left]=='W' and c[right]=='R':
            left+=1
            right-=1
            count+=1
else :
    while left!=right:
        if c[left]=='R':
            left+=1 
        elif c[right]=='W':
            right-=1
        elif c[left]=='W' and c[right]=='R':
            left+=1
            right-=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):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]

#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate 
import math

N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)

def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num)
    
    return cnt


while True:
    mid = (left + right) // 2
    tmp = count(mid)
    if tmp == K:
        break
    elif tmp > K:
        if left == mid:
            mid += 1
            break
        left = mid
    else:
        right = mid

if mid == 0:
    print(mid)
    exit()

right = mid
while True:
    tmp = count(mid)
    if tmp == K and tmp != count(mid-1):
        print(mid)
        break
    elif tmp == K:
        right = mid
    else:
        left = mid
    mid = (left + right) // 2

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]

#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
S = input()

num_r = S.count('R')
ans = num_r

for i in range(num_r):
    if S[i] == 'R':
        ans -= 1

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())
c = input()
W = c.count('W')
print(c[:R].count('W'))

N = int(input())
c = input()
W = c.count('W')
R = c.count('R')
print(c[: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())
A = list(input())
print(C[:C.count('R')].count("W"))


n = int(input())
C = 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 = 8
# S = "WRWWRWRR"
#
# N = 2
# S = "RR"
#
# N = 4
# S = "WWRR"

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

# N = 2
# S = "WW"

def calculate(n, s):
    arr = list(s)

    RNum = arr.count("R")

    leftW = 0
    rightR = RNum

    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        if leftW == 0 or rightR == 0:
            result.append(0)
            continue

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)


def calculate(n, s):
    arr = list(S)

    RNum = arr.count("R")

    leftW = 0
    rightR = RNum

    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)


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


def calculate(n, s):
    arr = list(s)
    result = []


    leftW = 0
    rightR = arr.count('R')


    if rightR == 0:
        print(0)
        return

    for i in range(n):
        val = arr[i]

        if val == 'R':
            rightR -= 1

        if val == 'W':
            leftW += 1

        result.append(max(leftW,rightR))

    if len(result) == 0:
        print(0)
    else:
        print(min(result))

calculate(N, S)


Verdicts: Wrong Answer

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()
if s.count('R')==0 or s.count('W')==0:
    print(0)
else:
    a= s.count('W')
    w=s.index('W')
    b= s[w:].count('R')
    if b==0:
        print(0)
    else:
        c = s[(w+1):].count('W')
        t=min(b,c)
        print(min(t,a))



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


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())
stone = list(map(str,input()))
ind = [""]*2
ind[0] = list()
ind[1] = list()
R = 0
W = 0
for i in range(N):
    if(stone[i]=="W"):
        ind[0].append(i)
        W += 1
    else:
        ind[1].append(i)
        R += 1
ind[1].reverse()
ans = 0

if(W != R):
    print(min(W,R))
else:
    for i in range(N):
        if(ind[0][i]>ind[1][i]):
            break
        ans+=1
    print(ans)


N = int(input())
stone = list(map(str,input()))
ind = [""]*2
ind[0] = list()
ind[1] = list()
R = 0
W = 0
for i in range(N):
    if(stone[i]=="W"):
        ind[0].append(i)
        W += 1
    else:
        ind[1].append(i)
        R += 1
newR = 0
for i in range(R):
    if(i != ind[1][i]):
        break
    newR+= 1


newind =list(reversed(ind[1]))
ans2 = 0

# print(W,R,newR)
# print(ind[1],newind)
if(newR != R):
    ans1 = min(W,R-newR)
else:
    ans1 = min(W,R)
if(ans1 != 0):
    for i in range(N//2):
        if(ind[0][i]>newind[i]):
            break
        ans2+=1
        # print(ans)
print(min(ans1,ans2))


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):
import sys
N = int(input())
c = [str(x) for x in list(input())]
R = sum([1 for i, x in enumerate(c) if(x=='R')])
W = 0
if(R==N)or(R==0):
  print(0)
  sys.exit()
ans = R
i = 0
while True:
  if(c[i] == 'W'):
    W += 1
  else:
    R -= 1
  n_ans = max(W,R)
  if(n_ans>ans):
    print(ans)
    sys.exit()
  ans = n_ans
  i += 1


import sys
N = int(input())
c = [str(x) for x in list(input())]
R = sum([1 for i, x in enumerate(c) if(x=='R')])
W = 0
if(R==N)or(R==0):
  print(0)
  sys.exit()
ans = R
i = 0
while True:
  if(i==N):
    print(ans)
    sys.exit()
  if(c[i] == 'W'):
    W += 1
  else:
    R -= 1
  n_ans = max(W,R)
  if(n_ans>ans):
    print(ans)
    sys.exit()
  ans = n_ans
  i += 1

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 = list(input().strip())

r = S.count('R')
w = S.count('W')

ans = min(r, w)

ri = S.index('R')
r2 = S[ri:].count('W')

ans = min(ans, r2)
print(ans)



N = int(input())
S = list(input().strip())

r = S.count('R')
w = S.count('W')

ans = min(r, w)

ri = S.index('R')
r2 = S[:ri].count('R')
w2 = S[ri:].count('W')

ans = min(ans, r2+w2)
print(ans)



N = int(input())
S = list(input().strip())

l = 0
r = N-1
ans = 0
while l < r:
    if S[l] == 'W' and S[r] == 'R':
        ans += 1
        l += 1
        r -= 1
    while l < N and S[l] != 'W':
        l += 1
    while r >= 0 and S[r] != 'R':
        r -= 1

print(ans)

Verdicts: 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):
import collections

c=input()

tmp=collections.Counter(c)

count_r=0
count_w=0
ans=0
dis_r=0

for i in c:
    if dis_r == tmp["R"]:
        break
        
    elif i == "W":
        if count_r<=tmp["R"]-count_r:
            ans+=1
            dis_r+=1
    else:
        count_r+=1
        dis_r+=1
print(ans)

import collections

c=input()
c=input()

tmp=collections.Counter(c)

count_r=0
count_w=0
ans=0
dis_r=0

for i in c:
    if dis_r == tmp["R"]:
        break
        
    elif i == "W":
        if count_r<=tmp["R"]:
            ans+=1
            dis_r+=1
        else:
            ans+=1
    else:
        count_r+=1
        dis_r+=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 sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
print(s[n//2].count('W'))

import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
cnt = 0
i = 0
j = n-1
while True:
    while s[i] == 'R':
        i += 1
        if i >= n:
            break
    while s[j] == 'W':
        j -= 1
        if j < 0:
            break
    if i < j:
        cnt += 1
        i += 1
        j -=1
    else:
        break
print(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 itertools
N = int(input())
S = input()
cnt = 0
while True:
    while i < N and S[i] == 'R':
        i += 1
    while 0 <= j and S[j] == 'W':
        j -= 1
    if j < i:
        break
    cnt += 1
    i += 1
    j -= 1
print(cnt)


import itertools
N = int(input())
S = input()
cnt = i = 0
j = N - 1
while True:
    while i < N and S[i] == 'R':
        i += 1
    while 0 <= j and S[j] == 'W':
        j -= 1
    if j < i:
        break
    cnt += 1
    i += 1
    j -= 1
print(cnt)


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):
import sys
input = sys.stdin.readline
n = int(input())
s = list(input())
ans = 0
for i in range(n - 1):
  idx = n - 1 - i
  if s[idx] == 'W' and s[idx + 1] == 'R':
    ans += 1
    s[idx] = 'R'
print(ans)

import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
for i in range(n - 1):
  idx = n - 1 - i
  if s[idx] == 'W' and s[idx + 1] == 'R':
    ans += 1
    s[idx] = 'R'
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
for i in range(n - 1):
  if s[i] == 'W' and s[i + 1] == 'R':
    ans += 1
print(ans)
  

import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
r = [0] * n
w = [0] * n
for i in range(n):
  if s[i] == 'W':
    w[i] += 1
  else:
    r[i] += 1
for i in range(1, n):
  w[i] += w[i - 1]
  r[i] += r[i - 1]
rn = r[n - 1]
ans = n
if rn == 0:
  ans = 0
for i in range(n):
  c = (i + 1)
  ri = r[i]
  left = rn - ri
  need = c - ri
  ans = min(ans, max(left, need))  

print(ans)


Verdicts: Wrong Answer

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 = list(input())
W = 0
R = 0
for i in range(int(N/2)+1):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2+1),N):
    if C[i] == 'R':
        R += 1
if W>R:
    print(R)
else:
    print(W)



N = int(input())
C = list(input())
W = 0
R = 0
for i in range(0,int(N/2+1)):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2+1),N):
    if C[i] == 'R':
        R += 1
if W >= R:
    print(R)
else:
    print(W)




N = int(input())
C = list(input())
W = 0
R = 0
for i in range(0,int(N/2)):
    if C[i] == 'W':
        W += 1
    print(C[i])
print("-------------")
for i in range(int(N/2),N):
    if C[i] == 'R':
        R += 1
    print(C[i])
if W>=R:
    print(R)
else:
    print(W)


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

for i in range(N):
    W = 0
    R = 0
    for j in range(0,int(N/2+1)):
        if C[j] == 'W':
            W += 1
    for j in range(int(N/2+1),N):
        if C[j] == 'R':
            R += 1
    if W > R:
        count.append(R)
    else:
        count.append(W)

print(min(count))

N = int(input())
C = list(input())
count = list()
W = 0
R = 0

for i in C:
    if i == "R":
        R += 1

if R == 0:
    count.append(0)

for i in C:

    if i == "W":
        W += 1
    else:
        R -= 1

    if W <= R:
        count.append(R)
    else:
        count.append(W)

print(min(count))

Verdicts: Wrong Answer

Wrong Answer

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())
s = input()
l = 0
r = n - 1
ans = 0
while l < r:
    while l < r && s[l] == 'R':
        l += 1
    while l < r && s[r] == 'W':
        r -= 1
    ans += 1
    l += 1
    r -= 1

print(ans)

n = int(input())
s = input()
l = 0
r = n - 1
ans = 0

while l < r:
    while l < r and s[l] == 'R':
        l += 1
    while l < r and s[r] == 'W':
        r -= 1
    if l >= r:
        break
    ans += 1
    l += 1
    r -= 1

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):
from collections import Counter


N = int(input())
C = input()
C_cntr = Counter(C)

ans = 0
for i in range(C_cntr["R"]):
　if C[i] == "W":
        ans += 1

print(ans)


from collections import Counter


N = int(input())
c = input()
cntr = Counter(c)

ans = 0
for c, r in zip(c, "R" * cntr["R"]):
    if c != r:
        ans += 1
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())
c=list(input())
print(c)
i=0
count1=0
count2=0
for i in c:
    if i=="R":
        count1+=1
for j in range(count1):
    if c[j]=="R":
        count2+=1
print(count1-count2)

N=int(input())
c=list(input())
i=0
count1=0
count2=0
for i in c:
    if i=="R":
        count1+=1
for j in range(count1):
    if c[j]=="R":
        count2+=1
print(count1-count2)

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())
a=input()
print(a)
a=list(a)
print(a)
t=0
s=0
for i in range(0,n):
    if a[i]=="R":
        t=t+1

for i in range(0,t):
    if a[i]!="R":
        s=s+1
print(s)

n=int(input())
a=input()
print(a)
a=list(a)
print(a)
t=0
s=0
for i in range(0,n):
    if a[i]=="R":
        t=t+1
for i in range(0,t):
    if a[i]!="R":
        s=s+1
print(s)

n=int(input())
a=input()

a=list(a)

t=0
s=0
for i in range(0,n):
    if a[i]=="R":
        t=t+1

for i in range(0,t):
    if a[i]!="R":
        s=s+1
print(s)

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
R = c.count('R')
if R == 0 or W == 0:
  print(0)
  exit()

ans = N
t = 0
for i in range(N):
  if c[i] == 'W':
    W += 1
  else:
    R -= 1
  t = max(R,W)
  ans = min(ans, t)
print(ans)

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

R_r = c.count("R")
W_l = 0
ans = N
for i in range(N+1):
  t = max(R_r,W_l)
  ans = min(ans, t)
  if R_r == 0:
    break
  if c[i] == "R":
    R_r -= 1
  else:
    W_l += 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())
C=list(input())
L=0
R=0
RR=0
X=0
    for i in range(N):
      L=i
      R=RR
      if L>=N-1-R:
        break
      if C[i]=='W':
          for ii in range(N-L-R):
            if C[N-1-R-ii]=='R':
              C[L]='R'
              C[N-1-R-ii]='W'
              X+=1
              break
            RR+=1
            if L>=N-1-R:
              break
print(X)

N = int(input())
C=list(input())
W=(C.count('W'))
R=N-W
WW=0
RR=0
X=[0]*(N-1)
if W>0 and R>0:
  for i in range(N-1):
    if C[i]=='W':
      WW+=1
    RR=(N-i-1)-(W-WW)
    X[i]=max(WW,RR)
print(min(X))

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):
widx = []
ridx = []
s = input()
for i, char in enumerate(s):
  if char == "W":
    widx.append(i)
  else:
    ridx.append(i)
count = 0
i = 0
j = len(ridx) - 1
while i < len(widx) and j >= 0 and widx[i] < ridx[j]:
  i += 1
  j -= 1
  count += 1
print(count)
  

widx = []
ridx = []
n = int(input())
s = input()
for i, char in enumerate(s):
  if char == "W":
    widx.append(i)
  else:
    ridx.append(i)
count = 0
i = 0
j = len(ridx) - 1
while i < len(widx) and j >= 0 and widx[i] < ridx[j]:
  i += 1
  j -= 1
  count += 1
print(count)

Verdicts: Wrong Answer

Accepted