problem_id
stringclasses
100 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
6
806
p02597
s660657004
Accepted
N = int(input()) c = list(str(input())) for i in range(N): if c[i] == "R": c[i] = 1 else: c[i] = 0 a = sum(c) d = c[:a] e = sum(d) print(a - e)
p02597
s830583150
Accepted
n = int(input()) c = list(input()) ramount = c.count('R') ans = c[: ramount].count('W') print(ans)
p02597
s746011481
Accepted
N = int(input()) C = input() W = sum([1 for c in C if c == 'W']) R = len(C) - W print(sum([1 for c in C[R:] if c == 'R']))
p02597
s136096602
Accepted
l = [] n = int(input()) r = 0 for i in [1 if x == 'R' else 0 for x in list(input())]: r += i l.append(r) c = r - l[r-1] print(c)
p02597
s553089832
Accepted
#!/usr/bin python3 # -*- coding: utf-8 -*- n = int(input()) s = input() r = s.count('R') print(s[:r].count('W'))
p02597
s273262724
Accepted
n = int(input()) c = input() l, r = 0, n-1 ans = 0 while l < r: if c[l] == "W" and c[r] == "R": ans += 1 l, r = l+1, r-1 else: if c[l] == "R": l += 1 if c[r] == "W": r -= 1 print(ans)
p02597
s385343054
Accepted
n = int(input()) s = str(input()) cnt1 = s.count("W") # Wの文字数 cnt2 = len(s) - cnt1 # Rの文字数 ss = s[:cnt2] cnt3 = ss.count("W") print(min(cnt1, cnt3))
p02597
s450984411
Accepted
n=int(input()) c=input() list=[0 for i in range(n+1)] r=0 for i in range(n): if c[i]=='R': r+=1 w=0 list[0]=max(r,w) #i corresponds to the right side boundary of c[i] for i in range(n): if c[i]=='W': w+=1 if c[i]=='R': r-=1 list[i+1]=max(r,w) print(min(list))
p02597
s824922999
Accepted
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) Cs = list(input()) from collections import deque Q = deque() for i, c in enumerate(Cs): if c=='R': Q.append(i) ans = 0 for i in range(N): c = Cs[i] if c=='W': if not Q: break r = Q.pop() if r>i: ans += 1 else: break print(ans)
p02597
s180154900
Accepted
N = int(input()) C = input() num_R = C.count("R") num_W = C.count("W") C_fin = ["R" if i < num_R else "W" for i in range(len(C))] count = 0 for c, c_fin in zip(C, C_fin): if(c == c_fin): count += 1 ans = (len(C) - count)//2 print(ans)
p02597
s549165896
Accepted
#coding:utf-8 N = int(input()) C = str(input()) Lis = [0,0] #["R","W"] for i in C: if i == "R": Lis[0] += 1 else: Lis[1] += 1 D = "R" * Lis[0] + "W" * Lis[1] Lis = [0,0] for s,t in zip(C,D): if (s != t) and (s == "R"): Lis[0] += 1 elif (s != t) and (s == "W"): Lis[1] += 1 print("{}".format(max(Lis)))
p02597
s253863296
Accepted
n = int(input()) c = list(input()) r = 0 w = 0 for i in range(len(c)): if(c[i]=="R"): r += 1 ans = max(r,w) for i in range(len(c)): if(c[i]=="R"): r -= 1 else: w += 1 now = max(r,w) ans = min(ans,now) print(ans)
p02597
s492483499
Accepted
N = input() li = input() #print(li) red = li.count("R") white = li.count("W") #print(red,white) target = li[:red] ans = red - target.count("R") print(ans)
p02597
s612886403
Accepted
n = int(input()) c = input() a = c.count("R") ans = 0 for i in range(a): if c[i] == "W": ans += 1 print(ans)
p02597
s740814292
Accepted
N=int(input()) C=input() R=0 for i in C: if i=="R": R+=1 D=C[:R] count=0 for i in D: if i=="W": count+=1 print(count)
p02597
s339793648
Accepted
import sys input = sys.stdin.readline n = int(input()) s = list(input()) c = 0 for e in s: if e == 'R': c += 1 res = min(c,n-c) tmp = 0 for i in range(c): if s[i] != 'R': tmp += 1 res = min(res,tmp) print(res)
p02597
s718302120
Accepted
n=input() i=list(input()) Wn=i.count("W") print(Wn-i[(len(i)-Wn):].count("W"))
p02597
s788967056
Accepted
N=int(input()) C=list(input()) D=sorted(C) P=0 for i in range(N): if C[i]!=D[i]: P+=1 print(P>>1)
p02597
s630213120
Accepted
n = int(input()) c = input() #右端から見ていって初めのRが出たらWとRをカウントする cnt = 0 R = 0 W = 0 for i in range(n): if c[i] == "R":R += 1 else:W += 1 for i in range(R): if c[i] == "W":cnt += 1 print(cnt)
p02597
s056831671
Accepted
def main(): n = int(input()) c = input() r = 0 for i in range(n): if c[i]=='R': r += 1 ans = 0 for i in range(r): if c[i]=='W': ans += 1 print(ans) if __name__ == "__main__": main()
p02597
s416753825
Accepted
N = int(input()) c = list(input()) count = 0 i = 0 j = N-1 while i < j: while c[i] == "R" and i <= N-2: i += 1 while c[j] == "W" and j >= 1: j -= 1 if i < j: count += 1 i += 1 j -= 1 if i >= j or i >= N or j <= 0: break print(count)
p02597
s976218065
Accepted
_=input();*C,=input();print(len([''for _ in range(C.count('W'))if C and C.pop()=='R']))
p02597
s716475236
Accepted
N = int(input()) C = list(input()) cnt_r = 0 for c in C: if c == "R": cnt_r += 1 for i in range(cnt_r): if C[i] == "R": cnt_r -= 1 print(cnt_r)
p02597
s009274703
Accepted
n = int(input()) c = input() # それぞれの色の数をカウント w = c.count("W") r = c.count("R") ans = 0 for i in range(r): # 赤の数分文字列を確認する if c[i] == "W": ans += 1 # カウント print(ans)
p02597
s954374089
Accepted
n = int(input()) k = input() a = k.count("R") b = k[:a].count("W") print(b)
p02597
s187987521
Accepted
N = int(input()) c = input() rlist = [] wlist = [] for i in range(N): if c[i] == 'R': rlist.append(i) else: wlist.append(i) cnt = 0 if len(rlist) == 0: print(0) exit() for i in range(len(wlist)): if wlist[i] < rlist[-cnt - 1]: cnt += 1 else: break print(cnt)
p02597
s976779952
Accepted
import sys readline = sys.stdin.readline from collections import deque def solve(): N = int(readline()) C = readline().rstrip() R, W = 'R', 'W' reds = deque(i for i in range(len(C)) if C[i] == 'R') whites = deque(i for i in range(len(C)) if C[i] == 'W') count = 0 while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]: reds.pop() whites.popleft() count += 1 print(count) solve()
p02597
s188464853
Accepted
N = int(input()) c = input() dp = [0] * (N) len_c_W = c.count('W') len_c_R = c.count('R') if (len_c_W == 0 or len_c_R == 0): print(0) exit() cnt_W = 0 cnt_R = 0 for i in range(N): if c[i] == 'R': cnt_R += 1 else: cnt_W += 1 count = 0 if (cnt_W <= (len_c_R - cnt_R)): count = len_c_R - cnt_R else: count = cnt_W dp[i] = count print(min(dp))
p02597
s724390586
Accepted
n = int(input()) c = input() s = [0] for i in range(n): if c[i] == 'R': s.append(s[i]) else: s.append(s[i] + 1) r = n - s[n] ans = 10**10 for i in range(n + 1): ans = min(ans, max(s[i], r - i + s[i])) print(ans)
p02597
s033822890
Accepted
import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 n = int(readline()) s = readline().rstrip().decode('utf-8') l = 0 r = n-1 ans = 0 while l < r: if s[l] == "W" and s[r] == "R": ans += 1 l += 1 r -= 1 if s[l] == "R": l += 1 if s[r] == "W": r -= 1 print(ans)
p02597
s562835239
Accepted
n = int(input()) cs = input() cnt = 0 i = 0 j = n-1 while(1): if i >= j: break if cs[i] == "R": i += 1 if cs[j] == "W": j -= 1 if cs[i] == "W" and cs[j] == "R": cnt += 1 i += 1 j -= 1 print(cnt)
p02597
s836852673
Accepted
N = int(input()) string = input() r2w = string.count("R") w2r = 0 ans_list = [max(r2w, w2r)] for c in string: if c == "W": w2r += 1 else: r2w -= 1 ans_list.append(max(r2w, w2r)) print(min(ans_list))
p02597
s237124643
Accepted
n = int(input()) c = list(input()) R_frag = 0 W_frag = 0 ans = 0 r = n - 1 l = 0 while l < r: if c[l] == "R": l += 1 if c[r] == "W": r -= 1 if c[l] == "W" and c[r] == "R": c[l] = "R" c[r] = "W" ans += 1 l += 1 r -= 1 print(ans)
p02597
s006342256
Accepted
N = int(input()) c = input() num_r = 0 for i in range(N) : if c[i] == 'R' : num_r += 1 ans = 0 for i in range(num_r, N) : if c[i] == 'R' : ans += 1 print(ans)
p02597
s340644540
Accepted
n = int(input()) s = input() i = 0 j = len(s)-1 count = 0 while i<j: if s[i] == 'R': i+=1 elif s[j] == 'W': j-=1 else: i+=1 j-=1 count+=1 print(count)
p02597
s389507714
Accepted
N = int(input()) c = list(str(input())) r = c.count('R') w = 0 for i in range(r): if c[i] == 'W': w += 1 print(w)
p02597
s367352941
Accepted
# Nとcの定義 N = int(input()) C = input() # 赤色の個数 red_num = str.count(C, "R") # 左からred_num個までに含まれる白色の個数 white_num_left = str.count(C[:red_num], "W") # 最小の操作回数 min_ope = white_num_left # 最小の操作回数の出力 print(min_ope)
p02597
s557742828
Accepted
n = int(input()) s = input() white_to_red = 0 red_to_white = s.count('R') ans = red_to_white for i in range(n): if s[i] == 'W': white_to_red += 1 else: red_to_white -= 1 ans = min(ans, max(white_to_red, red_to_white)) print(ans)
p02597
s740154110
Accepted
N = int(input()) S = input() r_c = 0 ch = 0 for i in S: if i == "R": r_c += 1 for i in range(r_c): if S[i] == "W": ch += 1 print(ch)
p02597
s138534195
Accepted
N = int(input()) S = input() r = S.count('R') ans = r - S[:r].count('R') print(ans)
p02597
s199134019
Accepted
n = int(input()) C = list(input()) a, b = 0, 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 tmp = max(a, b) ans = min(ans, tmp) print(ans)
p02597
s354007089
Accepted
n = int(input()) C = input() rc = C.count('R') print(C[:rc].count('W'))
p02597
s730020733
Accepted
N = int(input()) c = list(input()) if 'R' in c and 'W' in c: R = int(c.count('R')) c[0:R] = [] print(c.count('R')) else: print(0)
p02597
s153893145
Accepted
n = int(input()) c = input() ans = 0 l, r = 0, n-1 while True: while True: if c[l] == "W": break if l >= r: break l += 1 while True: if c[r] == "R": break if l >= r: break r -= 1 if l >= r: break ans += 1 l += 1 r -= 1 print(ans)
p02597
s778216357
Accepted
n=int(input()) inp=input() num=[0]*(n+1) k=0 for i in range(n): if inp[i]=='R':k+=1 num[i+1]=k R=num[-1] W=n-R ans=float('inf') for i in range(n+1): rl=num[i] wl=i-rl rr=R-rl wr=W-wl swap=min(wl,rr) change=max(wl,rr)-swap ans=min(ans,swap+change) print(ans)
p02597
s380436327
Accepted
N = int(input()) S = input() r = S.count('R') w = 0 ans = [max(r,w)] for i in range(N): if S[i] == 'W': w += 1 else: r -= 1 ans.append(max(w,r)) print(min(ans))
p02597
s700519221
Accepted
n = int(input()) c = str(input()) a, b = 0, 0 a = c.count('R') ans = max(a, b) for i in range(n): if c[i] == 'R': a -= 1 else: b += 1 ans = min(ans, max(a, b)) print(ans)
p02597
s911310529
Accepted
N = int(input()) C = input() nw = C.count('W') nr = N - nw if nw == N or nr == N: print(0) else: a = C[:nr] b = C[nr:] nw = a.count('W') nr = b.count('R') n = min(nw, nr) m = max(nw, nr) - n print(n + m)
p02597
s988959018
Accepted
N=int(input()) C=input() s=0 e=N-1 ans=0 while(s<e): while(C[s]=="R" and s<e): s+=1 while(C[e]=="W" and s<e): e-=1 if s<e: s+=1 e-=1 ans+=1 print(ans)
p02597
s511694637
Accepted
_,s=open(0) print(s[:s.count('R')].count('W'))
p02597
s125423828
Accepted
n = int(input()) c = list(input()) r_cnt = c.count('R') w_cnt = c.count('W') cnt = 0 for i in range(r_cnt): if c[i] == 'R': continue else: cnt += 1 print(cnt)
p02597
s893560839
Accepted
n = int(input()) s = input() check = s.count("R") q = s[:check] print(q.count("W"))
p02597
s585428948
Accepted
n = int(input()) c = input() l = 0 r = n - 1 ans = 0 while True: while c[l] == 'R' and l < r: l += 1 while c[r] == 'W' and l < r: r -= 1 if l < r: ans += 1 l += 1 r -= 1 else: print(ans) break
p02597
s411843343
Accepted
n = int(input()) C = list(input()) l = 0 r = n-1 ans = 0 while l < r: while C[l] == 'R' and l<r: l += 1 while C[r] == 'W' and l<r: r -= 1 if C[l]=='W' and C[r] == 'R': ans += 1 l += 1 r -= 1 print(ans)
p02597
s573288057
Accepted
import sys input = sys.stdin.readline N=int(input().rstrip('\n')) S=list(input().rstrip('\n')) score = [S.count('R'),S.count('W')] sta = 'R' ws = 0 rs = S.count('R') sto = 0 for i in range(N): if S[i] != sta: if sta=='W': ws += sto sto = 1 score.append(max(rs,ws)) sta ='R' else: rs -= sto sto = 1 score.append(max(rs,ws)) sta ='W' else: sto += 1 print(min(score))
p02597
s586641084
Accepted
import sys read = sys.stdin.read def main(): n = int(input()) a = input() if not 'WR' in a: print(0) sys.exit() a = list(a) rnum = a.count('R') rl = 0 rr = 0 for i1 in range(rnum): rl += a[i1] == 'W' for j1 in range(n - rnum): rr += a[rnum + j1] == 'R' r = max(rl, rr) print(r) if __name__ == '__main__': main()
p02597
s509651962
Accepted
import sys input = sys.stdin.readline N = int(input()) S = list(input().rstrip()) A1 = [0]*(N+1) A2 = [0]*(N+1) t = 0 for i, s in enumerate(S): if s == "W": t += 1 A1[i+1] = t t = 0 for i in reversed(range(N)): if S[i] == "R": t += 1 A2[i] = t ans = 10**18 for a1, a2 in zip(A1, A2): score = abs(a1-a2) + min(a1, a2) ans = min(ans, score) print(ans)
p02597
s833991403
Accepted
n = int(input()) c = input() r = 0 for i in range(len(c)): if c[i] == "R": r += 1 m_w = 0 for i in range(r): if c[i] == "W": m_w += 1 print(m_w)
p02597
s924738536
Accepted
N=int(input()) c=input() R=c.count('R') W=0 ans=[R,c.count('W')] for i in range(N): if c[i]=='W': W+=1 else: R-=1 ans.append(max(R,W)) print(min(ans))
p02597
s995335808
Accepted
n = int(input()) c = input() p = [] for i in range(n): if c[i]=='R': p += [i] print(len([1 for i in p if i>=len(p)]))
p02597
s970630442
Accepted
N=int(input()) c=input() C=[a for a in c] number=0 answer=0 red=C.count('R') if red==0 or red==N: print(0) else: words=C[red:] print(words.count('R'))
p02597
s456747277
Accepted
N,c=input(),input() print(c[:c.count('R')].count('W'))
p02597
s919642159
Accepted
N = int(input()) stones = input() total_count_R = stones.count('R') left_count_R = stones[0:total_count_R].count('R') answer = total_count_R - left_count_R print(answer)
p02597
s419655555
Accepted
N = int(input()) a = list(input()) #1文字ずつ # print(a) allW=0 allR=0 for i in range(N): if a[i]=='W': allW+=1 elif a[i]=='R': allR+=1 # print('allW,allR:',allW,allR) W=0 R=allR out = max(W,R) ans = out for shikiri in range(N): if a[shikiri] =='W': W+=1 elif a[shikiri]=='R': R-=1 out = max(W,R) ans = min(ans,out) # print('out,ans:',out,ans) print(ans)
p02597
s197970991
Accepted
import sys from collections import Counter sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline def solve(): _ = int(rl()) c = rl().rstrip() counter = Counter(c) red = counter['R'] white = counter['W'] red -= c[:red].count('R') white -= c[-white:].count('W') print(min(red, white)) if __name__ == '__main__': solve()
p02597
s997589192
Accepted
N = int(input()) C = input() tmp = 0 for i in range(N): if C[i] == "R": tmp += 1 ans = 0 for i in range(tmp): if C[i] == "W": ans += 1 print(ans)
p02597
s383565339
Accepted
N = int(input()) C = list(input()) l = 0 r = N-1 ans = 0 while (r-l) > 0: if C[l] == "W" and C[r] == "R": C[l], C[r] = C[r], C[l] l += 1 r -= 1 ans += 1 continue if C[l] == "R": l += 1 if C[r] == "W": r -= 1 print(ans)
p02597
s155987241
Accepted
n = int(input()) k = input() k2 = k[::-1] i1 = 0 i2 = 0 cnt = 0 while i1 < n: if k[i1] == 'W': while i2 < n: if k2[i2] == 'R': i2 += 1 cnt += 1 break i2 += 1 if i1 + i2 >= n: break i1 += 1 if i1 + i2 >= n: break print(cnt)
p02597
s223859715
Accepted
def resolve(): n = int(input()) c = input() ans = 0 l = -1 r = n while True: l += 1 r -= 1 while l < n and c[l] == "R": l += 1 while r >= 0 and c[r] == "W": r -= 1 if l > r: break ans += 1 print(ans) if __name__ == '__main__': resolve()
p02597
s399499804
Accepted
def main(): n = int(input()) c = input() r = c.count('R') w = c.count('W') ropt = c[:r].count('R') wopt = c[r:].count('W') rnot = r - ropt wnot = w - wopt return min(rnot,wnot) if __name__ == '__main__': print(main())
p02597
s329648901
Accepted
n = int(input()) c = input() r = 0 left, right = 0, n-1 while left < right: if c[left] == 'W' and c[right] == 'R': r += 1 left += 1 right -= 1 continue if c[left]=='R': left += 1 if c[right]=='W': right -= 1 print(r)
p02597
s845871695
Accepted
from collections import deque n=int(input()) d=deque(list(input())) #print(d) r=0 while n>1: #print(d) tempr=False n-=1 if d.pop()=="W": pass else: while n>0: n-=1 if d.popleft()=="R": pass else: r+=1 break #print(d,r) print(r)
p02597
s003496214
Accepted
N = int(input()) stone = input() R = stone.count('R') ans = stone.count('W', 0, R) print(ans)
p02597
s936097324
Accepted
import collections N= int(input()) s = input() counter = collections.Counter({'R':0, 'W':0}) counter.update(s) print(s[:counter['R']].count('W'))
p02597
s627318310
Accepted
n = int(input()) c = input() r_num = c.count("R") for i in range(n): if c[i] == "W": break print(max(c[i:].count("R")-c[i:r_num].count("R"), 0))
p02597
s681319975
Accepted
n, c = int(input()), input() wa = [0] * (n+2) for i in range(n): if(c[i]=='W'): wa[i+1]+=1 for i in range(n+1): wa[i+1] += wa[i] ans = n; for i in range(n+2): w = wa[i] r = n-i - (wa[n] - wa[i]) ans = min(ans, max(w, r)) print(ans)
p02597
s828033992
Accepted
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys n = int(input()) word = input() res = 0 num_r = 0 for charactor in word: if charactor == 'R': num_r += 1 num_w = 0 for i in range(num_r): if word[i] == 'W': num_w += 1 print(num_w)
p02597
s163892165
Accepted
N = int(input()) C = input() r = C.count('R') w = C.count('W') if len(C) == r or len(C) == w or C[:r].count('R') == r: print(0) else: print(C[:r].count('W'))
p02597
s484890486
Accepted
n=int(input()) c=input() R=c.count("R") W=c.count("W") LW=0 for i in range(R): if c[i]=="W": LW+=1 print(LW)
p02597
s464497962
Accepted
import collections N = int(input()) c = input() A = collections.Counter(c)["R"] B = collections.Counter(c[A:])["R"] print(B)
p02597
s857771975
Accepted
n=int(input()) c=list(input()) import math rkosu=c.count("R") wkosu=n-rkosu ca=["R"]*rkosu+["W"]*wkosu count=0 for i in range(n): if c[i] != ca[i]: count+=1 ans=math.ceil(count/2) print(ans)
p02597
s032568784
Accepted
import sys N = int(input()) c = str(input()) if "W" not in c or "R" not in c: print("0") sys.exit() red = c.count("R") stay_red = c.count("R", 0, red) print(red - stay_red)
p02597
s520364663
Accepted
n=int(input()) s=input() wcount=0 for i in range(n): if s[i]=="R" : wcount+=1 wwcount=0 for i in range(wcount): if s[i]=="R" : wwcount+=1 print(wcount-wwcount)
p02597
s370556869
Accepted
n = int(input()) cs = input() b=[] for i in range(n): if cs[i] == "W": b.append(0) else: b.append(1) a= sum(b) ans = a- sum(b[:a]) print(ans)
p02597
s939289803
Accepted
n = int(input()) s = input() w = s.count('W') r = s.count('R') sw = s.count('W',0-w) rw = 2*10**5 if r >=1: rw = w-sw print(min(w,r,rw))
p02597
s826482489
Accepted
N = int(input()) S = input() print(S[S.count("R"):].count("R"))
p02597
s875093602
Accepted
N = int(input()) S = input() R = [0] W = [0] r = 0 w = 0 for i in range(N): if S[i]=="W": w+=1 else: r+=1 R.append(r) W.append(w) ans = N for i in range(N+1): ans = min(ans,max(W[i],R[N]-R[i])) print(ans)
p02597
s140464054
Accepted
n=int(input()) c=input() a=c.count('R') print(c[:a].count('W'))
p02597
s861662815
Accepted
n=int(input()) c=list(input()) if len(set(c))==1: print('0') else: r=c.count('R') w=c.count('W') rc=c[:r].count('R') wc=c[:r].count('W') if rc==0: if r<w: print(r) else: print(w) else: if r-rc<wc: print(r-rc) else: print(wc)
p02597
s259719289
Accepted
N = int(input()) c = input() right = N-1 left = 0 cnt = 0 for i in range(N): if right <= left: break if c[right] == "W": right -= 1 else: if c[left] == "R": left += 1 # 交換 else: cnt += 1 left += 1 right -= 1 print(cnt)
p02597
s672256552
Accepted
import math import sys from itertools import permutations input = sys.stdin.readline n=int(input()) arr=list(input()) if arr[-1]=='\n': arr.pop() countW=0 for i in range(n): if arr[i]=='W': countW+=1 ans=0 for i in range(n-countW): if arr[i]=='W': ans+=1 print(ans)
p02597
s562644417
Accepted
_,C=input(),input() a=C.count('R') print(a-C[:a].count('R'))
p02597
s407675396
Accepted
def main(): N = int(input()) S = input() border = S.count("R") ans = 0 for i in range(N): if S[i] == "W" and i < border: ans += 1 print(ans) if __name__ == "__main__": main()
p02597
s516297911
Accepted
n = int(input()) c = input() l = 0 r = n-1 ans = 0 while l<r: if c[l] == "R": l += 1 if c[r] == "W": r -= 1 if c[l]=="W" and c[r]=="R": l += 1 r -= 1 ans += 1 print(ans)
p02597
s893462573
Accepted
n = int(input()) C = input() sR = [0]*(n+1) sW = [0]*(n+1) for i in range(n): sR[i+1] = sR[i] + (C[i] == "R") sW[i+1] = sW[i] + (C[i] == "W") ans = 10**10 for i in range(n+1): r = sR[n] - sR[i] w = sW[i] ans = min(ans, max(r,w)) print(ans)
p02597
s379686754
Accepted
n = input() data = input() w = [] r = [] for i in range(len(data)): if data[i] == "W": w.append(i) else: r.append(i) ans = 0 if len(w) == 0: print(ans) elif len(r) == 0: print(ans) else: r = r[::-1] for i in range(min(len(w), len(r))): tmp_w = w[i] tmp_r = r[i] if tmp_w <= tmp_r: r.append(tmp_w) w.append(tmp_r) ans += 1 else: break print(ans)
p02597
s476142809
Accepted
n = int(input()) c = [i for i in input()] cnt = 0 for num, i in enumerate(sorted(c)): if c[num] != i: cnt += 1 print(cnt // 2)
p02597
s337233627
Accepted
n = int(input()) wr = input() R_cnt = wr.count('R') ans = wr.count('W',0,R_cnt) print(ans)
p02597
s852100769
Accepted
N = int(input()) c = input() white = 0 white_ends = 0 for i in range(N): if c[i] == "W": white += 1 for i in range(N-white, N): if c[i] == "W": white_ends += 1 print(white-white_ends)
p02597
s560446527
Accepted
n=int(input()) c=input() a=c.count('R') print(a-c[:a].count('R'))