problem_id
stringclasses
100 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
6
806
p02597
s000466460
Accepted
import sys N = int(input()) c = list(input()) #print(c) myr_cnt = c.count('R') if myr_cnt == 0: print(0) sys.exit() #print(myr_cnt) myw_cnt = 0 for i in range(myr_cnt): if c[i] == 'W': myw_cnt += 1 print(myw_cnt)
p02597
s905122891
Accepted
N = int(input()) c_str = input() R_cnt = c_str.count('R') tmp_cnt = c_str[:R_cnt].count('R') print(R_cnt - tmp_cnt)
p02597
s342537420
Accepted
from collections import deque N = int(input()) c = list(str(input())) dw = deque() dr = deque() for i, c in enumerate(c, 1): if c == 'W': dw.append(i) else: dr.appendleft(i) ans = 0 while dw and dr: w = dw.popleft() r = dr.popleft() if w < r: ans += 1 else: break print(ans)
p02597
s958469311
Accepted
#d n=int(input()) c=input() rr=c.count('R') ans=0 for i in range(rr): if c[i]=='W': ans+=1 print(ans)
p02597
s285657803
Accepted
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"))
p02597
s781164021
Accepted
n = int(input()) clist = input() rs = clist.count("R") ws = clist.count("W") sort_rs = rs - clist[0:rs].count("R") ans = rs if ws < ans: ans = ws if sort_rs < ans: ans = sort_rs print(ans)
p02597
s150844950
Accepted
n=int(input()) c=input() a=[] for i in range(n): if(c[i]=='R'): a.append(0) else: a.append(1) zero=0 one=0 for i in range(n): if(a[i]==0): zero+=1 ans=[zero] for i in range(n): if(a[i]==0): zero-=1 else: one+=1 #print(zero,one) ans.append(max(zero,one)) print(min(ans))
p02597
s983191350
Accepted
n = int(input()) color = list(input()) left = 0 right = len(color) - 1 ans = 0 while left<right: if(color[left]=='W' and color[right]=='R'): ans += 1 left += 1 right -=1 if color[left] == 'R': left+=1 if color[right] == 'W': right -=1 print(ans)
p02597
s844737538
Accepted
n = int(input()) s = input() r = 0 w = 0 for i in range(n): if(s[i] == "R"): r += 1 else: w += 1 ngr = 0 ngw = 0 for i in range(n): if(i < r and s[i] == 'W'): ngw += 1 if(i >= r and s[i] == 'R'): ngr += 1 print(min(ngw, ngr) + abs(ngw-ngr))
p02597
s071369948
Accepted
from sys import stdin input = stdin.readline n = int(input()) s = input() i, j = 0, n - 1 ans = 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: ans += 1 i += 1 j -= 1 print(ans)
p02597
s170647057
Accepted
n = int(input()) C = list(input()) if "R" not in C: print(0) exit() W = C.count("W") R = C.count("R") w = 0 r = R ans = float('inf') for c in C: if c == "W": w += 1 else: r -= 1 ans = min(ans, max(w, r)) print(ans)
p02597
s669921084
Accepted
N=int(input()) c=input() count=0 if 'WR' in c: x=c.count('R') y=c.count('R',0,x) count=x-y print(count)
p02597
s986478641
Accepted
n = int(input()) c = input() count = c.count('R') ans = 0 for i in range(n): if c[i] == 'R' and i >= count: ans += 1 print(ans)
p02597
s821462878
Accepted
n = int(input()) stone = input() r = stone.count("R") print(stone.count("W", 0, r))
p02597
s395076607
Accepted
from collections import Counter N = int(input()) C = list(input()) C1 = Counter(C) ans = 0 for i in range(C1["R"]): if C[i] == "W": ans += 1 print(ans)
p02597
s805434547
Accepted
N=int(input()) c=input() print(c[:c.count('R')].count('W'))
p02597
s891244538
Accepted
n=int(input()) p = input() w, r = 0,0 for i in range(n): if p[i] == "W": w += 1 else: r += 1 ans = n noww , nowr = 0,0 for i in range(n+1): ans = min ( ans , max(noww , r - nowr)) if i < n and p[i] == "W": noww += 1 else: nowr += 1 print(ans)
p02597
s441529246
Accepted
a = int(input()) l=list(input()) b = l.count("R") s = 0 for i in range(b): if l[i]=="W": s = s+1 print(s)
p02597
s622580289
Accepted
n = int(input()) s = input() count_r = 0 for i in range(n): if s[i] == "R": count_r += 1 ans = 0 for i in range(count_r): if s[i] == "W": ans += 1 print(ans)
p02597
s290054013
Accepted
N,c = open(0).read().split() N = int(N) white_right = 0 red = 0 red_left = 0 for x in c: if x == 'R': red_left += 1 else: break c_altered = c[red_left:] l = len(c_altered) for x in c_altered: if x == 'R': red += 1 white_right = 0 else: white_right += 1 c_altered = c_altered[:l-white_right] l = len(c_altered) ans1 = red ans2 = c_altered[:red].count('W') print(min(ans1,ans2))
p02597
s942538631
Accepted
n = int(input()) S = input() r = S.count('R') w = len(S)-r if r == 0 or w == 0: print(0) exit() ans = 0 for i in range(len(S)): if S[i] == "R": r -= 1 else: r -= 1 w -= 1 ans += 1 if r == 0 or w == 0: break print(ans+r)
p02597
s697195239
Accepted
n = int(input()) c = input() c = list(c) r = 0 w = 0 for i in range(n): if c[i] == 'R': r += 1 else: w += 1 ans = min(r,w) t = 0 v = 0 for i in range(ans): if c[i] == 'R': t -= 1 for i in range(ans): if c[n-i-1] == 'W': v -= 1 if r <= w: ans = ans + t else: ans = ans + v print(ans)
p02597
s709431216
Accepted
n = int(input()) c = input() r = c.count('R') print(c[:r].count('W'))
p02597
s181956805
Accepted
N = int(input()) C = input() l, r = 0, N - 1 ans = 0 while l < r: if C[l] == 'R': l += 1 elif C[r] == 'W': r -= 1 else: ans += 1 l += 1 r -= 1 print(ans)
p02597
s367789101
Accepted
n = int(input()) s = input() num = s.count("R") L = s[:num] ans = L.count("W") print(ans)
p02597
s965160060
Accepted
n=int(input()) s=input() i,j=0,len(s)-1 ans=0 while(i<=j): if(s[j]=='W'): j-=1 elif(s[i]=='R'): i+=1 else: ans+=1 i+=1 j-=1 print(ans)
p02597
s770650582
Accepted
import collections n = int(input()) s = input() count = collections.Counter(s) ans = 0 if "R" in count.keys(): if count["R"] != n: r_count = collections.Counter(s[:count["R"]]) if r_count["R"] == 0: ans = count["R"] else: ans = r_count["W"] print(ans)
p02597
s428409670
Accepted
n = int(input()) s = input() r=s.count('R') ans=r for i in range(r): if s[i]=='R': ans-=1 print(ans)
p02597
s556280427
Accepted
N=int(input()) String=input().replace("W","1").replace("R","2") c=[0]*N for i in range (N): c[i]=int(String[i]) s=sorted(c) import bisect a=bisect.bisect_right(s,1) cnt=0 for j in range(N-a): if c[j]==1: cnt+=1 print(cnt)
p02597
s736178555
Accepted
N = int(input()) C = list(input()) C_ = sorted(C) wr = rw = 0 for i in range(len(C_)): if C[i] != C_[i]: if C[i] == 'R' and C_[i] == 'W': rw += 1 else: wr += 1 print(max(wr, rw))
p02597
s084509281
Accepted
N = int(input()) C = input() l = 0 while l < N and C[l] == "R": l += 1 r = N-1 while r > 0 and C[r] == "W": r -= 1 ans = 0 while l < r: if C[l] == "W" and C[r] == "R": ans += 1 l += 1 r -= 1 elif C[l] == "W": r -= 1 elif C[r] == "R": l += 1 else: l += 1 r -= 1 print(ans)
p02597
s920061566
Accepted
N=int(input()) S=input() rn,wn=0,0 for i in range(len(S)): if S[i]=='R': rn+=1 else: wn+=1 winr,rinw=0,0 for i in range(rn): if S[i]=='W': winr+=1 for i in range(rn,rn+wn): if S[i]=='R': rinw+=1 #print(rn,wn,rinw,winr) print(max(winr,rinw))
p02597
s219715224
Accepted
import sys input = sys.stdin.readline N=int(input())+2 C="R"+input().strip()+"W" W=[0]*(N+1) R=[0]*(N+1) for i in range(N): if C[i]=="W": W[i]=W[i-1]+1 else: W[i]=W[i-1] for i in range(N-1,-1,-1): if C[i]=="R": R[i]=R[i+1]+1 else: R[i]=R[i+1] ANS=1<<30 for i in range(N-1): ANS=min(ANS,max(W[i],R[i+1])) print(ANS)
p02597
s135582402
Accepted
def main(): input() # n stones = input() white_counter = [] white_stones = 0 red_stones = 0 for color in stones: if color == 'W': white_stones += 1 else: red_stones += 1 white_counter.append(white_stones) if red_stones == 0: print(0) else: print(white_counter[red_stones - 1]) if __name__ == '__main__': main()
p02597
s729785507
Accepted
n = int(input()) c = input() lists = list(c) cnt = 0 for i in range(len(lists)): if lists[i] == "R": cnt += 1 change = 0 for i in range(cnt): if lists[i] == "W": change += 1 print(change)
p02597
s352739079
Accepted
N = int(input()) S = input() r = S.count('R') w = S.count('W') if r == N or r == 0: print(0) exit() a = S[:r].count('W') print(a)
p02597
s051729062
Accepted
def solve(string): _, c = string.split() r = c.count("R") return str(c[:r].count("W")) if __name__ == '__main__': import sys print(solve(sys.stdin.read().strip()))
p02597
s570879982
Accepted
# coding: utf-8 N = int(input()) C = list(input()) R_cnt = 0 for i in range(N): if C[i] == "R": R_cnt += 1 ans = 0 for i in range(R_cnt): if C[i] == "W": ans += 1 print(ans)
p02597
s788639137
Accepted
def main(): n = int(input()) C = input() r = C.count('R') print(C[:r].count('W')) if __name__ == '__main__': main()
p02597
s280583867
Accepted
n = int(input()) c = input() w = 0 r = c.count('R') ans = r for k in range(n): if c[k] == 'W': w += 1 elif c[k] == 'R': r -= 1 cnt = max(w, r) if ans > cnt: ans = cnt print(ans)
p02597
s588498770
Accepted
N = int(input()) c=list(input()) countR = c.count('R') countW2 = 0 countR2 = 0 for i in range(countR): if c[i]=="W": countW2 += 1 print(countW2)
p02597
s286603621
Accepted
# D from collections import Counter n = int(input()) c = list(input()) d = Counter(c) # print(d) # print(d["R"]) e=Counter(c[:d["R"]]) # print(e["R"]) print(d["R"]-e["R"])
p02597
s113930493
Accepted
n=int(input()) c=input() d=c.count("R") e=c[:d].count("R") print(d-e)
p02597
s880185115
Accepted
n = int(input()) c = input() r_cnt = 0 for i in range(n): if c[i] == 'R': r_cnt += 1 r_cnt_2 = 0 for i in range(r_cnt): if c[i] == 'R': r_cnt_2 += 1 if r_cnt == n: print(0) else: print(r_cnt - r_cnt_2)
p02597
s489698900
Accepted
n=int(input()) s=input() w,r=0,0 for i in range(n): if s[i]=='W': w+=1 else : r+=1 c=0 for i in range(r): if s[i]=='R': c+=1 print(r-c)
p02597
s460660991
Accepted
n=int(input()) c=input() w_num=c.count("W") r_num=c.count("R") now_r_num=0 for i in range(r_num): if c[i]=="R": now_r_num+=1 print(r_num-now_r_num)
p02597
s096206347
Accepted
n=int(input()) c=str(input()) c=list(c) t1=[0]*n t2=[0]*n for i in range(len(c)): if c[i]=="R": t1[i]=1 else: t2[i]=1 if sum(t1)==len(c) or sum(t2)==len(c): print(0) else: ans=0 t=sum(t1) for i in range(n): if t2[i]==1: ans=ans+1 t=t-1 if t1[i]==1: t=t-1 if t==0: break print(ans)
p02597
s900910083
Accepted
n=int(input()) a=input() lista=list(a) w=lista.count("W") r=lista.count("R") count=0 for i in range(r): if lista[i]=="W": count+=1 print(count)
p02597
s527422755
Accepted
n = int(input()) A = list(input()) r = A.count("R") ans = A[:r].count("W") print(ans)
p02597
s189288231
Accepted
N = int(input()) C = list(input()) r = C.count("R") cnt = 0 for i in range(r): if C[i] == "W": cnt += 1 print(cnt)
p02597
s349727698
Accepted
n=int(input()) c=input() r=c.count("R") r_1=c[:r].count("R") ans=r-r_1 print(ans)
p02597
s474708086
Accepted
from collections import Counter N = int(input()) C = input() C_cntr = Counter(C) all_R_cnt = 0 all_W_cnt = 0 R_W_cnt = 0 for i in range(N): if C[i] == "W": all_R_cnt += 1 elif C[i] == "R": all_W_cnt += 1 if i < C_cntr.get("R", 0) and C[i] == "W": R_W_cnt += 1 print(min(all_R_cnt, all_W_cnt, R_W_cnt))
p02597
s964042240
Accepted
n = int(input()) s = input() nw = len([i for i in s if(i == 'W')]) ns = n - nw i = 0 j = n-1 c = 0 while(i < j): if(s[i] == 'W' and s[j] == 'R'): c += 1 i += 1 j -= 1 elif s[i] == 'R': i += 1 elif s[j] == 'W': j -= 1 print(min([c,nw, ns]))
p02597
s846191597
Accepted
import heapq N = int(input()) c = input() w = [i for i in range(N) if c[i]=='W'] r = [-i for i in range(N) if c[i]=='R'] heapq.heapify(w) heapq.heapify(r) ans = 0 for i in range(N): if w and r: a = heapq.heappop(w) b = -heapq.heappop(r) if a-b==1: break else: heapq.heappush(w,b) heapq.heappush(r,-a) ans += 1 print(ans)
p02597
s514172678
Accepted
n = int(input()) c = list(input()) ans = 0 for i in range(c.count("R")): if c[i] == "W": ans += 1 print(ans)
p02597
s309667261
Accepted
n=int(input()) c=input() c=list(c) a=sorted(c) countw=0 countr=0 for i in range(n): if c[i]=='R' and a[i]=='W': countw+=1 elif c[i]=='W' and a[i]=='R': countr+=1 ansmin=min(countw,countr) ansmax=max(countw,countr) print(ansmin+abs(ansmin-ansmax))
p02597
s820301985
Accepted
import random def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) #a = list(map(int, input().split())) n=int(input()) s=input() l=0 r=n-1 c=0 while(l<r): if s[l]=='R': l+=1 if s[r]=='W': r-=1 if s[l]=='W' and s[r]=='R': c+=1 l+=1 r-=1 print(c)
p02597
s318616024
Accepted
N = int(input()) c = input() r = c.count("R") w = c.count("W") a = "R"*r+"W"*w ans = 0 for i in range(N): if(c[i] != a[i]): if(c[i] == "W" and a[i] == "R"): ans += 1 print(ans)
p02597
s177403350
Accepted
n = int(input()) c = input() t = c.count('R') ans = 0 for i in range(n): if c[i] == 'R' and t <= i: ans += 1 print(ans)
p02597
s102841160
Accepted
n = int(input()) c = input() left = 0 right = n - 1 cnt = 0 while left < right: while left < right: if c[left] == "W": break; left += 1 while left < right: if c[right] == "R": break; right -= 1 if left < right: cnt += 1 left += 1 right -= 1 # print(cnt)
p02597
s115151941
Accepted
n = int(input()) s = input() res = 0 tem = s.find('WR') if tem == -1: print(res) else: i, j = 0, len(s)-1 while i<j: while i < j and s[i] != 'W': i+=1 while i < j and s[j] != 'R':j -= 1 if s[i] == 'W' and s[j] == 'R': res += 1 i += 1 j -= 1 print(res)
p02597
s247375116
Accepted
n = int(input()) c = input() left, right = 0, n - 1 cnt = 0 while left <= right: while left < n and c[left] == 'R': left += 1 while right > -1 and c[right] == 'W': right -= 1 if left == n or right == -1 or left >= right: break left += 1 right -= 1 cnt += 1 print(cnt)
p02597
s421689566
Accepted
n = int(input()) c = input() print(c[:c.count("R")].count("W"))
p02597
s169190651
Accepted
n=int(input()) c=input() from collections import Counter w=Counter(c)["W"] r=0 ans=w for i in range(n-1,-1,-1): if c[i]=="W": w-=1 else: r+=1 ans=min(ans,max(r,w)) print(ans)
p02597
s870675097
Accepted
#!/usr/bin/env python3 n = int(input()) s = input() l = 0 r = n - 1 cnt = 0 while l < r: if s[l] == "R": l += 1 elif s[r] == "W": r -= 1 else: cnt += 1 l += 1 r -= 1 print(cnt)
p02597
s741110974
Accepted
n = int(input()) s = input() count = 0 for i in range(n): if(s[i] == "R"): count += 1 count2 = 0 for i in range(count): if(s[i] == "W"): count2 += 1 print(count2)
p02597
s207023987
Accepted
N = int(input()) C = list(input()) RC = C.count("R") WC = C.count("W") print(C[:RC].count("W"))
p02597
s502838958
Accepted
n = int(input()) m = str(input()) red = m.count('R') con = 0; for i in range(red): if m[i] == 'W': con += 1 print(con);
p02597
s591921426
Accepted
import sys input = sys.stdin.readline N = int(input()) c = input().rstrip() white = [0] * N red = [0] * N if c[0] == 'W': white[0] = 1 for i in range(1, N): white[i] = white[i-1] if c[i] == 'W': white[i] += 1 for i in range(1, N)[::-1]: red[i-1] = red[i] if c[i] == 'R': red[i-1] += 1 if white[-1] == 0 or red[0] == 0: print(0) exit() for i in range(N): if white[i] == red[i]: print(white[i]) exit()
p02597
s074164130
Accepted
def I(): return int(input()) def LI(): return list(map(int,input().split())) def MI(): return map(int,input().split()) def LLI(n): return [list(map(int, input().split())) for _ in range(n)] n = I() c = list(input()) r = c.count('R') print(c[:r].count("W"))
p02597
s269260337
Accepted
N=int(input()) c=input() a=0 b=0 for i in range(N): if c[i]=='R': a+=1 ans=max(a,b) 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
s090739735
Accepted
n = int(input()) c = list(input()) r = c.count('R') w = c.count('W') ans = 0 for i in range(r): if c[i] == 'R': pass elif c[i] == 'W': ans += 1 print(ans)
p02597
s680823879
Accepted
# -*- coding: utf-8 -*- n = int(input()) s = list(input()) if s.count("W") == 0: print(0) exit() print(s[:s.count('R')].count("W"))
p02597
s698551500
Accepted
n = int(input()) C = [c for c in input()] ans = 0 l,r = 0, n-1 while(l < r): while(C[l] == 'R'): l += 1 if (n == l): break while(C[r] == 'W' or -1 == r): r -= 1 if (-1 == r): break if (l < r): ans += 1 l += 1 r -= 1 print(ans)
p02597
s024306964
Accepted
n = int(input()) C = list(input()) l, r, c = 0, n-1, 0 while l < r: if C[l] == 'W' and C[r] == 'R': l += 1 r -= 1 c += 1 elif C[l] != 'W': l += 1 elif C[r] != 'R': r -= 1 print(c)
p02597
s627221530
Accepted
n = int(input()) c = input() print(c[:c.count('R')].count('W'))
p02597
s083126379
Accepted
n = int(input()) c = input() cnt = 0 r = c.count('R') r_s = c[:r].count('R') print(r - r_s)
p02597
s572872866
Accepted
from collections import Counter n = int(input()) C = input() c = Counter(C) numR = 0 for i in range(c['R']): if C[i] == 'R': numR += 1 print(c['R']-numR)
p02597
s756810502
Accepted
def main(): N = int(input()) C = input() l, r = 0, N - 1 c = 0 while True: while l < r and C[l] == 'R': l += 1 while l < r and C[r] == 'W': r -= 1 if l >= r: break c += 1 l += 1 r -= 1 return c print(main())
p02597
s867660625
Accepted
n = int(input()) k = input() stone = list(k) w = 0 r = 0 for i in range(n): if stone[i] == 'R': r += 1 else: w += 1 ans = 0 w_s = 0 r_s = 0 for i in range(n): if i <= r-1 and stone[i] == 'W': w_s += 1 elif i > r-1 and stone[i] == 'R': r_s += 1 ans = max(w_s, r_s) print(ans)
p02597
s971476576
Accepted
N = int(input()) C = list(input()) RtoW = sum(map(lambda x: x=="R",C)) WtoR = 0 ans = RtoW for i in range(N): if C[i] == "R": RtoW -= 1 else: WtoR += 1 ans = min(ans,max(RtoW,WtoR)) print(ans)
p02597
s927737738
Accepted
n = int(input()) c = list(input()) sum_r, sum_w = [0], [0] s1, s2 = 0, 0 for v in c: if v == 'R': s1 += 1 else: s2 += 1 sum_r.append(s1) sum_w.append(s2) res = float('inf') for i in range(n+1): res = min(res, max(sum_w[i], s1 - sum_r[i])) print(res)
p02597
s088306369
Accepted
n=input() c=input() print(c[:c.count("R")].count("W"))
p02597
s262949587
Accepted
N = int(input()) C = input() cnt = 0 R = C.count('R') for i in range(R): if C[i] == 'R': cnt += 1 print(R - cnt)
p02597
s022000069
Accepted
N=int(input()) c=list(input()) cnt=0 res=10**30 rcum=[0]*(N+1) wcum=[0]*(N+1) for i in range(N): rcum[i+1]=rcum[i]+(c[i]=='R') wcum[i+1]=wcum[i]+(c[i]=='W') for i in range(N+1): a=wcum[i]+(rcum[N]-rcum[i]) res=min(res,a) for i in range(N+1): b=max(wcum[i],(rcum[N]-rcum[i])) res=min(res,b) print(res)
p02597
s485356992
Accepted
n = int(input()) a = list(input()) #print(a) w = a.count("W") r = a.count("R") aa = a[:r] #print(aa) r2 = aa.count("R") print(r-r2)
p02597
s815014414
Accepted
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)]))
p02597
s234446232
Accepted
n = int(input()) c = list(input()) d = sorted(c) count = 0 for i in range(n): if c[i] == 'W' and d[i] == 'R': count+=1 print(count)
p02597
s846735176
Accepted
n=int(input()) c=input() c1=c.count("R") c2=c[:c1].count("W") print(c2)
p02597
s100267821
Accepted
n = int(input()) string = input() Rcount = string.count('R') fixRcount = string.count('R', Rcount, n) print(fixRcount)
p02597
s135279237
Accepted
n = int(input()) C = input() len_r, len_w = 0, 0 for c in C: if c == 'R': len_r += 1 else: len_w += 1 c2 = 'R'*len_r + 'W'*len_w cnt = 0 for a, b in zip(C, c2): if a != b: cnt += 1 print(cnt//2)
p02597
s528464378
Accepted
N = int(input()) C = input() W = 0 #仕切りより左側の白い石の個数 R = C.count('R') #仕切りより右側の赤い石の個数 ans = max(W, R) for i in range(N): if C[i] == 'W': #仕切りの左側に'W'が移動する W += 1 else: #仕切りの左側に'R'が移動する R -= 1 ans = min(ans, max(W, R)) print(ans)
p02597
s306166819
Accepted
import sys input = sys.stdin.readline N = int(input()) c = input() nR = c.count('R') #nW = c.count('W') lnR = c[:nR].count('R') #lnW = c[:nW].count('W') print(nR-lnR)
p02597
s931986531
Accepted
N = int(input()) c = input() l = 0 r = N-1 cnt = 0 while(l<r): if c[l] == "W" and c[r] == "R": cnt += 1 l += 1 r -= 1 elif c[l] == "R": l += 1 elif c[r] == "W": r -= 1 print(cnt)
p02597
s056486226
Accepted
N = int(input()) c = list(input()) from collections import Counter dic = Counter(c) left = c[:dic["R"]] print(left.count("W"))
p02597
s087044996
Accepted
N = int(input()) S = input() ans = 0 d = {"RW": 0, "WR": 0} for i in range(N): if S[i] == "R": d["RW"] += 1 ans = d["RW"] for i in range(N): if S[i] == "R": d["RW"] -= 1 else: d["WR"] += 1 ans = min(ans, max(d["RW"], d["WR"])) print(ans)
p02597
s083346612
Accepted
N=int(input()) c=input() C=[] for i in range(N): C.append(c[i]) num= C.count("W") CC=C[(N-num):] numnum=CC.count("W") print(num-numnum)
p02597
s829511358
Accepted
n = int(input()) c = input() rl = [ i for i,_ in enumerate(c) if _ == 'R' ] cnt = 0 loc = 0 rid = -1 while True: try: if c[loc] == 'W': rloc = rl[rid] rid -= 1 if rloc < loc: break else: cnt += 1 loc += 1 if loc == n: break #print(c,cnt) except: break print(cnt)
p02597
s795625357
Accepted
N = int(input()) stone = input() if(stone == "R" * N): print(0) elif(stone == "W" * N): print(0) else: b = stone.count("R") c = stone[0:b].count("R") print(b-c)
p02597
s862637636
Accepted
n=int(input()) s=input() cnt=0 ri=len(s)-1 for li,ss in enumerate(s): if ss=="W": while ri>li and s[ri]=="W": ri-=1 if ri<=li: break ri-=1 cnt+=1 print(cnt)