import sys
input=sys.stdin.readline
N=int(input())
balls=input().strip()
def find_index(color): # 맨 우측과 좌측 중, 볼이 많이 모여있는 곳 찾기
left, right = 0, 0
for i in range(N):
if balls[i] != color: break
left += 1
for i in range(N - 1, -1, -1):
if balls[i] != color: break
right += 1
if left<right:
return find_move(False, right, color) #맨 우측
else:
return find_move(True, left, color) #맨 좌측
def find_move(loc, cnt, color): # 옮길 볼의 개수 구하기
if loc:
return balls[cnt:].count(color)
else:
return balls[:N - cnt].count(color)
red=find_index('R')
blue=find_index('B')
print(red if red<blue else blue)
'IT > coding study' 카테고리의 다른 글
[SWEA] 2115. 벌꿀채취(python) (0) | 2022.09.05 |
---|---|
[acmicpc] 14891. 톱니바퀴(python) (0) | 2022.09.01 |
[acmicpc] 16234. 인구 이동(python) (0) | 2022.07.15 |
[programmers] 삼각 달팽이 (python) (0) | 2022.07.10 |
[acmicpc] 18428. 감시 피하기(python) (0) | 2022.07.01 |