Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created February 8, 2026 07:41
Show Gist options
  • Select an option

  • Save maehrm/4182308d43a79ad36073798f941ee8a5 to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/4182308d43a79ad36073798f941ee8a5 to your computer and use it in GitHub Desktop.
N = int(input())
S = input()
prefixW = [0] * (N + 1) # iまでの白の個数
totalW = 0 # 全体で白が何個あるか
for i in range(N):
prefixW[i + 1] = prefixW[i]
if S[i] == 'W':
prefixW[i + 1] += 1
totalW += 1
ans = N
for i in range(N + 1):
leftW = prefixW[i]
rightR = (N - i) - (totalW - leftW)
ans = min(ans, max(leftW, rightR))
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment