Harryxun/stf_run huggingface dataset:
T = int(intput())

def solve(N, A, B, C, D):
  def pay(x, coin=0):
    if x == 0:
      return 0
    out1 = x/2 if x%2==0 else float('inf')
    out2 = x/3 if x%3==0 else float('inf')
    out3 = x/5 if x%5==0 else float('inf')
    out4 = x+1 if x%8==0 else float('inf')
    out5 = x-1 if x%8==0 else float('inf')
    return min(pay(out1, coin+A), pay(out2, coin+B), pay(out3, coin+C), pay(out4, coin+D), pay(out5, coin+D))
  return pay(N)

for _ in range(T):
  N, A, B, C, D = map(int, input().split())
  print(solve(N, A, B, C, D))

### FIXED CODE ###

T = int(input())
for _ in range(T):
  N,a,b,c,d = map(int, input().split())
  
  memo = {}
  def solve(n):
    if n == 0:
      return 0
    if n == 1:
      return d
    if n in memo:
      return memo[n]
    tmp = n * d
    if n % 2 == 0:
      tmp = min(tmp, a + solve(n//2))
    else:
      tmp =  min(tmp, a + d + solve(n//2), a + d + solve(n//2+1))
    if n % 3 == 0:
      tmp = min(tmp, b + solve(n//3))
    else:
      ret1 = n % 3
      ret2 = 3 - ret1
      tmp = min(tmp, b + d*ret1 + solve(n//3), b + d*ret2 + solve(n//3+1))
    if n % 5 == 0:
      tmp = min(tmp, c + solve(n//5))
    else:
      ret1 = n % 5
      ret2 = 5 - ret1
      tmp = min(tmp, c + d*ret1 + solve(n//5), c + d*ret2 + solve(n//5+1))
    memo[n] = tmp
    return memo[n]
    
  print(solve(N))
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        print(c,tr)
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:return False
    else:return True
    
n,k = input().split()
w = []
w = deque()
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    print("p",p)
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1

### FIXED CODE ###

from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break
import sys

X, Y = map(int, input().split())
ans = 'No'
if X[0] > 100 or X[1] > 100:
  print(ans)
  sys.exit()
if X[1] > X[0]*4 or X[1] < X[0]*2:
  print(ans)
  sys.exit()
if X[1] % 2 == 1:
  print(ans)
  sys.exit()

for a in range(X + 1):
 b = X - a
 if 2 * a + 4 * b == Y:
 ans = 'Yes'
 print(ans)


### FIXED CODE ###

import sys

X, Y = map(int, input().split())
ans = 'No'
if X > 100 or Y > 100:
  print(ans)
  sys.exit()
if Y > X*4 or Y < X*2:
  print(ans)
  sys.exit()
if Y % 2 == 1:
  print(ans)
  sys.exit()

for a in range(X + 1):
  b = X - a
  if 2 * a + 4 * b == Y:
    ans = 'Yes'
    print(ans)
D,T,S=map(int,input())
if D*S>T :
	print("No")
else:
	print("Yes")

### FIXED CODE ###

D,T,S=map(int,input().split())
if (D/S)>T:
	print("No")
else:
	print("Yes")
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

f = 0
ff = 0
num = 12
if int(s[:2]) > num or int(s[:2]) == 0:
    f = 1
if int(s[2:]) > num or int(s[2:]) == 0:
    ff = 1

if f == 0 and ff == 0:
    print("AMBIGUOUS")
elif f == 1 and ff == 0:
    print("YYMM")
elif f == 0 and ff == 1:
    print("MMYY")
elif f == 1 and ff == 1:
    print("NA")

### FIXED CODE ###

import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

f = 0
ff = 0
num = 12
if int(s[:2]) > num or int(s[:2]) == 0:
    f = 1
if int(s[2:]) > num or int(s[2:]) == 0:
    ff = 1

if f == 0 and ff == 0:
    print("AMBIGUOUS")
elif f == 1 and ff == 0:
    print("YYMM")
elif f == 0 and ff == 1:
    print("MMYY")
elif f == 1 and ff == 1:
    print("NA")
n=int(input())

D=[]

for i in range(n):
  d=int(input())
  D.append(d)

print(collections.Counter(D))  
  
  

### FIXED CODE ###

n=int(input())

D=[]

for i in range(n):
  d=int(input())
  D.append(d)

c=set(D)

  
print(len(c))
N = int(input())
A = map(int, input().split())

pairs = []

for i in A:
    if A[A[i] - 1] = i + 1:
        pairs.append(1)

print(len(pairs) // 2)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

pairs = []

for i in range(len(A)):
    if A[A[i] - 1] == i + 1:
        pairs.append(1)

print(len(pairs) // 2)
n, m = list(map(int, input().split()))
tmp = [[0 for i in range(1)] for j in range(m)]
pys = []
for i in range(0, m):
    p, y = list(map(int, input().split()))
    tmp[p].append(y)
    pys.append([p, y])

print(tmp)

ttmp = [[0 for i in range(1)] for j in range(m)]

for i in range(m):
    ttmp[i] = sorted(tmp[i])

print(ttmp)

for py in pys:
    p, y = py
    yindex = ttmp[p].index(y)
    print('{:06}'.format(p) + '{:06}'.format(yindex))

### FIXED CODE ###

n, m = list(map(int, input().split()))
tmps = [[] for _ in range(n)]
pyxs = []

for i in range(m):
    p, y = list(map(int, input().split()))
    pyxs.append([p, y, i])

pyxs.sort(key = lambda x: x[1])

num = [0] * (n+1)
ans = [None]*m

for p, y, x in pyxs:
    ans[x] = '{:06}'.format(p) + '{:06}'.format(num[p]+1)
    num[p] += 1

for s in ans:
    print(s)
if S[0] == "A" and S[2:-1].count("C") == 1:
    i =  S.index("C")
    S = S[1:i] + S[i+1:]
    if S.islower():
        print("AC")
    else:
        print("WA")
else:
        print("WA")

### FIXED CODE ###

S = input()
accept = False

if S[0] == "A" and S[2:-1].count("C") == 1:
    i =  S.index("C")
    S = S[1:i] + S[i+1:]
    if S.islower():
        accept = True

if accept:
    print("AC")

else:
    print("WA")
r1,c1,r2,c2=map(int,input().split())
a=r2-r1+1
b=c2-c1+1
m=max(a,b)
n=min(a,b)
mod=10**9+7
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a
def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
def f(x,y):
  return comb(x+y+2,y+1)-1
 
print((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%mod)

### FIXED CODE ###

r1,c1,r2,c2=map(int,input().split())
a=r2-r1+1
b=c2-c1+1
m=max(a,b)
n=min(a,b)
mod=10**9+7
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a
def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
def f(x,y):
  return comb(x+y+2,y+1,mod)-1
 
print((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%mod)
while True :
    A , B = input ( ) .split ( " " )
    A = int ( A )
    B = int ( B )
    if A == 0 and B == 0 :
        break
    for x in range ( A ) :
       print "#" * B + "\n"

### FIXED CODE ###

while True :
    A , B = raw_input ( ) .split ( " " )
    A = int ( A )
    B = int ( B )
    if A == 0 and B == 0 :
        break
    for x in range ( A ) :
       print "#" * B
    print
fl = input()
sl = input()

koma_num, pos_num = [int (x) for x in fl.split(" ")]
poses = [int(x) for x in sl.split(" ")]
poses.sort()

dists = []
total = 0
for n in range(pos_num-1):
    dist = poses[n+1] - poses[n]
    dists.append(dist)
    total += dist

dists.sort()
dists.reverse()

for n in range(koma_num-1):
    total -= dists[n]

print(total)


### FIXED CODE ###

fl = input()
sl = input()

koma_num, pos_num = [int (x) for x in fl.split(" ")]
poses = [int(x) for x in sl.split(" ")]
poses.sort()

if koma_num >= pos_num:
    print("0")
    exit()

dists = []
total = 0
for n in range(pos_num-1):
    dist = poses[n+1] - poses[n]
    dists.append(dist)
    total += dist

dists.sort()
dists.reverse()

if(len(dists) == 0):
    print("0")
    exit()

for n in range(koma_num-1):
    total -= dists[n]

print(total)
import numpy as np
from numba import njit, i8


R, C, K = map(int, input().split())
rcvs = [list(map(int, input().split())) for _ in range(K)]

@njit
def solve(rcvs):
    rcvs = np.array(rcvs, dtype=np.int64)
    
    for i in range(len(rcvs)):
        rcvs[i,0] -= 1
        rcvs[i,1] -= 1
    
    rewards = np.array([[0 for _ in range(C)] for _ in range(R)], dtype=np.int64)
    
    for rcv in rcvs:
        rewards[rcv[0],rcv[1]] = rcv[2]
    
    dp = np.array([[[0 for _ in range(4)] for _ in range(C+1)] for _ in range(R+1)], dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1,j+1,0] = max(dp[i,j+1])
            dp[i+1,j+1,1] = dp[i+1,j+1,0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1,j+1,k] = max(dp[i+1,j,k], dp[i+1,j+1,k])
            for k in range(3):
                dp[i+1,j+1,k+1] = max(dp[i+1,j,k]+reward,dp[i+1,j+1,k+1])
    print(np.max(dp[-1,-1]))

if __name__ == "__main__":
    solve(rcvs)

### FIXED CODE ###

import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
import sys

R, C, K = map(int, input().split())
rcvs = [list(map(int, input().split())) for _ in range(K)]
rcvs = np.array(rcvs, dtype=np.int64)

@njit(i8(i8[:,:]), cache=True)
def main(rcvs):
    rewards = np.zeros((R, C), dtype=np.int64)
    
    for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
    return max(dp[-1][-1])

print(main(rcvs))
s=input()
t=input()
n=len(s)

dic={}
ans='Yes'
for i in range(n):
    if s[i] in dic:
        if dic[t[i]]==t[i]:
            continue
        else:
            ans='No'
            break
    
    if t[i] not in dic:
        dic[t[i]]=s[i]
    else:
        if dic[t[i]]==s[i]:
            continue
        else dic[t[i]] !=s[i]:
            ans='No'
            break

print(ans)

### FIXED CODE ###

s=input()
t=input()
n=len(s)

dic={}
ans='Yes'
for i in range(n):
    if t[i] not in dic:
        dic[t[i]]=s[i]
    
    else:
        if dic[t[i]]==s[i]:
            continue
        else :
            ans='No'
            break
    
if len(dic)!=len(set(dic.values())):
    ans='No'
print(ans)
import math
 
a = list(map(int, input().split()))
A = a[0]
B = a[1]
N = a[2]
 
if N%B !=0:
  x_1 = (N//B)*B-1
  if x_1 == -1:
    x_1 = N
  x_2 = N
elif N == 1 or B ==1:
  x_1 =N
  x_2 =N

else:
  x_1 = N-1
  x_2 = N-1
ans_1 = math.floor(A*x_1/B)-A*math.floor(x_1/B)
ans_2 = math.floor(A*x_2/B)-A*math.floor(x_2/B)
if ans_1 >= ans_2:
  print(ans_1)
else:
  print(ans_2)

### FIXED CODE ###

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

if a[1]//k != a[0]//k:
  print('OK')
elif a[0]%k == 0:
  print('OK')
else:
  print('NG')
import math
n,h = map(int,input().split())
ab =[list(map(int,input().split())) for _ in range(n)]
lisA = []
lisB = []
#使いまわせるaを記録し、その最大値を見つける
for a,_ in ab:
  lisA.append(a)
m = max(lisA)

#ｍより大きければ収納
for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)
#print(lisA,lisB,m,s)

cnt = 0
#もし、m以上のbの合計だけでhを超えられるなら、点数の低い順に抜いていく
if s>=h:
  while s>=H:
    #小さいやつを抜いていく
    s -= lisB.pop()
  cnt = len(lisB)  
else:
  cnt = len(lisB) + math.ceil((h-s)//m)
  
print(cnt)  
      
  
  

  
  
  
  

### FIXED CODE ###

import math
n,h = map(int,input().split())
ab =[list(map(int,input().split())) for _ in range(n)]
lisA = []
lisB = []
#使いまわせるaを記録し、その最大値を見つける
for a,_ in ab:
  lisA.append(a)
m = max(lisA)

#ｍより大きければ収納
for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)
#print(lisA,lisB)

cnt = 0
#もし、m以上のbの合計だけでhを超えられるなら、点数の低い順に抜いていく
if s>=h:
  while s>=h:
    #小さいやつを抜いていく
    s -= lisB.pop()
  cnt = len(lisB) + 1 
else:
  cnt = len(lisB) + math.ceil((h-s)/m)
  
print(cnt)
x,n  = map(int,input().split())
if(n==0):
    print(x)
else:

    p = list(map(int,input().split()))
    l = list(range(1,101))

    rl =  set(l) - set(p)
    m = max(p)
    for i in  rl:
        if(abs(i-x) < m):
            m = abs(i-x)
            ans = i
    print(ans)

### FIXED CODE ###

X, N = map(int, input().split())
P = list(map(int, input().split()))

Q = [q for q in range(-1, 102) if q not in P]  # -1以上101以下整数のうちPに存在しないもの
ans = min(Q, key=lambda q: (abs(q - X), q))  # maspyさん解法
print(ans)
n, m = map(int, input().split())
ks = [[0] for i in range(m)]
jud = []
for i in range(m):
    tmp = list([int(i)-1 for i in input().split()])
    ks[i] = tmp[1:]
jud = list(map(int, input().split()))

ans = 0
c = True
for i in range(2 ** n):
    tmp = list()
    c = True
    for j in range(m):
        t = ks[j]
        ch = 0
        for m in t:
            ib = format(i, 'b')
            if len(ib) >= m+1:
                ch += int(ib[m])
            else:
                break
        if ch % 2 != jud[j]:
            c = False
            break
    if c:
        ans += 1
print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
ks = [[0] for i in range(m)]
jud = []
for i in range(m):
    tmp = list([int(i)-1 for i in input().split()])
    ks[i] = tmp[1:]
jud = list(map(int, input().split()))

ans = 0
c = True
for i in range(2 ** n):
    c = True
    ib = format(i, 'b')
    for iks, j in enumerate(ks):
        ch = 0
        for m in j:
            if len(ib) >= m+1:
                ch += int(ib[-m-1])
        if ch % 2 != jud[iks]:
            c = False
            break
    if c:
        ans += 1
print(ans)
n,k=map(int,input().split())
for i in range(n):
    l = [input()]
l.sort()
al = sum(l)-l[:n-k]
print(al)

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
al=sum(l)
for i in range(n-k):
    al -= l[i]
print(al)
s=list(input())
cnt=0
ans=0
lis=list("ATCG")

for i in s:
  if s[i] in lis:
    cnt+=1
    ans=max(ans,cnt)
  else:
    cnt=0
print(ans)

### FIXED CODE ###

s=list(input())
cnt=0
ans=0
lis=list("ATCG")

for i in s:
  if i in lis:
    cnt+=1
    ans=max(ans,cnt)
  else:
    cnt=0
print(ans)
import itertools

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

D = list(map(int, input().split()))
dic = [0,1,2,3,4,5,6,7,8,9]

for i in D:
    dic.remove(i)

dict = map(str, dic)
n = len(str(N)) #何桁か

ans = []
for i in range(2):
    for v in itertools.permutations(dict, n+i):
        if int(''.join(v)) >= N:
            ans.append(int(''.join(v)))
print(min(ans))

### FIXED CODE ###

N, K = map(int, input().split())
D = set(input().split())

for i in range(N, 10**5):
    if not set(str(i)) & D:
        print(i)
        break
N = int(input())
if '9' in N:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = input()
if '9' in N:
    print('Yes')
else:
    print('No')
n = int(input())
ans = [0 for _ in range(10050)]
	for i in range(1,105):
    	for j in range(1,105):
        	for k in range(1,105):
            	v=i*i+j*j+k*k+i*j+j*k+k*i;
              	if v<10050:
                  ans[v]+=1
 
for i in range(n):
	print(ans[i+1])

### FIXED CODE ###

l, r, d = map(int, input().split())
print(r//d - (l-1)//d)
N=input()

if 1<N,N<9:
    output=N
elif 10<N,N<99:
    output=9
elif 100<N,N<999:
    output=N-100+9
elif 1000<N,N<9999:
    output=909
elif 10000<N,N<99999:
    output=N-10000+900+9
else:
    output=90909
print(output)

### FIXED CODE ###

N=input()
N=N.split()
N=int(N[0])

if 1<=N and N<=9:
    output=N
elif 10<=N and N<=99:
    output=9
elif 100<=N and N<=999:
    output=N-99+9
elif 1000<=N and N<=9999:
    output=900+9
elif 10000<=N and N<=99999:
    output=N-9999+900+9
else:
    output=90000+900+9
print(output)
# -*- coding: utf-8 -*-
import collections
N = int(input())
A = list(map(int, input().split()))
A_amount = collections.Counter(A)

result = sum(A)

Q = int(input())
for q in range(Q):
    B, C = map(int, input().split())
	B_elem = A_amount.get(B, None)
    if B_elem is not None:
        C_elem = A_amount.get(C, None)
        if C_elem is not None:
            A_amount.pop(B_elem)
            A_amount[C] = (C, B_elem[1]+C_elem[1])
        else:
            A_amount.pop(B_elem)
            A_amount[C] = (C, B_elem[1])

        result += (C-B)*B_elem[1]
        
    print(result)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import collections
N = int(input())
A = list(map(int, input().split()))
A_amount = dict(collections.Counter(A))

result = sum(A)

Q = int(input())
for q in range(Q):
    B, C = map(int, input().split())
    B_elem = A_amount.get(B, None)
    if B_elem is not None:
        C_elem = A_amount.get(C, None)
        if C_elem is not None:
            A_amount.pop(B)
            A_amount[C] = B_elem+C_elem
        else:
            A_amount.pop(B)
            A_amount[C] = B_elem

        result += (C-B)*B_elem

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

H = 0
N_LR = 0
N_RL = 0

if S[0] == 'R' and S[1] == 'R':
    H += 1
if S[0] == 'R' and S[1] == 'L':
    N_RL += 1
if S[0] == 'L' and S[1] == 'R':
    N_LR += 1

if S[N-1] == 'L' and S[N-2] == 'L':
    H += 1

for i in range(1, N-1):
    if S[i] == 'L' and S[i-1] == 'L' or S[i] == 'R' and S[i+1] == 'R':
        H += 1
    if S[i] == 'R' and S[i+1] == 'L':
        N_RL += 1
    if S[i] == 'L' and S[i+1] == 'R':
        N_LR += 1

M = min(N_RL, N_LR, K)
H += 2 * M
K -= M
N_RL -= M
N_LR -= M

s0 = S[0]
while K > 0 and (s0 == 'R' and N_RL > 0 or s0 == 'L' and N_LR > 0):
    if s0 == 'R' and N_RL > 0:
        H += 1
        s0 = 'L'
        N_RL -= 1
        K -=1
    elif s0 == 'L' and N_LR > 0:
        H += 1
        s0 = 'R'
        N_LR -= 1
        K -=1

sN = S[N-1]
while K > 0 and (sN == 'R' and N_LR > 0 or sN == 'L' and N_RL > 0):
    if sN == 'R' and N_LR > 0:
        H += 1
        sN = 'L'
        N_LR -= 1
        K -=1
    elif sN == 'L' and N_RL > 0:
        H += 1
        sN = 'R'
        N_RL -= 1
        K -=1

print(H)


### FIXED CODE ###

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

if N == 1:
    print(0)
else:
    H = 0
    N_LR = 0
    N_RL = 0

    if S[0] == 'R' and S[1] == 'R':
        H += 1
    if S[0] == 'R' and S[1] == 'L':
        N_RL += 1
    if S[0] == 'L' and S[1] == 'R':
        N_LR += 1

    if S[N-1] == 'L' and S[N-2] == 'L':
        H += 1

    for i in range(1, N-1):
        if S[i] == 'L' and S[i-1] == 'L' or S[i] == 'R' and S[i+1] == 'R':
            H += 1
        if S[i] == 'R' and S[i+1] == 'L':
            N_RL += 1
        if S[i] == 'L' and S[i+1] == 'R':
            N_LR += 1

    M = min(N_RL, N_LR, K)
    H += 2 * M
    K -= M
    N_RL -= M
    N_LR -= M

    s0 = S[0]
    while K > 0 and (s0 == 'R' and N_RL > 0 or s0 == 'L' and N_LR > 0):
        if s0 == 'R' and N_RL > 0:
            H += 1
            s0 = 'L'
            N_RL -= 1
            K -=1
        elif s0 == 'L' and N_LR > 0:
            H += 1
            s0 = 'R'
            N_LR -= 1
            K -=1

    sN = S[N-1]
    while K > 0 and (sN == 'R' and N_LR > 0 or sN == 'L' and N_RL > 0):
        if sN == 'R' and N_LR > 0:
            H += 1
            sN = 'L'
            N_LR -= 1
            K -=1
        elif sN == 'L' and N_RL > 0:
            H += 1
            sN = 'R'
            N_RL -= 1
            K -=1

    print(H)
a = int(input())
c = list(map(int,input().split()))
c1=c2=c34=0
for i in c:
    if c%2==1:
        c1+=1
    elif c%4==0:
        c4+=1
    else:c2+=1
if c1+1>c4:print("No")
elif c1+c2-c4==1:print("Yes")
elif c1<=c4:print("Yes")
        
        
    

### FIXED CODE ###

a = int(input())
c = list(map(int,input().split()))
c1=c2=c4=0
for i in c:
    if i%2==1:
        c1+=1
    elif i%4==0:
        c4+=1
    else:c2+=1
if c1+c2-c4==1:print("Yes")
elif c1<=c4:print("Yes")
else:print("No")
import numpy as np
x, y, z = map(int, input().split())
matrix1 = list()
matrix2 = list()
ans = list()
for i in range(x):
    matrix1.append(list(map(int, input().split())))
for i in range(y):
    matrix2.append(list(map(int, input().split())))
matrix1 = np.matrix(matrix1)
matrix2 = np.matrix(matrix2)
matrix3 = matrix1.dot(matrix2).tolist()
for i in range(x):
    print (' '.join(map(str, matrix3[i])))
        


### FIXED CODE ###

x, y, z = map(int, input().split())
matrix1 = list()
matrix2 = list()
ans = list()
for i in range(x):
    matrix1.append(list(map(int, input().split())))
for j in range(y):
    matrix2.append(list(map(int, input().split())))
for i in range(x):
    row = list()
    for j in range(z):
        term = 0
        for k in range(y):
            term += matrix1[i][k]*matrix2[k][j] 
        row.append(term)
    ans.append(row)
for i in range(x):
    print (' '.join(map(str, ans[i])))
S = input()
ans = 0
for i in range(1 << (len(S)-1)):
    eq = S
    for j in range(len(S)-1):
        if i & (1 << j):
            eq = eq[:j+1] + "," + eq[j+1:]
        else:
            pass
    eq = eq.split(",")
    ans += sum(eq)
print(ans)

### FIXED CODE ###

S = input()
ans = 0
for i in range(1 << (len(S)-1)):
    eq = S
    k = 0
    for j in range(len(S)-1):
        if i & (1 << j):
            eq = eq[:j+1+k] + "," + eq[j+1+k:]
            k +=1
        else:
            pass
    eq = eq.split(",")
    eq = list(map(int,eq))
    ans += sum(eq)
print(ans)
a, b = map(int, input().split())

res = 0 3
for i in range(2):
    if a > b:
        res += a
        a -= 1
    else:
        res += b
        b -= 1

print(res)


### FIXED CODE ###

a, b = map(int, input().split())

res = 0
for i in range(2):
    if a > b:
        res += a
        a -= 1
    else:
        res += b
        b -= 1

print(res)
l = input().replace(' ','')
print(l[0]+l[7]+l[-7])



### FIXED CODE ###

a,b,x = map(int,input().split())
      
print(max(b//x-(a-1)//x,0))
N,M = map(int,input().split())
a = [1]*N
for i in range(M):
    a[int(input())-1] = 0

mod = int(1e9+7)

dp = [0]*N

if a[0] and a[1]:
    dp[0] = 1
    dp[1] = 2
elif not a[0] and a[1]:
    dp[1] = 1
    
for i in range(2,N):
    if a[i]:
        dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = 0

print(dp[N-1]%mod)

### FIXED CODE ###

N,M = map(int,input().split())
a = [1]*N
for i in range(M):
    a[int(input())-1] = 0

mod = int(1e9+7)

dp = [0]*N

if N == 1:
    print(1)
    exit()

if a[0] and a[1]:
    dp[0] = 1
    dp[1] = 2
elif not a[0] and a[1]:
    dp[1] = 1

for i in range(2,N):
    if a[i]:
        dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = 0

print(dp[N-1]%mod)
import math
n , x = map(int,input().split())

field = [int(i) for i in input().split()]

tmp = []

for i in field:
    tmp.append(abs(i-x))


ans = tmp[0]

for i in range(1,n):
    ans = math.gcd(ans,tmp[i])

print(ans)

### FIXED CODE ###

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

field = [int(i) for i in input().split()]

diff = list(map(lambda a:abs(a-x),field))

def gcd(x,y):
    # print(x,y)
    if x < y:
        x,y = y,x

    if x % y == 0:
        return y
    else:
        return gcd(y,x%y)

ans = diff[0]


for i in diff[1:]:
    ans = gcd(i,ans)

print(ans)