problem_id
stringclasses
100 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
6
806
p02597
s997695997
Accepted
n = int(input()) C = list(input()) r_num = C.count('R') ans = C[:r_num].count('W') print(ans)
p02597
s949949400
Accepted
import sys N = int(input()) c = list(input()) r = c.count("R") rs = c[:r] rsw = rs.count("W") print(rsw)
p02597
s726424049
Accepted
n = int(input()) c_array = list(input()) w_num = c_array.count('W') r_num = n-w_num def get_ans(half): wl_num = c_array[:half].count('W') rr_num = c_array[half:].count('R') ans = min(wl_num, rr_num) + abs(wl_num-rr_num) return ans ans = min(get_ans(r_num), w_num, r_num) print(ans)
p02597
s648329457
Accepted
from collections import Counter def main(): N = int( input()) C = list(input()) CC = Counter(C) ans = min(CC["R"], CC["W"]) r = CC["R"] count = 0 for c in C[:r]: if c == "W": count += 1 ans = min(ans, count) print(ans) if __name__ == '__main__': main()
p02597
s511710952
Accepted
n = int(input()) c = list(input()) wpos = 0 rpos = n-1 count = 0 while wpos < rpos : while c[wpos] == "R": wpos += 1 if wpos > rpos: break while c[rpos] == "W": rpos -= 1 if wpos > rpos: break if wpos < rpos : count += 1 c[wpos],c[rpos]=c[rpos],c[wpos] print(count)
p02597
s141502753
Accepted
N = int(input()) c = list(input()) red=0 for i in c: if i=="R": red+=1 count = 0 for i in range(red): if c[i]=="W": count+=1 print(count)
p02597
s757296336
Accepted
N = int(input()) C = list(input()) r_cnt = C.count("R") w_cnt = C.count("W") ref_c = ["R"]*r_cnt + ["W"]*w_cnt cnt = 0 for i in range(N): if C[i] != ref_c[i]: cnt += 1 ans = min(r_cnt, w_cnt, int(cnt/2)) print(ans)
p02597
s368686304
Accepted
n = int(input()) mozi = input() a_list = [] for i in range(n): if mozi[i] == 'W': a_list.append(0) else: a_list.append(1) r_count = sum(a_list) print(r_count - sum(a_list[0:r_count]))
p02597
s037891053
Accepted
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") 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 LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] n=II() s=SI() allr=s.count("R") lr=s[:allr].count("R") print(allr-lr)
p02597
s476881661
Accepted
n=int(input()) c=list(input()) r_count=c.count("R") w_count=c.count("W") temp=list(c[:n-w_count]) print(temp.count("W"))
p02597
s131425526
Accepted
N = int(input()) words = list(input()) ct_R = words.count('R') ct_W = words.count('W') a = words[0:ct_R] W_in_a_count = a.count('W') print(W_in_a_count)
p02597
s208387115
Accepted
n = int(input()) c = input() cntR = c.count('R') print(c[:cntR].count('W'))
p02597
s298356000
Accepted
N=int(input()) c=list(input()) x=0 M=N for i in range(N): if c[i]=="W": for j in range(N): if i==M-1-j: M=i break elif c[M-1-j]=="R": x+=1 c[M-1-j]="W" M=M-j break if i==M: break print(x)
p02597
s051625615
Accepted
def f(c): return 1*(c=="R") N=int(input()) C=list(map(f,input())) R=C.count(1) S=C[:R].count(0) print(S)
p02597
s481195142
Accepted
# coding: utf-8 n = int (input()) s=list(input()) w_count = 0 r_count = 0 for item in s: if (item == "W"): w_count+=1 elif (item == "R"): r_count+=1 target = ["R"] * r_count + ["W"] * w_count ans_count = 0 for i in range(n): if (s[i] != target[i]): ans_count+=1 print (int(ans_count / 2))
p02597
s291102889
Accepted
import sys import math sys.setrecursionlimit(500000) INF = float('inf') def main(): n = int(input()) c = input() red_stones = c.count('R') return c[red_stones:].count('R') if __name__ == '__main__': print(main())
p02597
s060067501
Accepted
n = int(input()) s = input() siro = s.count('W') aka = n - siro ans = 0 for i in range(aka, n): if s[i] == 'R': ans += 1 print(ans)
p02597
s487621643
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') r = 0 for i1 in range(rnum): r += a[i1] == 'W' for j1 in range(n - rnum): r += a[rnum + j1] == 'R' r = r // 2 print(r) if __name__ == '__main__': main()
p02597
s335709602
Accepted
N = int(input()) s = input() r = s.count("R") print(s[:r].count("W"))
p02597
s737575701
Accepted
N = int(input()) C = input() c = [] for i in C: c.append(i) a = c.count("R") count = 0 for b in c[0:a]: if b == "R": count += 1 print(a - count)
p02597
s761133990
Accepted
N = int(input()) A = str(input()) Wsum = 0 Wright = 0 for i in range(N): if A[i] == "W": Wsum += 1 for i in range(N - Wsum): if A[i] == "W": Wright += 1 print(Wright)
p02597
s624265322
Accepted
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)
p02597
s722410661
Accepted
def main(): n = int(input()) s = input() r = s.count("R") cnt = 0 for i in range(n-1, r-1, -1): if s[i] == "R": cnt += 1 print(cnt) main()
p02597
s382067081
Accepted
N = int(input()) c = list(input()) Wnum = c.count("W") if Wnum == 0 or Wnum == N: print(0) else: F = "R" * (N - Wnum) + "W" * Wnum t = 0 for i in range(N): if c[i] != F[i]: t += 1 print(t//2 + t%2)
p02597
s060582600
Accepted
N = int(input()) c = list(input()) l = 0 r = N - 1 ans = 0 while True: while l < N and c[l] == 'R': l += 1 while r >= 0 and c[r] == 'W': r -= 1 if r < l: break c[r], c[l] = c[l], c[r] ans += 1 print(ans)
p02597
s984056144
Accepted
""" 4 WWRR 2 """ import itertools n = int(input()) s = list(input()) left_w = [0] right_r = [0] for l in s: if l == "W": left_w.append(1) else: left_w.append(0) lacc = list(itertools.accumulate(left_w)) for r in s[::-1]: if r == "R": right_r.append(1) else: right_r.append(0) racc = list(itertools.accumulate(right_r)) racc = racc[::-1] print(min(map(max, zip(lacc, racc))))
p02597
s524323781
Accepted
n = int(input()) S = [c for c in input()] ans = 0 i = 0 j = n-1 while i < j: if S[i] == "W": if S[j] == "R": S[i] = "R" S[j] = "W" j -= 1 i += 1 ans += 1 else: j -= 1 else: i += 1 print(ans)
p02597
s215301169
Accepted
def main(): n = int(input()) s = input() ans = 0 L, R = 0, n-1 while L < R: if s[L] != "W": L += 1 elif s[R] != "R": R -= 1 else: ans += 1 L += 1 R -= 1 print(ans) if __name__ == "__main__": main()
p02597
s591894122
Accepted
N = int(input()) c = input() ans = [-1] * (N+1) for i in range(0, N+1): if i == 0: l = c[:i] r = c[i:] W = l.count("W") R = r.count("R") else: if (c[i-1]) == "W": W += 1 elif (c[i-1]) == "R": R -= 1 ans[i] = max(R, W) print(min(ans))
p02597
s337071306
Accepted
n=int(input()) c=input() s=0 t=n-1 ans=0 while s<t and s<n and t>=0: while c[s]=='R': s+=1 if not s<n: break while c[t]=='W': t-=1 if not t>=0: break if s<t: ans+=1 s+=1 t-=1 else: break print(ans)
p02597
s152757035
Accepted
n = int(input()) # cs = ['W' for i in range(200000)] cs = input() w_count = 0 for c in cs: if c == 'W': w_count += 1 if w_count == 0: print(0) exit() rest = cs[-w_count:] answer = 0 for c in rest: if c == 'R': answer += 1 print(answer)
p02597
s921704352
Accepted
N = int(input()) c = input() ans = 0 i = 0 j = N-1 while i < j: while True: # print(1, i, j) if i == j: break if c[i] == 'W': break i += 1 while True: # print(2, i, j) if i == j: break if c[j] == 'R': ans += 1 break j -= 1 i += 1 j -= 1 print(ans)
p02597
s521458399
Accepted
n = int(input()) c = input() cls = list(c) rcnt = cls.count('R') wcnt = cls[:rcnt].count('W') print(wcnt)
p02597
s527859859
Accepted
N = int(input()) s = input() fir = True f = 0 b = len(s)-1 count = 0 while(b > f): if(s[f] == "R"): f += 1 continue elif(s[b] == "R"): count += 1 f += 1 b -= 1 continue elif(s[b] == "W"): b -= 1 print(count)
p02597
s435611966
Accepted
N = int(input()) c = input() red = 0 for i in c: if i == "R": red += 1 ans = 0 for i in c[red:]: if i == "R": ans += 1 print(ans)
p02597
s898005495
Accepted
n = int(input()) c = input() left = 0 right = len(c)-1 count = 0 while left < right: while c[left] != 'W': left += 1 if left >= right: print(count) exit() while c[right] != 'R': right -= 1 if left >= right: print(count) exit() count += 1 left += 1 right -= 1 print(count)
p02597
s720220541
Accepted
n = int(input()) c = input() rcnt = 0 for i in range(n): if c[i] == 'R': rcnt += 1 ans = 0 for i in range(rcnt): if c[i] == 'W': ans += 1 print(ans)
p02597
s710110602
Accepted
N = int(input()) c = input() l = 0 r = N-1 ans = 0 while(l < r): while(l < N and c[l] == 'R'): l += 1 while(r >= 0 and c[r] == 'W'): r -= 1 if l > r or l >= N or r < 0: break else: # print(l, r) if l-1 == r: ans += 1 break else: l += 1 r -= 1 ans += 1 print(ans)
p02597
s575482366
Accepted
n = int(input()) c = input() head = 0 tail = n-1 cnt = 0 while head < tail: if c[tail] == "R": while c[head] == "R" and head != tail: head += 1 if head != tail: head += 1 cnt += 1 tail -= 1 print(cnt)
p02597
s378267607
Accepted
N = int(input()) C = input() R = C.count("R") ans = 0 for i in range(R): if C[i] == "W": ans += 1 print(ans)
p02597
s517553576
Accepted
n = int(input()) c = input() cnt = 0 for i in range(n): w_idx = c.find("W") r_idx = c.rfind("R") if w_idx < r_idx and w_idx != -1: c = c[w_idx+1:r_idx] cnt += 1 print(cnt)
p02597
s917031650
Accepted
N = input() c = input() R_count = c.count("R") W_count = c[:R_count].count("W") print(W_count)
p02597
s675430665
Accepted
N = int(input()) c = list(input()) li = 0 import sys if "R" not in c or "W" not in c: print (0) sys.exit() ans = 0 for i in range(N-1,-1,-1): if c[i] == "R": while c[li] != "W" and li <= i: li += 1 if li >= i: break c[i] = "W" c[li] = "R" ans += 1 print (ans)
p02597
s399016466
Accepted
N=int(input()) c=input() right_r=0 right_w=0 left_r=0 left_w=0 for i in range(N): if c[i]=='R': right_r+=1 else: right_w+=1 ans=right_r for j in range(N): cnt=0 if c[j]=='W': left_w+=1 right_w-=1 else: left_r+=1 right_r-=1 if right_r<=left_w: cnt+=right_r cnt+=left_w-right_r else: cnt+=left_w cnt+=right_r-left_w if cnt<ans: ans=cnt print(ans)
p02597
s961153227
Accepted
n = int(input()) s = input() l = 0 r = n-1 ans = 0 while(True): while(s[l]=='R' and l<n-1): l+=1 while(s[r]=='W' and 0<r): r-=1 if l < r: ans += 1 l += 1 r -= 1 else: break print(ans)
p02597
s741073785
Accepted
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))
p02597
s729858841
Accepted
n = int(input()) c = list(input()) sc = sorted(c) if sc[0] == "W" or sc[-1] == "R": print(0) else: for i in range(n): if sc[i] == "W": W_start = i break W_in_R = 0 for i in c[:W_start]: if i == "W": W_in_R += 1 R_in_W = 0 for i in c[W_start:]: if i == "R": R_in_W += 1 print(max(W_in_R , R_in_W))
p02597
s725217085
Accepted
N = int(input()) C = [c == "R" for c in input()] count_red = C.count(True) print(C[:count_red].count(False))
p02597
s418687279
Accepted
#abc174d n=int(input()) c=input() r=c.count('R') x=c[:r] print(x.count('W'))
p02597
s308407308
Accepted
n = int(input()) s = input() red = 0 white = 0 for x in s: if x=='R': red += 1 else: white += 1 reqr = 0 for i in range(red): if s[i]=='W': reqr += 1 print(reqr)
p02597
s116770067
Accepted
def alter_altar(s): tmp = 'R' * s.count('R') + 'W' * s.count('W') ans = 0 for i in range(len(s)): if s[i] == tmp[i]: pass else: ans += 1 return ans//2 if __name__ == "__main__": _ = input() s = input() print(alter_altar(s))
p02597
s164491031
Accepted
n = int(input()) c = list(input()) r = c.count('R') r_li = c[r:] ans = r_li.count('R') print(ans)
p02597
s718534611
Accepted
n = int(input()) c = input() l_c = len(c) r = 0 ans = 0 for i in range(l_c): if c[i] == 'R': r += 1 for i in range(r,l_c): if c[i] == 'R': ans += 1 print(ans)
p02597
s156384660
Accepted
n=int(input()) s=input() l=[0] for i in range(n): l.append(l[i]+(s[i]=="R")) ans=n #print(l) for i in range(n+1): ans=min(ans,abs(l[i]-i)+abs(l[-1]-l[i])) #print(ans,i) if i==l[-1]: ans=min(ans,abs(l[i]-i)) #print(ans) print(ans)
p02597
s823656725
Accepted
from collections import deque n=int(input()) c=input() r=deque() lr=0 for i in range(n): if c[i]=="R": lr+=1 r.append(i) ans=0 for i in range(n): if lr==0: break if c[i]=="W": if i<r[-1]: ans+=1 r.pop() lr-=1 else: break print(ans)
p02597
s380968906
Accepted
n = int(input()) s = input() red = [] white = [] for i in range(n): if s[i] == 'W': white.append(i) for i in range(n - 1, -1, -1): if s[i] == 'R': red.append(i) #print(white, red) if min(len(red), len(white)) == 0: print(0) exit() for i in range(min(len(red), len(white))): if white[i] >= red[i]: print(i) exit() print(min(len(red), len(white)))
p02597
s062693496
Accepted
N = int(input()) C = input() r_count = C.count("R") ans = r_count - C[:r_count].count("R") print(ans)
p02597
s416829743
Accepted
import numpy as np N = int(input()) S = input() R_count=0 w_count=0 for i in S: if(i=="R"): R_count+=1 for i in np.arange(R_count): if(S[i]=="W"): w_count+=1 print(w_count)
p02597
s728677121
Accepted
N = int(input()) c = list(input()) r_num = c.count("R") ref = c[:r_num] w_num = ref.count("R") print(r_num - w_num)
p02597
s224465644
Accepted
n = int(input()) s = list(input()) w = s.count("R") #print(w) x = s[:w].count("R") #print(x) print(w-x)
p02597
s615501660
Accepted
N = int(input()) C = input() left = 0 right = N -1 ans = 0 while left < right: if C[left] == 'W' and C[right] == 'R': left += 1 right -= 1 ans += 1 elif C[left] == 'W': right -= 1 elif C[left] == 'R': left += 1 print(ans)
p02597
s039490433
Accepted
# -*- coding: utf-8 -*- n=int(input()) c=str(input()) r=c.count('R') if r==0: print(r) else: cp=c[0:r] k=cp.count('R') print(r-k)
p02597
s176769113
Accepted
n = int(input()) c = input() l = 0 r = n - 1 ans = 0 while l < r: while c[l] != "W" and l + 1 < n: l += 1 while c[r] != "R" and r - 1 >= 0: r -= 1 if l < r: ans += 1 l += 1 r -= 1 print(ans)
p02597
s052969658
Accepted
n=int(input()) c=input() cw=c.count('W') cr=c.count('R') ans_s='R'*cr+'W'*cw cnt=0 for i in range(n): if c[i]!=ans_s[i]: cnt+=1 print((cnt+2-1)//2)
p02597
s869387082
Accepted
N = int(input()) c = list(input()) cnt = 0 w_last_index = N-1 for i in range(N): if c[i] == 'W': flag = True for j in range(w_last_index,i,-1): if c[j] == 'R': c[j] = 'W' w_last_index=j cnt+=1 flag = False break if flag: break print(cnt)
p02597
s493270558
Accepted
n = int(input()) c = input() strings = "R"*c.count("R") + "W"*c.count("W") ans = 0 for a,b in zip(strings,c): if a != b: ans += 1 print(ans//2)
p02597
s436252523
Accepted
n = int(input()) c_list = list(input()) start = 0 end = n ans = 0 while 1: for i in range(start, n): start = i if c_list[i] == "W": break for i in reversed(range(end)): end = i if c_list[i] == "R": break if start >= end: break c_list[start], c_list[end] = c_list[end], c_list[start] start += 1 ans += 1 print(ans)
p02597
s124971103
Accepted
n=int(input("")) lis=input("") rt=0 for i in lis: if(i=="R"): rt+=1 ht=n-rt r=0 h=0 s=max(h,rt) for i in lis: if(i=="R"): r+=1 else: h+=1 on=rt-r m=max(on,h) if(s>m): s=m print(s)
p02597
s517675436
Accepted
N = int(input()) S = input() cumw = [0] for c in S: cumw.append(cumw[-1] + int(c=='W')) cumr = [0] for c in S[::-1]: cumr.append(cumr[-1] + int(c=='R')) cumr.reverse() ans = N for a,b in zip(cumw,cumr): ans = min(ans, max(a,b)) print(ans)
p02597
s954481696
Accepted
N=int(input()) d=input() r=d.count('R') w=N-r ans=r leftr,leftw,rightr,rightw=0,0,r,N-r for i in range(N): if d[i]=='R': leftr+=1 rightr-=1 else: leftw+=1 rightw-=1 if leftw==rightr: f=rightr elif leftw<rightr: f=rightr else: f=leftw ans=min(ans,f) print(ans)
p02597
s743445719
Accepted
N = int(input()) c = list(input()) l, r = 0, N - 1 cnt = 0 while l < r: L, R = c[l], c[r] if L == 'W' and R == 'R': c[l], c[r] = 'R', 'W' l += 1 r -= 1 cnt += 1 elif L == 'W' and R == 'W': r -= 1 elif R == 'R' and R == 'R': l += 1 else: l += 1 r -= 1 print(cnt)
p02597
s831127924
Accepted
import sys N=int(sys.stdin.readline().strip()) C=sys.stdin.readline().strip() L=[0] R=[0] for c in C: if c=="W": L.append(L[-1]+1) else: L.append(L[-1]) for c in C[::-1]: if c=="R": R.append(R[-1]+1) else: R.append(R[-1]) R=R[::-1] ans=float("inf") for i in range(N+1): ans=min(ans,max(L[i],R[i])) print ans
p02597
s791342034
Accepted
import sys input=sys.stdin.readline n=int(input()) c=input().rstrip() l=0 r=n-1 ans=0 while True: while c[l]=='R': l+=1 if l==n: break while c[r]=='W': r-=1 if r==-1: break if l>r: break ans+=1 l+=1 r-=1 temp=0 for i in c: if i=='R': temp+=1 temp=min(temp,n-temp) ans=min(ans,temp) print(ans)
p02597
s938876177
Accepted
N = int(input()) *C, = input() nw = C.count('W') ans = 0 for _ in range(N): if nw == 0: break tmp = C.pop() if tmp == 'W': nw -= 1 else: ans += 1 nw -= 1 print(ans)
p02597
s371249975
Accepted
def main(): n = int(input()) s = str(input()) num_r = 0 for i in range(n): if s[i] == "R": num_r += 1 ans = 0 for i in range(num_r): if s[i] == "W": ans += 1 print(ans) if __name__ == "__main__": main()
p02597
s540461191
Accepted
n = int(input()) s = list(input()) j = 1 count = 0 for i in range(n): if s[i] == 'R': continue else: while 1: if j + i >= n: break elif s[-j] == 'R': s[i] = 'R' s[-j] = 'W' count += 1 break j += 1 print(count)
p02597
s947593337
Accepted
N = int(input()) C = input() tmp = C tmp2 = len(tmp.replace("W","")) tmp3 = C[0:tmp2] ans = len(tmp3.replace("R","")) print(ans)
p02597
s425798682
Accepted
N = int(input()) c = input() r = c.count('R') print(c[:r].count('W'))
p02597
s147937758
Accepted
N = int(input()) C = input() def solve(): red = C.count('R') white = C[:red].count('W') return white if __name__ == "__main__": print(solve())
p02597
s827721701
Accepted
N = int(input()) C = input() R, W = [], [] R_ = [] nR, nW = 0, 0 for c in C: if c == 'R': nR += 1 else: nW += 1 R.append(nR) W.append(nW) if nR == 0 or nW == 0: print(0) exit() for r in R: R_.append(nR - r) ans = N for i in range(N): r, w, r_ = R[i], W[i], R_[i] if r_ > w: ans = min(r_, ans) else: ans = min(w, ans) print(ans)
p02597
s227883248
Accepted
def main(): N = int(input()) c = input() r_count = 0 w_count = 0 for cc in c: if cc == 'R': r_count += 1 else: w_count += 1 ans = 0 for cc in c[:r_count]: if cc == 'W': ans += 1 print(ans) if __name__ == "__main__": main()
p02597
s644906560
Accepted
N = int(input()) c = input() rw = [0, 0] for i in range(N): if c[i] == 'R': rw[0] += 1 else: rw[1] += 1 ans = N left_rw = [0, 0] right_rw = rw[:] for i in range(N+1): if i == 0: pass else: if c[i-1] == 'R': left_rw[0] += 1 right_rw[0] -= 1 else: left_rw[1] += 1 right_rw[1] -= 1 ans = min(max(left_rw[1], right_rw[0]), ans) print(ans)
p02597
s339778670
Accepted
from collections import Counter N = int(input()) S = input() c = Counter(S) S_target = 'R' * c['R'] + 'W' * c['W'] ans = 0 for a, b in zip(S, S_target): if b == 'W': break if a != b: ans += 1 print(ans)
p02597
s144149203
Accepted
N = int(input()) C = input() cnt = 0 left = 0 right = N-1 while(left < right and left<=N-1): if(C[left] == 'W'): flag = 0 while(left < right): if(C[right] == 'R'): cnt += 1 right -= 1 break right -= 1 left += 1 print(cnt)
p02597
s430115618
Accepted
#from functools import lru_cache import sys def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst)) def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst)) def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines()) ls = reader() n = int(ls[0][0]) wr =ls[1][0] nr = len(list(filter(lambda a:a=='R',wr))) nleftr = len(list(filter(lambda a:a=='R',wr[:nr]))) print(nr-nleftr)
p02597
s031324915
Accepted
N = int(input()) C = input() i = 0 j = N-1 ans = 0 while True: while i<N and C[i] != "W": i += 1 while j>=0 and C[j] !="R": j -= 1 if i>=j: break ans += 1 i += 1 j -= 1 print(ans)
p02597
s786799274
Accepted
def main(): n=int(input()) c=input() cc=sorted(c) count = 0 for i in range(n): if c[i] != cc[i]: count += 1 print(count//2) if __name__ == '__main__': main()
p02597
s815359100
Accepted
import collections def main(): n = int(input()) c = list(input()) wcnt = c.count("W") rcnt = c.count("R") if wcnt == 0 or rcnt == 0: print(0) return ans = c[0:rcnt].count("W") print(ans) if __name__ == '__main__': main()
p02597
s701614956
Accepted
input() s = input() pref = 0 total = s.count('R') res = int(1e9) for i in range(total): pref += s[i] == 'R' res = min(res, total - pref) print(res if total != len(s) and total != 0 else 0)
p02597
s840440228
Accepted
N=int(input()) c=str(input()) rnum=c.count('R') wnum=c.count('W') rnum_front=c.count('R', 0, rnum) wnum_back=c.count('W', N-wnum, N) if rnum > wnum: print(wnum-wnum_back) else: print(rnum-rnum_front)
p02597
s450638732
Accepted
N = int(input()) C = input() White = C.count("W") Red = C.count("R") left_white = 0 left_red = 0 right_white = White right_red = Red ans = Red for n,c in enumerate(C): if c == "W": left_white += 1 right_white -= 1 else: left_red += 1 right_red -= 1 ans = min(ans,max(left_white,right_red)) print(ans)
p02597
s824007881
Accepted
n = int(input()) c = input() r = c.count('R') w = c.count('W') print(c[:r].count('W'))
p02597
s446554328
Accepted
N=int(input()) c=list(input()) W_cnt=c.count("W") R_cnt=c.count("R") wcnt=0 rcnt=0 for n in range(R_cnt): if c[n]=="W": wcnt+=1 for n in range(R_cnt+1,N): if c[n]=="R": rcnt+=1 print(max(wcnt,rcnt))
p02597
s461973706
Accepted
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)
p02597
s498022521
Accepted
n = int(input()) x = list(input()) sx = len(set(x)) if sx == 1: print(0) exit() cnt_r = x.count("R") cnt = 0 for i in range(cnt_r): if x[i] == "W": cnt += 1 print(cnt)
p02597
s887505929
Accepted
from collections import Counter n=int(input()) c=input() d=Counter(c) w,r=Counter(c)["W"], Counter(c)["R"] ans=0 for i in range(r): if c[i]=="W": ans+=1 print(ans)
p02597
s333366985
Accepted
N=int(input()) c=input() left=0 right=N-1 ans=0 if all(c[i]=='R' for i in range(N)): print('0') exit() if all(c[i]=='W'for i in range(N)): print('0') exit() while left<right: if c[left]=='R':#これより左に白石なし left+=1 if c[right]=='W':#これより右に赤石なし right-=1 if c[left]=='W' and c[right]=='R': left+=1 right-=1 ans+=1 print(ans)
p02597
s656152497
Accepted
N = int(input()) c = list(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
s796498939
Accepted
N = int(input()) S = input() r, w = 0, 0 for i in range(N): if S[i] == 'R': r += 1 else: w += 1 res = [0 for _ in range(N+1)] for i in range(1, N+1): if S[i-1] == 'R': res[i] = res[i-1] + 1 else: res[i] = res[i-1] print(r-res[r])
p02597
s354828708
Accepted
def main(): import collections N = int(input()) stones = input() N_red = stones.count('R') N_whi = N - N_red ans = stones[:N_red].count('W') print(ans) if __name__ == '__main__': main()