peterverebics/CodeNet_Python_118 huggingface dataset:
X, K, D = map(int, input().strip().split())
res = 0

if X < 0:
    X *= -1

res = X
for i in range(K):
    X -= D
    if (i + 1) % 2 != K % 2:
        continue
    if X < 0:
        if res > abs(X):
            res = abs(X)
        break
    res = X

print(res)
a=input().split(" ")
b=[x,k,d]= [int(a[0]),int(a[1]),int(a[2])]  
ans = 0
if x - k*d > 0:
  ans = x - k*d
elif x + k*d < 0:
  ans = k*d -x
else:
  if k%2==0:
    ans= x%(2*d)
    if d<x%(2*d):
      ans= 2*d-x%(2*d)
  elif k%2==1:
    ans= (x+d)%(2*d)
    if d<(x+d)%(2*d):
      ans= 2*d-(x+d)%(2*d)
print(ans)
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations

# input = sys.stdin.readline

X, K, D = map(int, input().split())
X = abs(X)
Xs = X // D
Xm = X % D
if K < Xs:
#     print("A")
    print(abs(X-K*D))
elif Xm == 0:
    if K % 2 == 0:
        print(D)
    else:
        print(0)
elif Xm / 2 > K:
#     print("B")
    print(abs(D-Xm))
else:
    print(abs(D-K))
X, K, D = map(int, input().split())

if X < 0:
    X = -X

for i in range(K):
    X -= D    
    if(X < D):
        if(i % 2 == 1):
            break
        elif(X < 0):
            X += D
            break
        else:
            X -= D
            break 

print(abs(X))
x, k, d = map(int, input().split())
a = 0
b = k + 1
mid = 0
if x < 0:
    x *= -1
while b - a > 1:
    mid = (a + b) >> 1
    if x - d * mid >= 1:
        a = mid
    else:
        b = mid

ans = x - a * d
if a < k:
    y = abs(ans - d)
    if y < ans:
        ans = y
if x == 0:
    ans = d
print(ans)
[_x, _k, _d] = list(map(int, input().split(" ")))
_x = abs(_x)

if _x >= _d:
  _y = _x//_d
  if _k > _y:
    _y = _k
  _x = abs(_x - _d * _y)
  _k -= _y
if _k % 2 == 1:
  _x = abs(_x - _d)

print(_x)
x,k,d=map(int,input().split())
x=abs(x)
i=0
while x>0 and k>i:
    x=x-d
    i+=1
    if i>=k:
        print(x)
    elif i<k:
        if (k-i)%2==0:
            print(abs(x))
        else:
            print(abs(x+d))
import math
X,K,D = map(int,input().split())
dist = abs(X)
rem = K
D = abs(D)
count = min(math.floor(X/D),K)
dist = dist - count*D
rem = K - count
if rem % 2 == 1:
  dist = dist - D
ans = abs(dist) 
print(ans)
def cal(x,f, k ,d):
    return x+(((2*f)-k)*d)
[x, d, k]=list(map(int, input().split()))
low=1
high=k
mini=1000000000000000000
curr=abs(cal(x, k , k, d))
while low<=high:
    mid=low+(high-low)//2
    new=cal(x, mid, k ,d)
    if abs(new)>abs(curr):
        low=mid+1
    else:
        high=mid-1
    curr=abs(new)
    mini=min(abs(new), mini)
print(mini)
a,b,c=map(int, input().split()) 
k = b*c

if abs(a) > 0:
    l = abs(a)
    if l > k:
        print(l-k)
    if l == k:
        print(0)
    if l < k:
        d = int(l//c)
        e = b - d
        if e%2== 0:
            print(l-c*d)
        else:
            print((c*d)+c -l)
if a == 0:
    if b%2==0:
        print(c)
    else:
        print(0)
x, k, d = map(int,input().split())

x = abs(x)
e = round(x / d)
output = 0

a = k - e
a = a%2


if e >= k:
    output = x - (k * d)
    # print('abc',1)
elif a == 1:
    output = x - ((e + 1) * k)
    # print('abc',2)
elif a == 0:
    output = x - (e * d)
    # print('abc',3)

print(abs(output))
X,K,D=map(int,input().split())
if X<=D and K%2==0:
    print(abs(X))
elif X<=D and K%2==1:
    print(abs(D-X))
elif X>D:
    if abs(X)>K*D:
        print(abs(abs(X)-K*D))
    else:
        t=abs(X)//D
        print(min(abs(abs(X)-D*t),abs(abs(X)-D*(t+1))))
x,k,d=map(int,input().split())
ans=0
if x//d>=k:
    ans=x-d*k
else:
    if ((x//d)%2==0 and k%2==0) or ((x//d)%2==1 and k%2==1):
        ans=x%d
    else:
        ans=abs(x%d-d)
print(ans)
x, k ,d = map(int, input().split())


if k >= x//d:
    k -= abs(x)//d
    if x >= 0:
        diff = abs(x-d*(x//d))
    else:
        diff = abs(x-d*(x//d))
    
    if k % 2 == 0:
        print(diff)
    else:
        print(abs(diff-d))
else:
    if x >= 0:
        print(abs(x-k*d))
    else:
        print(abs(x+k*d))
x, k, d = list(map(int,input().split()))
ans = 0
if x >= k * d:
  ans = x - k * d
else:
  ans = x - (x // d) * d
  if abs(ans - d) < ans:
    ans = abs(ans - d)
  else:
    pass
print(ans)
X,K,D=map(int,input().split())
Y=X%D
if abs(X)-K*D>0:
    ans=abs(X)-K*D
else:
    Z=(K-abs(X)//D)%2
    if Z==0:
        ans=Y
    else:
        ans=Y-D
print(abs(ans))
X,K,D=map(int, input().split())
s=X
if X<0:
  s=X*(-1)
for i in range(K):
  a=X+i*D-(K-i)*D
  if a<0:
    a=a*(-1)
  if a<s:
    s=a
print(s)
X,K,D = map(int,input().split())
a=X//D
if(a<=K):
    X=X-(D*a)
    K=K-a
    if(K%2==0):
        print(X)
    else:
        print(min(abs(X-D),abs(X+D)))
else:
    print(X-(D*K))
X,K,D=map(int,input().split())
if X>=K*D :
  print(X-K*D)
else :
  for i in range(K) :
    if X>0 :
      X-=D
    elif X<0 :
      X+=D
    else :
      if K%2==0 :
        print(D)
        exit()
      else :
        print(0)
        exit()
x, k, d = list(map(int, input().split()))

direction = -1 if x > 0 else 1

move_counter = 1 if (k % 2) == 1 else 2

min_abs = abs(x)

while True:
    moved_x = x + (direction * d * move_counter)

    if abs(moved_x) < min_abs:
        min_abs = abs(moved_x)
    else:
        break

print(min_abs)
x,k,d = map(int,input().split())
ans = 0

if x>0 and x-k*d>0:
  ans = x-k*d

elif x<0 and x+k*d>0:
  ans = x+k*d

else:
  if x < 0:
    x = -x

  if (k-(x//d))%2 == 0: #右
    ans = x-(x//d)*d    
  else:
    ans = abs(x-(x//d+1)*d)

print(ans)
X,  K,  D = list(map(int, input().split()))
L = X + D * K

if L >= 0:
   if L / (2 * D) - int(L / (2 * D)) > 0.5:
      ans = int(L / (2 * D)) + 1
   else:
      ans = int(L / (2 * D))

elif L < 0:
   if L / (2 * D) - int(L / (2 * D)) < -0.5:
      ans = int(L / (2 * D)) - 1
   else:
      ans = int(L / (2 * D))
print(ans)
x,k,d=map(int, input().split())
x=abs(x)

if x+d >=k*d:
    print(abs(x-k*d))
    exit()

if k%2==1:
    x=x-d

kaisu=int(x/(2*d))
ans=abs(x-kaisu*d*2)
print(ans)
x, k, d = map(int, input().split())
if k % 2 == 1:
    x = abs(x) - d
    k -= 1
else:
    x = abs(x)
if abs(x) - d * k <= 0:
    temp = x % (d * 2)
    print(min(temp, d * 2 - temp))
else:
    print(x - d * k)
#!/usr/bin/env python3
import collections as cl
import sys


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 main():
    x, k, d = MI()

    min_idou = x // d
    amari = x % d

    if min_idou >= k:
        print(x - k*d)
        return

    k -= min_idou
    if k % 2 == 0:
        print(amari)
    else:
        print(-1*(amari - d))


main()
x, k, d = [int(x) for x in input().split(' ')]

q = x // d
r = x % d

if k >= q:
    if k%2 == q%2:
        print(r)
    else:
        print(d - r)
else:
    print(x - d*k)
x, k, d = map(int,input().split())

# mを得るために必要な最小の移動回数
n = abs(x) // d

if k <= n:
    print(abs(x) - k * d)
    exit()

k -= n

x = x % d

if x > abs(x - d):
    x = x - d
    k -= 1

if k % 2 == 0:
    print(abs(x))
else:
    print(min(abs(x - d), abs(x + d)))
x, k, d = map(int, input().split())
if abs(x) > k * d:
    print(abs(x) - k * d)
else:
    a = abs(x) % d
    b = a - d
    if (k - (abs(x) // d)) % 2 == 1:
        print(abs(abs(x) % d - d))
    else:
        print(min(abs(a), abs(b)))
#C
x,k,d=map(int,input().split())
if abs(x)-k*d<d:
    print(min(abs(x)%d,d-abs(x)%d))
else:
    print(abs(x)-k*d)
# coding: utf-8
import math
X, K, D = list(map(int, input().split(" ")))

x = abs(X)
k = int(math.floor(x/D))
if X==K==D:
    print(X)
    exit()
elif k>=K:
    print(abs(x - K*D))
    exit()
x -= k*D
if K%2==0:
    print(abs(x))
else:
    print(abs(x - D))
import sys
input = sys.stdin.readline
x,k,d=map(int,input().split())
x=abs(x)
if x<d:
    print(min(abs(x-d),x))
    sys.exit()

val = x//d

if val>k:
    x-=(k*d)
    print(x)
    sys.exit()

x-=(val*d)
k-=val
if k&1==0:
    print(x)

else:
    ans = min(x+d,abs(x-d))
    print(ans)
import math
X,K,D = map(int,input().split())
dist = abs(X)
rem = K
count = min(math.floor(X/D),K)
dist = dist - count*D
rem = K - count
if rem > 0:
  if rem % 2 == 1:
    dist = dist - D
ans = abs(dist) 
print(ans)
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)
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)
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)
#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)
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"))
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)
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))
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)
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))
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)
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)
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)
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)
n = int(input())
stone = input()
r = stone.count("R")
print(stone.count("W", 0, r))
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)
N=int(input())
c=input()
print(c[:c.count('R')].count('W'))
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)
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)
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)
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))
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)
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)
n = int(input())
c = input()
r = c.count('R')
print(c[:r].count('W'))
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)
n = int(input())
s = input()
num = s.count("R")
L = s[:num]
ans = L.count("W")
print(ans)
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)
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)
n = int(input())
s = input()

r=s.count('R')
ans=r

for i in range(r):
  if s[i]=='R':
    ans-=1
    
print(ans)
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)
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))
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)
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))
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)
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()
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)
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)
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()))
# 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)
def main():
    n = int(input())
    C = input()
    r = C.count('R')
    print(C[:r].count('W'))

if __name__ == '__main__':
    main()
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)
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)
# 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"])
n=int(input())
c=input()
d=c.count("R")
e=c[:d].count("R")
print(d-e)
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)
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)
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)
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)
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)
n = int(input())
A = list(input())

r = A.count("R")

ans = A[:r].count("W")

print(ans)
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)
n=int(input())
c=input()
r=c.count("R")
r_1=c[:r].count("R")
ans=r-r_1
print(ans)
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))
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]))
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)
n = int(input())
c = list(input())
ans = 0
for i in range(c.count("R")):
    if c[i] == "W":
        ans += 1
print(ans)
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))
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)
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)
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)
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)
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)
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)
n = int(input())
c = input()
print(c[:c.count("R")].count("W"))
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)
#!/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)
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)
N = int(input())
C = list(input())

RC = C.count("R")
WC = C.count("W")

print(C[:RC].count("W"))
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);
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()
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"))
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)
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)
# -*- coding: utf-8 -*-
n = int(input())
s = list(input())
if s.count("W") == 0:
    print(0)
    exit()
print(s[:s.count('R')].count("W"))
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)
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)