problem_id
stringclasses
100 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
6
806
p02597
s625730691
Accepted
n = int(input()) c_l = list(input()) c_l = [ 1 if c == 'R' else 0 for c in c_l ] r_n = sum(c_l) w_n = sum(c_l[:r_n]) print(r_n-w_n)
p02597
s433151878
Accepted
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)
p02597
s772120415
Accepted
n = int(input()) s = input() w = s.count('W') print(0 if w == 0 else s[-w:].count('R'))
p02597
s911482104
Accepted
n = int(input()) c = list(input()) i = 0 j = len(c)-1 cnt = 0 while i < j: if c[i] == "R": i += 1 continue if c[j] == "W": j -= 1 continue i += 1 j -= 1 cnt += 1 print(cnt)
p02597
s158182526
Accepted
N, = map(int, input().split()) X = input().strip() i,j = 0,N-1 R = 0 while i<=j: if X[i] == "R": i += 1 continue if X[j] == "W": j -= 1 continue R += 1 i += 1 j -= 1 print(R)
p02597
s041230431
Accepted
n = int(input()) moji = input() num_r = moji.count('R') num_w = moji.count('W') ext_moji = moji[:num_r] print(ext_moji.count("W"))
p02597
s626945794
Accepted
N = int(input()) C = list(input()) W = C.count("W") R = C.count("R") w = 0 r = R ans = R for i in range(1,N+1): if C[i-1] == "W": w += 1 else: r -= 1 ans = min(ans, max(w,r)) print(ans)
p02597
s631850174
Accepted
n = int(input()) C = list(input()) r = C.count('R') c = 0 for i in range(r, n): if C[i] == 'R': c += 1 print(c)
p02597
s520572110
Accepted
n = int(input()) c = list(input()) c_sort = sorted(c) count = 0 for i in range(n): if c[i] != c_sort[i]: count += 1 print(count//2)
p02597
s824660907
Accepted
from collections import Counter N=int(input()) color=input() c = Counter(color) r = c['R'] count = 0 for i in range(N): if r == 0:break if color[i]=='W': count += 1 r -= 1 else: r -= 1 print(count)
p02597
s623718869
Accepted
N = int(input()) C = list(input()) res = 0 j = N - 1 for i in range(N): if C[i] == "W": while i < j: if C[j] == "R": res += 1 C[i] = "R" C[j] = "W" break j -= 1 if i >= j: break print(res)
p02597
s049451908
Accepted
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)
p02597
s986850683
Accepted
n = int(input()) s = input() ans = 0 while True: if not ('R' in s and 'W' in s): break r = s.rindex('R') w = s.index('W') if r < w: break s = s[:w] + 'R' + s[w+1:r] + 'W' + s[r+1:] ans += 1 print(ans)
p02597
s320836457
Accepted
N = int(input()) cs = list(input()) ans = 0 sorted = N - 1 for i in range(N): if cs[i] == "W": for j in range(sorted, i, -1): sorted = j - 1 if cs[j] == "R": cs[i], cs[j] = cs[j], cs[i] ans += 1 break if (i + 1) > sorted: break print(str(ans))
p02597
s921732958
Accepted
import sys import math import collections import decimal import itertools from collections import deque from functools import reduce import heapq import copy n = int(input()) #n, d = map(int, sys.stdin.readline().split()) s = input() #a = list(map(int, sys.stdin.readline().split())) rc = 0 for i in range(n): if s[i] == "R": rc += 1 wc = 0 for i in range(rc): if s[i] == "W": wc += 1 print(wc)
p02597
s440461924
Accepted
N = int(input()) cs = [i for i in input()] n_R = 0 for c in cs: if c == 'R': n_R += 1 n_n_R = 0 for i in range(n_R): if cs[i] == 'R': n_n_R += 1 print(n_R - n_n_R)
p02597
s667757239
Accepted
N = int(input()) C = input() R_cnt = C.count('R') x = C[:R_cnt].count('R') print(R_cnt-x)
p02597
s975272506
Accepted
n = int(input()) C = input() chk = 0 for i in range(n): if C[n-1-i] == 'R': chk = n-1-i break cnt = 1 for i in range(chk): if C[i] == 'R': cnt += 1 ans = 0 for i in range(cnt): if C[i] == 'W': ans += 1 if 'R' not in C: print(0) else: print(ans)
p02597
s536400891
Accepted
n = int(input()) c = input() r_num = c.count("R") c_left = c[:r_num] r_num_left = c_left.count("R") print(r_num - r_num_left)
p02597
s064101702
Accepted
n = int(input()) c = input() r, w = 0, 0 for i in range(n): if c[i] == 'R': r += 1 else: w += 1 ans = 0 for i in range(r): if c[i] == 'W': ans += 1 print(ans)
p02597
s077397090
Accepted
# import sys # input = sys.stdin.readline def mp(): return map(int, input().split()) def lmp(): return list(map(int, input().split())) n = int(input()) c = list(input()) r = 0 w = 0 for i in range(n): if c[i] == "R": r += 1 else: w += 1 ans = 0 for i in range(r): if c[i] != "R": ans += 1 print(ans)
p02597
s138525799
Accepted
N = int(input()) C = input() rcount = C.count("R") ans = 0 w = 0 r = 0 for i in range(rcount): if C[i] == "W": if r > 0: r -= 1 ans += 1 else: w += 1 j = N - i - 1 if C[j] == "R": if w > 0: w -= 1 ans += 1 else: r += 1 ans += w print(ans)
p02597
s822918445
Accepted
n = int(input()) stones = list(input()) w_num = 0 r_num = 0 for i in stones: if i == 'W': w_num += 1 else: r_num += 1 goal = 'R' * r_num + 'W' * w_num index = 0 poplist = list() for i in stones: if i == goal[index]: poplist.append(index) index += 1 for i in sorted(poplist, reverse=True): stones.pop(i) w_num = 0 r_num = 0 for i in stones: if i == 'W': w_num += 1 else: r_num += 1 print(min(w_num, r_num))
p02597
s105605788
Accepted
import sys n = int(input()) s = input() count_w = s.count('W') count_r = n - count_w if count_w == 0 or count_r == 0: print(0) sys.exit() sa = s[:count_r] sb = s[count_r:] num_sa = sa.count('W') num_sb = sb.count('R') if num_sa <= num_sb: print(num_sa) else: print(num_sb)
p02597
s811682789
Accepted
N=int(input()) S=input() a=S.count("W") b=S.count("R") print(min([S[:b].count("W"),a,b]))
p02597
s153033507
Accepted
# -*- coding: utf-8 -*- n = int(input()) cs = input() r_num = 0 w_num = 0 # RRR|WWWW にする 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))
p02597
s958354495
Accepted
n=int(input()) S=input() c=0 for i in range(n): if S[i]=="R": c=c+1 d=0 for i in range(c): if S[i]=="R": d=d+1 print(c-d)
p02597
s417922319
Accepted
n = int(input()) c = ','.join(input()).split(',') ans = 0 ri = -1 if c.count('W') == 0: print(0) exit() if c.count('R') == 0: print(0) exit() for i in range(n): if c[i] == 'W': while c[ri] != 'R': ri -= 1 if n < i-ri: break c[i], c[ri] = 'R', 'W' ans += 1 print(ans)
p02597
s645951942
Accepted
n = int(input()) s = input() w = [] r = [] for i,j in enumerate(s): if j == 'W': w.append(i) else: r.append(i) if len(w) == 0 or len(r) == 0: print(0) else: p = -1 q = 0 ans = 0 mp = len(r) mq = len(w) while r[p] > w[q]: ans += 1 p -= 1 q += 1 if q >= mq or -p > mp: break print(ans)
p02597
s826823562
Accepted
N = int(input()) A = input() r_cnt = A.count('R') ans = 0 for i in range(r_cnt): if A[i] != 'R': ans += 1 print(ans)
p02597
s426522836
Accepted
N=int(input()) List=input() AList=list(List) RCNT=AList.count("R") BList=sorted(List) ANUM=0 BNUM=0 ans=0 i=0 while i<N: if AList[i]!=BList[i]: ans+=1 i+=1 print(ans//2)
p02597
s383159268
Accepted
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)
p02597
s192587490
Accepted
n = int(input()) s = input() num_r = s.count("R") count = 0 for i in range(num_r): if s[i] != "R": count += 1 print(count)
p02597
s897446401
Accepted
N = int(input()) c = str(input()) w = c.count("W") rr = c[-w:].count("R") print(min(w,N-w,rr))
p02597
s892482290
Accepted
N=int(input()) num=list(input()) num=[0 if i=="W" else 1 for i in num ] count=0 first=0 for i in num: if i==1:count+=1 jk=0 for i in range(count): if num[i]==1: jk+=1 print(count-jk)
p02597
s335394086
Accepted
n=int(input()) c=input() r=c.count("R")#全R r_1=c[:r].count("R")#左からr番目までのR #print(r,r_1) ans=r-r_1 print(ans)
p02597
s350400092
Accepted
import sys import math import time sys.setrecursionlimit(int(1e6)) if False: dprint = print else: def dprint(*args): pass N = list(map(int, input().split()))[0] s = list(input()) w = 0 r = s.count('R') min_op = max(w, r) dprint('w, r = ', w, r) p = 0 while(p < N): if (s[p] == 'W'): w = w + 1 else: # (s[p] = 'R') r = r - 1 min_op = min(min_op, max(w, r)) dprint('p, w, r = ', p, w, r) p = p + 1 print(min_op)
p02597
s994456119
Accepted
N = int(input()) RW = input() j = N-1 count = 0 for i in range(N): if RW[i]=='W': while i<j: if RW[j]=='R': count += 1 j -= 1 break j -= 1 print(count)
p02597
s037646454
Accepted
num = int(input()) strs = input() allRs = 0 notAlignedRs = 0 for i in range(num): if strs[i] == 'R': allRs += 1 for i in range(allRs): if strs[i] == 'W': notAlignedRs += 1 print(notAlignedRs)
p02597
s308896997
Accepted
#!/usr/bin/env python3 N = int(input()) S = list(input()) s = 0 e = N - 1 cnt = 0 while s <= e: if S[s] == 'W': while (S[e] != 'R'): if s >= e: print(cnt) exit() e -= 1 S[s], S[e] = S[e], S[s] cnt += 1 s += 1 print(cnt)
p02597
s611500388
Accepted
n=int(input()) c=input() r=c.count('R') print(c[:r].count('W'))
p02597
s144395440
Accepted
n=int(input()) c=input() r=c.count("R") w=n-r ans=0 for i,j in zip(c,"R"*r+"W"*w): if i!=j: ans+=1 print(ans//2)
p02597
s247394245
Accepted
N=int(input()) S=input() R=S.count("R") S=S[:R] r=S.count("R") print(R-r)
p02597
s867307994
Accepted
n = int(input()) c = input() r = [] w = [] for i in range(n): if c[i] == 'R': r.append(i) else: w.append(i) r.sort(reverse=True) if len(r) == 0 or len(w) == 0: print(0) else: ans = 0 while ans < len(r) and ans < len(w) and r[ans] > w[ans]: ans += 1 print(ans)
p02597
s411711081
Accepted
n = int(input()) c = input() cntR = c.count('R') print(c[:cntR].count('W'))
p02597
s633711410
Accepted
n = int(input()) c = input() lw, rr = [0]*(n+1), [c.count('R')]*(n+1) for i in range(n): lw[i+1] = lw[i] + (c[i] == 'W') rr[i+1] = rr[i] - (c[i] == 'R') def operation(left_white, right_red): swap = min(left_white, right_red) white_to_red, red_to_white = max(0, left_white-swap), max(0, right_red-swap) return swap + white_to_red + red_to_white print(min(operation(white, red) for white, red in zip(lw, rr)))
p02597
s445057755
Accepted
n = int(input()) c = list(input()) schw = 0 schr = n-1 ans = 0 while schw < schr: while c[schw] != 'W' and schw < n-1: schw += 1 while c[schr] != 'R' and schr > 0: schr -= 1 ans += 1 c[schw] = 'R' c[schr] = 'W' print(ans - 1)
p02597
s408523599
Accepted
N=int(input()) S=input() c=0 d=0 for i in range(N): if S[i]=="R": c+=1 for j in range(c): if S[j]=="W": d+=1 for k in range(c,N): if S[k]=="R": d+=1 if d%2==0: print(int(d/2)) else: print(int((d+1)/2))
p02597
s405849744
Accepted
n = int(input()) s = input() white = 0 red = 0 white_ren = 0 red_ren = 0 for i in range(n): if s[i] == "W": white += 1 else: red += 1 for i in range(red): if s[i] == "R": red -= 1 for i in range(white): if s[-i - 1] == "W": white -= 1 remain = white + red ans1 = min(red, white) remain -= 2 * ans1 print(remain + ans1)
p02597
s603800665
Accepted
N=int(input()) c=list(input()) R=c.count('R') W=0 ans=max(R,W) for i in range(N): if c[i]=='W': W+=1 else: R-=1 ans=min(ans,max(W,R)) print(ans)
p02597
s541897960
Accepted
N = int(input()) stone = str(input()) num_red = stone.count('R') cnt = 0 for i in range(num_red): if stone[i] == 'W': cnt += 1 print(cnt)
p02597
s041950004
Accepted
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n = ni() c = ns() aw = c.count('W') ans = min(n-aw,aw) w = 0 for i in range(n): if c[i] == 'W': w+=1 rw = aw-w rr = n-i-1-rw ans = min(ans, max(w,rr)) print(ans)
p02597
s766871467
Accepted
N = int(input()) c = input() rnum = 0 okrnum = 0 wnum = 0 for i in range(N): if(c[i]=="R"): rnum += 1 else: wnum += 1 if(rnum == 0 or wnum == 0): print(0) else: for i in range(rnum): if(c[i]=="R"): okrnum += 1 #print(rnum , wnum, okrnum) #print("ans =",rnum-okrnum) print(rnum - okrnum)
p02597
s572125074
Accepted
N = int(input()) c = list(input()) rr = [] ww = [] for i in range(N): if (c[i] == "R"): rr.append(i) if (c[i] == "W"): ww.append(i) wl = len(ww) rl = len(rr) l = min([wl,rl]) ans = 0 for i in range(l): if (ww[i] < rr[-i-1]): ans += 1 print(ans)
p02597
s174380277
Accepted
N = int(input()) WR = input() i = 0 j = len(WR) - 1 num = 0 while(i < j): if(WR[j] == "R"): if(WR[i] == "W"): num += 1 i += 1 j -= 1 else: i += 1 else: j -= 1 print(num)
p02597
s427623720
Accepted
import collections N = int(input()) stones = list(input()) #print(stones) c = collections.Counter(stones) r_s = collections.Counter(stones[:c['R']]) print(c['R']-r_s['R'])
p02597
s434689601
Accepted
N = int(input()) S = list(input()) i, j = 0, N - 1 res = 0 while i < j: while i < j and S[i] == 'R': i += 1 while i < j and S[j] == 'W': j -= 1 if i < j and S[i] == 'W' and S[j] == 'R': S[i], S[j] = S[j], S[i] i += 1 j -= 1 res += 1 continue print(res)
p02597
s434624592
Accepted
N = int(input()) A = input() a = A.count("R") b = A.count("W", 0, a) print(b)
p02597
s368036770
Accepted
from collections import deque N = int(input()) c = input() rd = deque([i for i, x in enumerate(c) if x == "R"]) wd = deque([i for i, x in enumerate(c) if x == "W"]) if(len(rd) == 0 or len(wd) == 0): print(0) exit() count = 0 for i in range(len(c)): if(not(wd[0] < rd[-1])): break rd.pop() wd.popleft() count += 1 if(len(rd) == 0 or len(wd) == 0): break print(count)
p02597
s590249025
Accepted
import math from decimal import * n = int(input()) c = str(input()) w = c.count('W') c = c[::-1] ans= 0 for i in range(w): if(c[i]!= 'W'): ans+=1 print(ans)
p02597
s209697053
Accepted
N = int(input()) stones = input() red = stones.count("R") ans = 0 for i in range(red,N): if stones[i] == "R": ans+=1 print(ans)
p02597
s891492556
Accepted
n=int(input()) c=input() a=c.count("R") l=[c[i] for i in range(a)] print(l.count("W"))
p02597
s952539692
Accepted
n=int(input()) c=input() w=0 for i in range(n): if c[i]=="W": w+=1 w1=0 t=100 s=0 for i in range(n+1): r=n-i-(w-w1) if abs(w1-r)==1 and t!=0: t=1 s=w1 if w1==r: t=0 s=w1 if i!=n: if c[i]=="W": w1+=1 print(s+t)
p02597
s179029170
Accepted
n = int(input()) c=str(input()) if c.count("W") >= c.count("R"): C_W =c[:-c.count("W")] print(C_W.count("W")) else: C_R =c[c.count("R"):] print(C_R.count("R"))
p02597
s708283125
Accepted
N = int(input()) C = input() a, b = 0, 0 a = C.count('R') ans = a for i in range(N): if C[i] == 'R': a -= 1 else: b += 1 now = max(a, b) ans = min(ans, now) print(ans)
p02597
s076517673
Accepted
n=int(input()) s=list(input()) i=0 j=n-1 ans=0 while i<j: while s[i]!="W" and i<j: i+=1 while s[j]!="R" and i<j: j-=1 if i<j: ans+=1 i+=1 j-=1 print(ans)
p02597
s675142344
Accepted
n=int(input()) s=input() r = s.count('R') ans=0 for i in range(r): if s[i]=='W': ans+=1 print(ans)
p02597
s170156511
Accepted
n = int(input()) c = list(input()) w, r = [0] * (n + 1), [0] * (n + 1) for i in range(n): if c[i] == "W": w[i + 1] = w[i] + 1 r[i + 1] = r[i] else: w[i + 1] = w[i] r[i + 1] = r[i] + 1 ans = min(w[n], r[n]) for i in range(1, n): x = w[i] - w[0] y = r[n] - r[i] ans = min(ans, x + abs(x - y)) print(ans)
p02597
s467487308
Accepted
n = int(input()) c = input() cnt = [0 for _ in range(n)] red = 0 for i in range(n): if c[i] == 'R': red += 1 cnt[i] = red print(red - cnt[red-1])
p02597
s246757665
Accepted
from collections import Counter n = int(input()) c = list(input()) num = Counter(c) r = num["R"] ans = ["R"]*r + ["W"]*(n-r) cnt = 0 for i in range(n): if c[i] != ans[i]: cnt += 1 print(cnt//2)
p02597
s989705098
Accepted
n = int(input()) c = str(input()) l = 0 r = n-1 answer = 0 while l < r: if c[l] == "W" and c[r] == "R": answer += 1 l += 1 r -= 1 elif c[l] == "W" and c[r] == "W": r -= 1 elif c[l] == "R" and c[r] == "R": l += 1 else: l += 1 r -= 1 print(answer)
p02597
s769029568
Accepted
import sys N = int(input()) word = input() if word.count('W') == N: print(0) sys.exit() num_R = word.count('R') num_W,min_count= 0,float('inf') for i in range(N): if word[i] == 'W': num_W += 1 else: num_R -= 1 min_count = min(min_count,max(num_W,num_R)) print(min_count)
p02597
s495666310
Accepted
def main(): N = int(input()) S = input() r = S.count("R") ans = S[r:].count("R") print(ans) if __name__ == '__main__': import sys sys.setrecursionlimit(10000) main()
p02597
s806380251
Accepted
def d1(x): if x == "R": return 0 else: return 1 N = int(input()) C = list(map(d1,input())) w = sum(C) r = N - w if sum(C[:r]) < w: print(sum(C[:r])) else: print(w)
p02597
s363488950
Accepted
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) n = I() mychr = input().rstrip() result = float('inf') red = 0 for i in mychr: if i == "R": red += 1 R = 0 W = 0 for index, i in enumerate(mychr): if i == "R": R+=1 else: W+=1 temp = max(W,red-R) result = min(result, temp) if W != n: print(result) else: print(0)
p02597
s066902418
Accepted
from itertools import accumulate n = int(input()) s = input() left_w = [0] for c in s: if c == 'W': left_w.append(1) else: left_w.append(0) left_w = list(accumulate(left_w)) right_r = [0] for c in s[::-1]: if c == 'R': right_r.append(1) else: right_r.append(0) right_r = list(accumulate(right_r)) right_r.reverse() print(min(map(max, zip(left_w, right_r))))
p02597
s179335702
Accepted
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)
p02597
s545720046
Accepted
n=int(input()) s=input() red=s.count('R') white=s.count('W') mn=min(red,white) ct=0 for i in range (red): if s[i]=='W': ct+=1 mn=min(mn,ct) print(mn)
p02597
s029509914
Accepted
import sys sys.setrecursionlimit(10**6) n = int(input()) C = input() C = list(C) d = {0:0} tot = 0 for i,c in enumerate(C): if c == 'R': tot += 1 d[i+1] = tot ans = tot-d[tot] print(ans)
p02597
s313042509
Accepted
n=int(input()) c=input() a=c.count("R") print(a-(c[:a].count("R")))
p02597
s268069973
Accepted
n = int(input()) rw = input() red = rw.count('R') ans = rw[:red].count('W') print(ans)
p02597
s444997641
Accepted
N=int(input()) stone= list(input()) white_number=sum(x=='W' for x in stone) stone.reverse() ans=0 for i in range(white_number): if stone[i] != 'W': ans+=1 print(ans)
p02597
s083502900
Accepted
import sys readline = sys.stdin.readline N = int(readline()) C = readline().rstrip() ans = 0 left = 0 right = N - 1 while left < right: # Wを見つけるまで左からカーソル移動 if C[left] == "R": left += 1 continue while left < right and C[right] == "W": right -= 1 if left == right: break ans += 1 left += 1 right -= 1 print(ans)
p02597
s905186781
Accepted
a=int(input()) v=input() b=v.count("R") c=0 for i in v[:b]: if i!="R": c+=1 print(c)
p02597
s638404069
Accepted
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n = ini() s = list(ins()) t = sorted(s) ans = 0 for i in range(n): if t[i] != "R": break if s[i] != t[i]: ans += 1 print(ans)
p02597
s928607087
Accepted
n = int(input()) stones = input() left = 0 right = n-1 ans = 0 while True: while left < n and stones[left] == 'R': left += 1 while right > 0 and stones[right] == 'W': right -= 1 if left < n and right > 0 and left < right: left += 1 right -= 1 ans += 1 else: break print(ans)
p02597
s784518332
Accepted
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)
p02597
s233124367
Accepted
n=int(input()) c=list(input()) num=c.count("R") ans=num for i in range(num): if c[i]=="R": ans-=1 print(ans)
p02597
s889860785
Accepted
import sys input = sys.stdin.readline N = int(input()) S = list(input())[: -1] r = S.count("R") res = 0 for i in range(r): if S[i] != "R": res += 1 print(res)
p02597
s951795985
Accepted
from math import floor, ceil N = int(input()) WHITE = 0 RED = 1 str = list(map(str, list(input()))) r = [] w = [] for i in range(N): w.append(i) if str[i] == "W" else r.append(i) str[i] = WHITE if str[i] == "W" else RED r.reverse() max_count = min(len(r), len(w)) count = 0 for i in range(max_count): if r[i] - w[i] > 0: count += 1 print(count)
p02597
s479476941
Accepted
N = int(input()) c = list(input()) num_r = 0 for ci in c: if ci == 'R': num_r += 1 ans = 0 if num_r != N and num_r != 0: for i in range(num_r): if c[i] == 'W': ans += 1 print(ans)
p02597
s356938756
Accepted
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N = int(input()) C = input() left = 0 right = N-1 count = 0 while left < right: if C[left] == 'W' and C[right] == 'R': count += 1 left += 1 right -= 1 if C[left] == 'R': left += 1 if C[right] == 'W': right -= 1 print(count)
p02597
s930611394
Accepted
N=int(input()) S=input() ans=0 i=0 j=N-1 while i<j: while i<N: if S[i]=='W': break else: i+=1 while j>0: if S[j]=='R': break else: j-=1 if i<j: ans+=1 i+=1 j-=1 print(ans)
p02597
s214495725
Accepted
n = int(input()) s=input() isi=[] for i in s: isi.append(i) R_kosuu=isi.count("R") irekaekosuu=0 for i in range(R_kosuu): if isi[i]=="W": irekaekosuu+=1 print(irekaekosuu)
p02597
s620719294
Accepted
n = int(input()) c = list(input()) r = c.count('R') wr = c[:r].count('W') print(wr)
p02597
s175768889
Accepted
# -*- coding: utf-8 -*- # 標準入力を取得 N = int(input()) c = input() # 求解処理 w = 0 r = c.count("R") ans = max(w, r) for n in range(N): c_n = c[n] if c_n == "W": w += 1 else: r -= 1 ans = min(ans, max(w, r)) # 結果出力 print(ans)
p02597
s508393758
Accepted
N = int(input()) c = input() w = 0 w_left = [None]*(N+1) w_left[0] = 0 for i in range(N): if c[i] == 'W': w += 1 w_left[i+1] = w r = 0 r_right = [None]*(N+1) r_right[N] = 0 for i in reversed(range(N)): if c[i] == 'R': r += 1 r_right[i] = r def cost(i): return max(w_left[i], r_right[i]) best = min(cost(i) for i in range(N+1)) print(best)
p02597
s326623162
Accepted
N = int(input()) list=[] list = (str(input())) cnt = 0 R = 0 W = 0 ans = 0 for i in range (N): if list[i] == "R": R += 1 W = N-R cnt = min(R, W) if R > W: for i in range(0,cnt): if list[N-i-1]=="R": ans +=1 if R<=W: for j in range(0,cnt): if list[j] == "W": ans +=1 print(ans)
p02597
s150602163
Accepted
import sys input = lambda: sys.stdin.readline().rstrip('\r\n') N = int(input()) S = input() Rs = S.count('R') Ws = N - Rs if Rs == 0 or Ws == 0: print(0) sys.exit() C = list(S) i = 0 j = N-1 ops = 0 while i < j: while i < N and C[i] == 'R': i += 1 while j >= 0 and C[j] == 'W': j -= 1 if i < j: C[i], C[j] = C[j], C[i] ops += 1 print(ops)
p02597
s653827724
Accepted
n=int(input()) c=list(input()) all_r=c.count('R') l_w=0 l_r=0 ans=0 for i in range(n): if l_w==all_r-l_r: ans=l_w break if c[i]=='W': l_w+=1 else: l_r+=1 print(ans)