Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

s = input()
q = int(input())
Q = [ list(input().split()) for _ in range(q) ]

# print(Q)

for i in range(q):
    t = int(Q[i][0])
    if t==1:
        s = s[::-1]
    else:
        f = int(Q[i][1])
        if f == 1:
            s = Q[i][2] + s
        else:
            s = s + Q[i][2]

print(s)

### FIXED CODE ###

s = input()
q = int(input())
Q = [ list(input().split()) for _ in range(q) ]

from collections import deque
s = deque(list(s))

count = 0
for i in range(q):
    t = int(Q[i][0])
    if t==1:
        count += 1
    else:
        f = int(Q[i][1])
        new = Q[i][2]
        if count%2==0 and f==1:
            s.appendleft(new)
        elif count%2==0 and f==2:
            s.append(new)
        elif count%2==1 and f==1:
            s.append(new)
        elif count%2==1 and f==2:
            s.appendleft(new)
        else:
            pass

# print(count)

if count%2==0:
    print("".join(s))
    exit()
else:
    s = list(s)[::-1]
    print("".join(s))
    exit()
### BUGGY CODE ###

import numpy as np

n, k = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
arr = np.zeros(n-k+1)

for i in range(k):
    arr += np.array(p[i:n-k+i+1]) / 2

arr += k / 2

print(np.max(arr))


### FIXED CODE ###

def exp(a):
    return (a + 1) / 2

n, k = map(int, input().split())
p = list(map(int, input().split()))

tmp = [0] * (n + 1) 
ans = 0

for i in range(1, n+1):
    if i <= k:
        tmp[i] = tmp[i-1] + exp(p[i-1])
    else:
        tmp[i] = tmp[i-1] - exp(p[i-k-1]) + exp(p[i-1])

print(max(tmp))
### BUGGY CODE ###

from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Ai = [int(x) for x in stdin.readline().rstrip().split()]

    foo = [0] + Ai + [0]
    bar = sum([abs(foo[i] - foo[i + 1]) for i in range(len(foo) - 1)])

    for i in range(N):
        spam = Ai[:]
        del spam[i]
        spam = [0] + spam + [0]

        if foo[i] <= foo[i + 1] <= foo[i + 2] or foo[i + 2] <= foo[i + 1] <= foo[i]:
            print(bar)
        else:
            ham = [abs(spam[i] - spam[i + 1]) for i in range(len(spam) - 1)]
            print(sum(ham))


if __name__ == '__main__':
    main()


### FIXED CODE ###

from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Ai = [int(x) for x in stdin.readline().rstrip().split()]

    foo = [0] + Ai + [0]
    bar = [abs(foo[i] - foo[i + 1]) for i in range(len(foo) - 1)]
    sumbar = sum(bar)

    spam = [0] + Ai + [0]
    for i in range(N):
        if foo[i] <= foo[i + 1] <= foo[i + 2] or foo[i + 2] <= foo[i + 1] <= foo[i]:
            print(sumbar)
        else:
            ans = sumbar - (bar[i] + bar[i + 1]) + abs(spam[i] - spam[i + 2])
            print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
f = [[a] for a in A]
for i in range(N):
    j = 0
    while j < 1<<N:
        j |= 1<<i
        f[j] = sorted(f[j]+f[j^1<<i], reverse=True)[:2]
        j += 1
Ans = [sum(f[1])]
for a, b in f[2:]:
    Ans.append(max(Ans[-1], a+b))
print("\n".join(map(str, Ans)))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
f = [[a] for a in A]
for i in range(N):
    for j in range(1<<N):
        if j & 1<<i:
            f[j] = sorted(f[j]+f[j^1<<i], reverse=True)[:2]
Ans = [sum(f[1])]
for a, b in f[2:]:
    Ans.append(max(Ans[-1], a+b))
print("\n".join(map(str, Ans)))
### BUGGY CODE ###

N = int(input())
Al = input().split()

A = []
for i in range(N):
  A.append(int(Al[i]))

num = 0
ma = 10**9 + 7

for i in range(N):
  for j in range(i+1, N):
    num = (num + A[i]*A[j]) % ma

print(num)


### FIXED CODE ###

N = int(input())
Al = input().split()
A = list( map((lambda x: int(x)), Al))
num = 0
ma = 10**9 + 7
li = 0

for i in range(N-1, 0, -1):
  li += A[i]
  num += A[i-1] * li

num = num % ma
print(num)
### BUGGY CODE ###

s = list(input())
q = int(input())
for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        s = s[::-1]
    else:
        if a[1] == "1":
            s.insert(0,a[2])
        else:
            s.append(a[2])
print(*s,sep="")


### FIXED CODE ###

from collections import deque
s = list(input())
ans = deque(s)
q = int(input())
check = 1
for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        check *= -1
    else:
        if a[1] == "1":
            if check == 1:
                ans.appendleft(a[2])
            else:
                ans.append(a[2])
        else:
            if check == 1:
                ans.append(a[2])
            else:
                ans.appendleft(a[2])
    
ans = list(ans)
if check==1:
    print(*ans,sep="")
else:
    ans = ans[::-1]
    print(*ans,sep="")
### BUGGY CODE ###

import sys

input = sys.stdin.readline

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

d = []
for aa in a[:k]:
    for bb in b[:k]:
        d.append(aa + bb)

d.sort(reverse=True)

e = []
for dd in d[:k]:
    for cc in c[:k]:
        e.append(dd + cc)

e.sort(reverse=True)

print(*e[:k], sep='\n')


### FIXED CODE ###

# https://www.kumilog.net/entry/python-speed-comp#input-%E3%81%A8-sysstdinreadline
# https://teratail.com/questions/88396

from heapq import heapify, heappush, heappop
import sys

input = sys.stdin.readline


class Data:
    def __init__(self, value, indices):
        self.value = value
        self.indices = indices

    def __lt__(self, other):
        return self.value < other.value


X, Y, Z, K = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
c = map(int, input().split())

a = list(sorted(a, reverse=True))
b = list(sorted(b, reverse=True))
c = list(sorted(c, reverse=True))

hq = []
heapify(hq)

t = a[0] + b[0] + c[0]
t *= -1

d = Data(t, (0, 0, 0))

heappush(hq, d)

dtpls = ((1, 0, 0), (0, 1, 0), (0, 0, 1))

st = set()

cnt = 0
for _ in range(K):
    d = heappop(hq)
    print(-d.value)
    for dtpl in dtpls:
        na = d.indices[0] + dtpl[0]
        if na >= X: continue
        nb = d.indices[1] + dtpl[1]
        if nb >= Y: continue
        nc = d.indices[2] + dtpl[2]
        if nc >= Z: continue

        nt = a[na] + b[nb] + c[nc]
        nt *= - 1

        ntpl = (na, nb, nc)
        if ntpl in st: continue
        heappush(hq, Data(nt, ntpl))
        st.add(ntpl)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(200000)
n, m = list(map(int, input().split()))
def cutterl(l, lst) :
    if lst == [] :
        return []
    elif lst[0] < l :
        return cutterl(l, lst[1:])
    else :
        return lst
def cutterr(r, lst) :
    if lst == [] :
        return []
    elif r < lst[-1] :
        return cutterr(r, lst[:-1])
    else :
        return lst
nlist = list(map(lambda x : x + 1, range(n)))
llist=[]
rlist=[]
for i in range(m) :
    l, r = list(map(int, input().split()))
    llist.append(l)
    rlist.append(r)
nlist = cutterl(max(llist), nlist)
nlist = cutterr(min(rlist), nlist)
print(len(nlist))

### FIXED CODE ###

n, m = list(map(int, input().split()))
llist = []
rlist = []
for i in range(m) :
    l, r = list(map(int, input().split()))
    llist.append(l)
    rlist.append(r)
ll = max(llist)
rr = min(rlist)
print(max(0, min(rr, n)-ll+1))
### BUGGY CODE ###

from copy import deepcopy

a,b,n = [int(i) for i in input().split()]

score = 0
if a * n / b < 1:
    print(0)
    exit()

for i in range(n+1):
    tmp = int(a * i / b) - a * int(i / b)
    if score <= tmp:
        score = deepcopy(tmp)
    else:
        print(score)
        exit()
print(score)

### FIXED CODE ###


a,b,n = [int(i) for i in input().split()]

score = 0

if n < b:
  print(int(a * n / b) - a * int(n / b))
else:
  n = b-1
  print(int(a * n / b) - a * int(n / b))
### BUGGY CODE ###

n, k = map(int, input().split())

if k == 1:
    print(0)
    exit()

low = 10**19
while True:
    tmp = abs(n-k)
    if tmp < low:
        low = tmp
        n = tmp
    else: break

print(low)

### FIXED CODE ###

n, k = map(int, input().split())

if k == 1:
    print(0)
    exit()
    
if n > k:
    n = n%k
    print(min(n, abs(n-k)))
else:
    print(min(n, abs(n-k)))
### BUGGY CODE ###

import math
import numpy

N , Y = map(int, input().split())
conc = True
a_ = Y // 10000
for i in range(a_ + 1):
	a = i
	b_ = (Y - 10000*a) // 5000
	for k in range(b_ + 1):
		b = k
		if ((Y - 10000*a - 5000*b) % 1000) == 0:
			c = int((Y - 10000*a - 5000*b) / 1000)
			if conc:
				if (a + b + c) == N:
					print(str(a) +" "+ str(b) + " " + str(c))
					conc = False
if conc:
	print("-1 -1 -1")

### FIXED CODE ###

N, Y = map(int, input().split())

flag = True

for i in range(Y // 10000 + 1):
    for k in range((Y - 10000*i) // 5000 + 1):
        l = int((Y - 10000*i - 5000*k) / 1000)
        if (i + k + l) == N:
            print(str(i) + " " + str(k) + " " + str(l))
            flag = False
            break
    if flag == False:
        break
if flag:
    print("-1 -1 -1")
### BUGGY CODE ###

#
import sys
import math
import itertools

# 整数をいくつか入力
n,k = (int(i) for i in input().split())


lr = [[int(i) for i in input().split()] for i in range(k)] 

dp  = [0] * (n+1)
ans = [0] * (n+1)
dp[1]=1
ans[1]=1

for i in range(2,n+1):
    for a in lr:
        if a[0] < i:
            dp[i] += ans[i-a[0]]
            if a[1] < i-1:
                dp[i] -= ans[i-a[1]-1]
    ans[i]=ans[i-1]+dp[i]

print(dp[n]%998244353)



### FIXED CODE ###

#
import sys
import math
import itertools

# 整数をいくつか入力
n,k = (int(i) for i in input().split())


lr = [[int(i) for i in input().split()] for i in range(k)] 

dp  = [0] * (n+1)
ans = [0] * (n+1)
dp[1]=1
ans[1]=1

for i in range(2,n+1):
    for a in lr:
        if a[0] < i:
            dp[i] += ans[i-a[0]]
            if a[1] < i-1:
                dp[i] -= ans[i-a[1]-1]
    dp[i] = dp[i] % 998244353
    ans[i]=ans[i-1]+dp[i]

print(dp[n]%998244353)
### BUGGY CODE ###

import math
from collections import deque

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
g = [[] for _ in range(N)]
for a, b in AB:
    g[a-1].append(b-1)

q = deque([(i, [i]) for i in range(N)])
min_loop = (math.inf, [])
while len(q) > 0:
    node, path = q.pop()
    for to_node in g[node]:
        if to_node in path:
            if min_loop[0] > len(path):
                min_loop = (len(path), path)
        else:
            q.append((to_node, path + [to_node]))
if min_loop[0] == math.inf:
    print(-1)
else:
    print(min_loop[0])
    for node in min_loop[1]:
        print(node+1)


### FIXED CODE ###

import math
import sys
from collections import deque, defaultdict

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
g = [set() for _ in range(N)]
for a, b in AB:
    g[a - 1].add(b - 1)


def find_loop(s, subnode):
    q = deque([(s, {s})])
    visited = defaultdict(lambda: math.inf)
    while len(q) > 0:
        node, p = q.popleft()
        for to_node in g[node] & subnode:
            if to_node == s:
                return p
            if visited[to_node] > len(p):
                visited[to_node] = len(p)
                q.append((to_node, p | {to_node}))
    return -1


V = set(range(N))
for i in range(N):
    subnode = find_loop(i, V)
    if subnode != -1:
        break
if subnode == -1:
    print(-1)
    sys.exit()


while True:
    # 条件判定
    flg = True
    for i in subnode:
        if len(g[i] & subnode) != 1:
            flg = False
            s = i
            break
    if flg:
        break
    subnode = find_loop(s, subnode)

print(len(subnode))
for node in subnode:
    print(node+1)
### BUGGY CODE ###

# numpyで書換えた
import numpy as np

def main():
    MOD = 998244353

    N, S = map(int, input().split())
    A = tuple(map(int, input().split()))

    DP = np.array([[[0] * 3 for _ in range(S + 1)] for _ in range(N + 1)], dtype = np.int64)
    DP[0, 0, 0] = 1

    for i in range(N):
        DP[i + 1, :, :] = DP[i, :, :] 
        DP[i + 1, 0, 1] = DP[i, 0, 0] + DP[i, 0, 1]
        a = A[i]
        if a > S:
            DP[i + 1, 1:, 1] = DP[i, 1:, 1] #以前から合計jになっている場合のみOK
        else:
            DP[i + 1, 1:a, 1] = DP[i, 1:a, 1] #以前から合計jになっている場合のみOK
            DP[i + 1, a: S + 1, 1] = (DP[i, a: S + 1, 1] + DP[i, :S - a + 1, 0] + DP[i, :S - a + 1, 1]) % MOD
            
        DP[i + 1, S, 2] = (DP[i, S, 1] + DP[i, S, 2])
        if a <= S:
            DP[i + 1, S, 2] += DP[i, S - a, 0] + DP[i, S - a, 1]
        DP[i + 1, S, 2] %= MOD

    print (DP[N, S, 2])

    # for i in range(N + 1):
    #     print (DP[i])

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    MOD = 998244353

    N, S = map(int, input().split())
    A = tuple(map(int, input().split()))

    DP0 = [[0] * (S + 1) for _ in range(N + 1)]
    DP1 = [[0] * (S + 1) for _ in range(N + 1)]
    DP2 = [[0] * (S + 1) for _ in range(N + 1)]

    DP0[0][0] = 1

    for i in range(N):
        DP0[i + 1][0] = DP0[i][0] 
        DP1[i + 1][0] = DP0[i][0] + DP1[i][0]
        a = A[i]
        if a > S:
            for j in range(1, S + 1):
                DP1[i + 1][j] = DP1[i][j] #以前から合計jになっている場合のみOK
        else:
            for j in range(1, a):
                DP1[i + 1][j] = DP1[i][j] #以前から合計jになっている場合のみOK
            for j in range(a, S + 1):
                DP1[i + 1][j] = (DP1[i][j] + DP0[i][j - a] + DP1[i][j - a]) % MOD
                # DP[i + 1][j][1] = (DP[i][j][0] + DP[i][j][1] + DP[i + 1][j - a][1]) % MOD

        DP2[i + 1][S] = (DP1[i][S] + DP2[i][S])
        if a <= S:
            DP2[i + 1][S] += DP0[i][S - a] + DP1[i][S - a]
        DP2[i + 1][S] %= MOD

    print (DP2[N][S])

    # for i in range(N + 1):
    #     print (DP[i])

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys

n, q = map(int, input().split())
sys.setrecursionlimit(2 * (10 ** 5))

adj_list = [[] for _ in range(n + 1)]

for i in range(n - 1):
    u, v = map(int, input().split())
    adj_list[u].append(v)
    adj_list[v].append(u)

val = [0] * (n + 1)
visited = [False] * (n + 1)

for i in range(q):
    p, x = map(int, input().split())
    val[p] += x


def dfs(val, adj_list, visited, cur, prev):
    if prev != -1:
        val[cur] += val[prev]

    visited[cur] = True

    for next in adj_list[cur]:
        if visited[next] is False:
            dfs(val, adj_list, visited, next, cur)


dfs(val, adj_list, visited, 1, -1)

for i in range(n):
    print(val[i + 1], end="")
    if i != n - 1:
        print(" ", end="")
    else:
        print()


### FIXED CODE ###

from collections import deque

n, q = map(int, input().split())

adj_list = [[] for _ in range(n + 1)]
val = [0] * (n + 1)
visited = [False] * (n + 1)

for i in range(n - 1):
    u, v = map(int, input().split())
    adj_list[u].append(v)
    adj_list[v].append(u)

for i in range(q):
    p, x = map(int, input().split())
    val[p] += x

dq = deque()
prev = -1
cur = 1
dq.append([cur, prev])

while len(dq) > 0:

    cur, prev = dq.popleft()
    if prev != -1:
        val[cur] += val[prev]
    visited[cur] = True

    for next in adj_list[cur]:
        if visited[next] is False:
            dq.append([next, cur])

print(*val[1:])
### BUGGY CODE ###

def turn(S,l,r):
    S1=S[:l]
    S2=S[l:r+1][::-1]
    S3=S[r+1:]
    S2=S2.replace('L',' ')
    S2=S2.replace('R','L')
    S2=S2.replace(' ','R')
    return S1+S2+S3

def score(S):
    ans=0
    for i in range(N):
        if((i<N-1 and S[i]==S[i+1]=='R') or (i>0 and S[i]==S[i-1]=='L')):
            ans+=1
    return ans

N,K=map(int,input().split())
S=input()

for i in range(K):
    l=r=-1
    for j in range(1,N-1):
        if S[j]!=S[0]:
            l=j
            break
    for k in range(l+1,N-1):
        if S[k]==S[0]:
            r=k-1
            break
    if l==r==-1:
        break
    elif r==-1:
        S=turn(S,l,N-1)
    else:
        S=turn(S,l,r)

print(score(S))

### FIXED CODE ###

import bisect

def turn(S,l,r):
    S1=S[:l]
    S2=S[l:r+1][::-1]
    S3=S[r+1:]
    S2=S2.replace('L',' ')
    S2=S2.replace('R','L')
    S2=S2.replace(' ','R')
    return S1+S2+S3

def score(S):
    ans=0
    for i in range(N):
        if((i<N-1 and S[i]==S[i+1]=='R') or (i>0 and S[i]==S[i-1]=='L')):
            ans+=1
    return ans

N,K=map(int,input().split())
S=input()
L=[];R=[]
c0=S[0]

for i in range(1,N):
    c=S[i]
    if c0!=c=='L':
        L.append(i)
    elif c0!=c=='R':
        R.append(i)
    c0=c

lenL,lenR=len(L),len(R)

for i in range(K):
    if i<min(lenL,lenR):
        S=turn(S,min(L[i],R[i]),max(L[i],R[i])-1)
    elif i==min(lenL,lenR)<max(lenL,lenR):
        if lenL>lenR:
            S=turn(S,L[lenL-1],N-1)
        elif lenL<lenR:
            S=turn(S,R[lenR-1],N-1)
    else:
        break

print(score(S))
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

m=max(a)
b=a[:]
b.remove(m)
m2=max(b)

for j in a:
    if j==m and a.count(m)>1:
        print(m)
    elif j==m and a.count(m)==1:
        print(m2)
    else:
        print(m)

### FIXED CODE ###

n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
m=sorted(l)
m1=m[-1]
m2=m[-2]
c=l.count(m1)

for j in l:
    if j==m1:
        if c>1:
            print(m1)
        else:
            print(m2)
    else:
        print(m1)
### BUGGY CODE ###

import math
N = int(input())
z = 0
for a in range(N):
    for b in range(math.floor(N/(a+1))):
        c = N - (a+1)*(b+1)
        if c > 0:
            z = z+1
        else:
            pass
print(z)

### FIXED CODE ###

import math
N = int(input())
z = 0
for a in range(N):
    for b in range(min(a,math.floor(N/(a+1)))):
        if N - (a+1)*(b+1) > 0:
            z = z+2
        else:
            pass
    if N - (a+1)*(a+1) > 0:
        z = z+1
    else:
        pass
print(z)
### BUGGY CODE ###

n=int(input())
s=input()
print(min(s[:i].count('#')+s[i:].count('.') for i in range(n+1)))

### FIXED CODE ###

N=int(input())
S=input()
b=0
w=S.count(".")
ans=b+w
for s in S:
    if s=="#":
        b+=1
    else:
        w-=1
    ans=min(ans, b+w)
print(ans)
### BUGGY CODE ###

n = int(input())
seq = [x for x in input().split(' ')]

b = []

for i in range(n):
    curr = seq[i]
    b.append(curr)
    c = b[i::-1]
    b = c

print(' '.join(b))

### FIXED CODE ###

n = int(input())
seq = [x for x in input().split(' ')]

b = []

if n % 2 == 0:
    for j in range(n-1, -1, -2):
        b.append(seq[j])
    for i in range(0, n, 2):
        b.append(seq[i])

else:
    for j in range(n-1, -1, -2):
        b.append(seq[j])
    
    for i in range(1, n, 2):
        b.append(seq[i])

print(' '.join(b))
### BUGGY CODE ###

import heapq
INFTY = 10**12
def dist(cur,b):
    d = [INFTY for _ in range(N)]
    d[cur[1]] = 0
    hist = [0 for _ in range(N)]
    hist[cur[1]] = 1
    heap = [cur]
    while heap:
        cur = heapq.heappop(heap)
        hist[cur[1]] = 1
        for x in B[cur[1]]:
            if hist[x[1]]==0:
                if d[x[1]]>cur[0]+x[0]:
                    d[x[1]] = cur[0]+x[0]
                    heapq.heappush(heap,(d[x[1]],x[1]))
    return d[b]
N = int(input())
A = {(i,j):INFTY for i in range(N) for j in range(N)}
for i in range(N):
    row = list(map(int,input().split()))
    for j in range(N):
        A[(i,j)] = row[j]
G = list(A.items())
G = sorted(G,key=lambda x:x[1])
B = {i:[] for i in range(N)}
ind = 0
for x in G:
    a,b = x[0][0],x[0][1]
    d = x[1]
    if d>0:
        dmin = dist([0,a],b)
#         print("dmin({},{})={}".format(a,b,dmin))
        if dmin>d:
            if (d,b) not in B[a]:
                B[a].append((d,b))
            if (d,a) not in B[b]:
                B[b].append((d,a))
        elif d>dmin:
            ind = 1
            break
#         print("B={}".format(B))
if ind==1:
    print(-1)
else:
    cnt = 0
    for a in B:
        for x in B[a]:
            cnt += x[0]
    print(cnt//2)

### FIXED CODE ###

N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        amin = 10**10
        for k in range(N):
            if k!=i and k!=j:
                amin = min(amin,A[i][k]+A[k][j])
        if A[i][j]>amin:
            cnt = -1
            break
        elif A[i][j]<amin:
            cnt += A[i][j]
    if cnt==-1:break
print(cnt)
### BUGGY CODE ###

from functools import reduce

n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

ans = 0
for x in a:
    ans += (reduce(lcm, a) - 1) % x

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

m = 1
for i in a:
  m *= i

ans = 0
for i in a:
  ans += (m-1) % i

print(ans)
### BUGGY CODE ###

import math
K = int(input())
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            n = math.gcd(i, math.gcd(j, k))
            ans += n
print(ans)

### FIXED CODE ###

import math
from functools import reduce
K = int(input())
ans = 0
for i in range(1, K-1):
    for j in range(i+1, K):
        for k in range(j+1, K+1):
            n = math.gcd(i, math.gcd(j,k))
            ans += 6*n
for i in range(1, K+1):
    for j in range(i+1, K+1):
        n = math.gcd(i,j)
        ans += 6*n
print(ans+sum(list(i for i in range(K+1))))
### BUGGY CODE ###

MOD = 10**9 + 7
s = input()
now = [0] * 13
now[0] = 1
k = 1
for c in reversed(s):
    nxt = [0] * 13
    if c == '?':
        for i in range(10):
            a = k * i % 13
            for j in range(13):
                nxt[(j + a) % 13] += now[j]
                nxt[(j + a) % 13] %= MOD
    else:
        i = int(c)
        a = k * i % 13
        for j in range(13):
            nxt[(j + a) % 13] += now[j]
            nxt[(j + a) % 13] %= MOD
    now = nxt
    k = k * 10 % 13
print(now[5])


### FIXED CODE ###

MOD = 10**9 + 7
s = input()
now = [0] * 13
now[0] = 1
k = 1
for c in reversed(s):
    nxt = [0] * 13
    if c == '?':
        for i in range(10):
            a = k * i % 13
            for j in range(13):
                nxt[(j + a) % 13] += now[j]
                nxt[(j + a) % 13] %= MOD
    else:
        i = int(c)
        a = k * i % 13
        for j in range(13):
            nxt[(j + a) % 13] += now[j]
            nxt[(j + a) % 13] %= MOD
    now = nxt
    k = k * 10 % 13
print(now[5])
### BUGGY CODE ###

import numpy as np
N = int(input())
string = np.zeros(N)
ans = 0
for i in range(N):
    mozi = input()
    for k in range(10):
        string[i] += (ord(mozi[k])-96)**10

string_new = sorted(string)
for j in range(N-1):
    index = j + 1
    while string_new[j] == string_new[index]:
        ans += 1
        index += 1
        if index >= N:
            break

print(ans)


### FIXED CODE ###

N = int(input())
string = [0] * N
ans = 0
for i in range(N):

    mozi = input()
    for k in range(10):
        string[i] += (ord(mozi[k])-96)**10

string_new = sorted(string)
ite = 0
index = 0
while ite < N-1:
    index = ite + 1
    while string_new[ite] == string_new[index]:
        #print(ite, index)
        ans += index-ite
        index += 1

        if index >= N:
            break
    ite = index
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
    n = int(input())
    a = input()
    if not 'WR' in a:
        print(0)
        sys.exit()
    a = list(a)
    r = 0
    rnum = a.count('R')
    while True:
        if 'W' in a[:rnum]:
            t1 = a[:rnum].index('W')
            t2 = a[rnum:].index('R')
            a[t1] = 'R'
            a[t2+rnum] = 'W'
            r += 1
        else:
            break
    print(r)

if __name__ == '__main__':
    main()

### FIXED CODE ###

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()