Harryxun/stf_run huggingface dataset:
import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

### FIXED CODE ###

import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)
from math import log2
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i < k:
        ans += 1/2**(int(log2(k/i))+1)
    else:
        ans += 1
ans /= n
print(ans)

### FIXED CODE ###

from math import log2,ceil
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i < k:
        ans += 1/2**(ceil(log2(k/i)))
    else:
        ans += 1
ans /= n
print('{:.15f}'.format(ans))
R,G,B,N =map(int,input().split())

cnt =0
    
for r in range((int(N//R)+1)):
    
    for g in range((int(N//G)+1)):
        
        if r*R+g*G > N:
            continue
            
        temp = N - r*R-g*G
            
        if temp%B ==0:
            cnt+=1
    
print(cnt)
            


### FIXED CODE ###

R,G,B,N =map(int,input().split())

cnt =0
    
for r in range(int(N/R)+1):
  ball = N-r*R 
  for g in range(int(ball/G)+1):
    res = N- (r*R+g*G)
    if  res >=0 and res%B ==0:
      cnt+=1
    
print(cnt)
a,b,k = map(int,input().split())


if a>= K:
    print(a-k,b)
elif a+b>=k:
    print(0,a+b-k)
else:
     print(0,0)


### FIXED CODE ###

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


if a>= k:
    print(a-k,b)
elif a+b>=k:
    print(0,a+b-k)
else:
    print(0,0)
n= int(input())
a_list = list(map(int, input().split()))
gcd = a_list[0]
for i in range(1,n):
    gcd = math.gcd(gcd,a_list[i])
    
    
print(gcd)

### FIXED CODE ###

import math
n= int(input())
a_list = list(map(int, input().split()))
gcd = a_list[0]
for i in range(1,n):
    gcd = math.gcd(gcd,a_list[i])
    
    
print(gcd)
LIM=200002
L=[0]*LIM

def bin_sum(Y):
    S=bin(Y)[2:]
    count=0
    for i in range(len(S)):
        count+=int(S[i])
    return count

def bin_sum2(Y):
    count=0
    for i in range(len(Y)):
        count+=int(Y[i])
    return count

for i in range(1,LIM):
    L[i]+=bin_sum(i)

def pop_num(N,b,L):
    if N==0:
        return 0
    v=N%b
    return pop_num(v,L[v],L)+1
    
M=[0]*200002
for i in range(1,200002):
    M[i]+=pop_num(i,L[i],L)
X=int(input())
Y=input()
d=bin_sum2(Y)+1
c=bin_sum2(Y)-1
e=int(Y,2)%d
f=int(Y,2)%c
for i in range(X):
    if Y[i]=="0":
        b=d
        g=e+2**(X-1-i)%d
    else:
        b=c
        g=e-2**(X-1-i)%c
    if f==0:
        print(0)
    else:
        print(M[g%b])

### FIXED CODE ###

from collections import deque
LIM=200004
L=[0]*LIM

def bin_sum(Y):
    S=bin(Y)[2:]
    count=0
    for i in range(len(S)):
        count+=int(S[i])
    return count

def bin_sum2(Y):
    count=0
    for i in range(len(Y)):
        count+=int(Y[i])
    return count

for i in range(1,LIM):
    L[i]+=bin_sum(i)

def pop_num(N,b,L):
    if N==0:
        return 0
    v=N%b
    return pop_num(v,L[v],L)+1
    
M=[0]*200005
for i in range(1,200004):
    M[i]+=pop_num(i,L[i],L)
X=int(input())
Y=input()
d=bin_sum2(Y)
e=int(Y,2)%(d+1)
f=int(Y,2)%max(1,(d-1))
O=[1]*(X+2)
P=[1]*(X+2)
q=max(d-1,1)
for i in range(1,X+1):
    O[i]=O[i-1]*2%q
    P[i]=P[i-1]*2%(d+1)
for i in range(X):
    
    if int(Y[i])==1:
        b=max(d-1,1)
        flag=max(0,d-1)
        g=(f-O[X-1-i]+b)%b
    else:
        b=d+1
        flag=1
        g=(e+P[X-1-i])%b

    if flag==0:
        print(0)
    elif g==0:
        print(1)
    else:
        print(M[g]+1)
a,b,c=num(input(),split())
  
  print(c,a,b)

### FIXED CODE ###

num=input()
num=num.split()

print(num[2]+" "+num[0]+" "+num[1])
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
e=[]
flag=0
for i in range(h):
  if i%2:
    for j in range(w-1,-1,-1):
      if a[i][j]%2:
        flag=1
        break
  else:
    for j in range(w):
      if a[i][j]%2:
        flag=1
        break
  if flag:break
else:
  exit()
flag=0
y,x=i,j
while True:
  nx,ny=x,y
  if y%2:
    if x:nx=x-1
    else:ny=y+1
  else:
    if x<w-1:nx=x+1
    else:ny=y+1
  if a[y][x]%2:flag=1-flag
  if flag:e.append((y,x,ny,nx))
  if h%2:
    if (ny,nx)==(h-1,w-1):break
  else:
    if (ny,nx)==(h-1,0):break
  x,y=nx,ny
print(len(e))
for i in e:
  print(*i)

### FIXED CODE ###

h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h):
  for j in range(w-1):
    if a[i][j]%2:
      a[i][j]-=1
      a[i][j+1]+=1
      ans+=[(i+1,j+1,i+1,j+2)]
for i in range(h-1):
  if a[i][w-1]%2:
    a[i][w-1]-=1
    a[i+1][w-1]+=1
    ans+=[(i+1,w,i+2,w)]
print(len(ans))
for i in ans:
  print(*i)
n=int(input())
sp_lis=[]
s,p=input().split()
for i in range(1,n+1):
  sp_lis.append([s,100-p,i])
for j in range(n)
print(sorted(sp_lis[j][2]))

### FIXED CODE ###

n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-int(p),i+1])
sp_lis.sort()
for j in range(n):
    print(sp_lis[j][2])
n =  int(input())
arr = input().split()
arr = [int(x) for x in arr]
def hhhh(arr):
    res = []
    for j in range(1,len(arr)):
        for i in range(j):
            #print(arr[i:j])
            if all([arr[i:j][k] >= arr[i:j][k+1] for k in range(len(arr[i:j])-1)]):
                    res.append(j-i)
                    
    
    return max(res)
a = hhhh(arr)
print(a)

### FIXED CODE ###

n =  int(input())
arr = input().split()
arr = [int(x) for x in arr]
counts = []
temp = 0
for i in range(n-1):
    if arr[i] >= arr[i+1]:
        temp += 1
        #print(temp)
        counts.append(temp)
    else:
        #counts.append(temp)
        temp = 0
if not counts:
    print(0)
else:
    print(max(counts))
print(int(input()).count(2))

### FIXED CODE ###

print(input().count("2"))
N, X = map(int, input().split())
List = list(map(int, input().split()))

i = 0
s = 0
while s<=X:
    s += List[i]
    i+=1
    
print(i)

### FIXED CODE ###

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

s = 0
pS = []
for i in range(N):
    s += List[i]
    pS.append(s)
    
pS = [0]+pS

if pS[-1]<=X:
    print(len(pS))
    
else:
    for j in range(N):
        if (pS[j]<=X)&(X<pS[j+1]):
            print(j+1)
# from math import factorial
# from collections import defaultdict, deque
#  from heapq import heappush, heappop

# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]
# A = int(input())

A, B = [int(i) for i in input().split(" ")]
total = A
ans = 1
if B == 1: return 0
while True:
   if B <= total: break
   ans += 1
   total += A  -1
print(ans)




### FIXED CODE ###

# from math import factorial
# from collections import defaultdict, deque
#  from heapq import heappush, heappop

# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]
# A = int(input())

A, B = [int(i) for i in input().split(" ")]
total = A
ans = 1
while True:
   if B <= total: break
   ans += 1
   total += A  -1
if B == 1:  print(0)
else: print(ans)
INF = 1000000007
N = int(input())
A = list(map(int, input().split()))
blst =[0, 0, 0]
blst[0] += 1
ans = 3
for i in range(1, N):
    cnt = blst.count(A[i])
    ans *= cnt
    ans %= INF
    index = blst.index(A[i])
    blst[index] += 1
    if ans == 0:
        ans = 0
        break

print(ans)

### FIXED CODE ###

N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]

for a in A:
    ans = ans * cnt[a] % MOD

    cnt[a] -= 1
    cnt[a+1] += 1

print(ans)
n = int(input())
A = [int(i) for i in input().split()]

A.sort()
m = 2 ** 31
used = set()
ans = 0

def search(ok, ng, n):
    if abs(ok-ng) <= 1:
            return ok
    mid = (ok+ng) // 2
    if A[mid] < n or (A[mid] == n and mid in used):
        return search(mid, ng, n)
    else:
        return search(ok, mid, n)

for i in range(30):
    m //= 2
    for j in range(n):
        if j in used or A[j] >= m:
            continue
        a = search(-1, n, m - A[j]) + 1
        if a >= n:
            continue
        if A[a] == m - A[j]:
            if a == j:
                if not A[a+1] == A[j]:
                    continue
                a += 1
            used.add(a)
            used.add(j)
            ans += 1

print(ans)

### FIXED CODE ###

from collections import Counter

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

A.sort(reverse=True)
C = Counter(A)
m = 1 << 30
ans = 0

for a in A:
    if C[a] <= 0:
        continue
    C[a] -= 1
    while m > a * 2:
        m >>= 1
    v = m - a
    if v in C and C[v] > 0:
        C[v] -= 1
        ans += 1

print(ans)
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, c, d = nm()
    if abs(b-a) <= d or abs(c-b) <= d or abs(c-a) <=:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

### FIXED CODE ###

import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, c, d = nm()
    if (abs(b-a) <= d and abs(c-b) <= d) or abs(c-a) <= d:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()
def main():
    n = int(input())
    S = input()
    s = []
    mod = 998244353
    fact = 1
    for i in range(2, n+1):
        fact = fact*i % mod

    for i in S:
        if i == "R":
            s.append(0)
        elif i == "G":
            s.append(1)
        else:
            s.append(2)

    ans = 1
    color = [0, 0, 0]
    mode = []
    for i in range(3*n):
        if mode == []:
            color[s[i]] += 1
            if color[s[i]] > 0:
                mode.append(s[i])
        elif len(mode) == 1:
            if s[i] == mode[0]:
                color[s[i]] += 1
            else:
                color[s[i]] += 1
                if color[s[i]] > 0:
                    mode.append(s[i])
        else:
            rest = list({0, 1, 2}-{mode[0]}-{mode[1]})[0]
            if s[i] == rest:
                if color[rest] < 0:
                    color[rest] += 1
                else:
                    ans *= color[mode[0]]*color[mode[1]]
                    color[mode[0]] -= 1
                    color[mode[1]] -= 1
                    if color[mode[0]]+color[mode[1]] == 0:
                        mode = []
                    elif color[mode[0]] == 0:
                        mode = [mode[1]]
                    elif color[mode[1]] == 0:
                        mode = [mode[0]]
            else:
                color[s[i]] += 1
        if len(mode) == 2:
            if color[mode[0]] == color[mode[1]]:
                if color[mode[0]] < color[mode[1]]:
                    color[rest] -= color[mode[0]]
                    for i in range(color[mode[0]]):
                        ans *= color[mode[0]]*color[mode[1]]
                        color[mode[0]] -= 1
                        color[mode[1]] -= 1
                    mode = [mode[1]]
                elif color[mode[0]] > color[mode[1]]:
                    color[rest] -= color[mode[1]]
                    for i in range(color[mode[1]]):
                        ans *= color[mode[0]]*color[mode[1]]
                        color[mode[0]] -= 1
                        color[mode[1]] -= 1
                    mode = [mode[0]]
                else:
                    color[rest] -= color[mode[1]]
                    for i in range(color[mode[1]]):
                        ans *= color[mode[0]]*color[mode[1]]
                        color[mode[0]] -= 1
                        color[mode[1]] -= 1
                    mode = []
        ans = ans % mod
    print(ans*fact % mod)


main()


### FIXED CODE ###

def main():
    d = {"R": 0, "G": 1, "B": 2}
    n = int(input())
    s = [d[i] for i in input()]
    #n = len(s)//3
    mod = 998244353
    fact = 1
    for i in range(2, n+1):
        fact = fact*i % mod

    cnt = 0
    ans = fact
    RGB_list = [0, 0, 0]
    for i in s:
        srt = sorted(RGB_list)[::-1]
        if RGB_list[i] == srt[0]:
            pass
        elif RGB_list[i] == srt[1]:
            ans = ans*(srt[0]-srt[1]) % mod
            cnt += 1
        else:
            ans = ans*cnt % mod
            cnt -= 1
        RGB_list[i] += 1
    print(ans)
main()
import sys
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

a, b, c, d = LI()
a = a-1

cd = int(c * d / gcd(c, d))
cs = b // c - a // c
ds = b // d - a // d
cds = b // (cd) - a // (cd)
print(b - a - cs - ds + cds)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict

num  = S()
for i in range(3):
    if num[i] == num[i+1]:
        print("Bad")
        break
else:
    print("Good")
n = int(input())
tree = [[] for _ in range(n+1)]

for _ in range(n-1):
    a, b, c = map(int,input().split())
    a -= 1
    b -= 1
    tree[a].append([b, c])
    tree[b].append([a, c])

q, k = map(int, input().split())
k -= 1
d = [0] * (n+1)

def dfs(x, c, p):
    global tree
    d[x] = c
    for leaf in tree[x]:
        if leaf[0] == p:
            continue
        else:
            dfs(leaf[0], leaf[1]+c, x)

dfs(k, 0, -1)
for i in range(q):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    print(d[a]+d[b])


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
tree = [[] for _ in range(n+1)]

for _ in range(n-1):
    a, b, c = map(int,input().split())
    tree[a].append([b, c])
    tree[b].append([a, c])

q, k = map(int, input().split())
d = [0] * (n+1)

def dfs(x, c, p):
    global tree
    d[x] = c
    for l, c_ in tree[x]:
        if l == p:
            continue
        else:
            dfs(l, c_+c, x)

dfs(k, 0, -1)
for i in range(q):
    a, b = map(int, input().split())
    print(d[a]+d[b])
N, M = map(int, input().split())
bre = []
flag = 0
A = []
for i in range(M):
    bre.append(int(input()))
#print(bre)
A.append(bre[0] - 1)
count = 0
if len(bre) >= 2:
    for i in range(len(bre) - 1):
        a = bre[i + 1] - bre[i]
        A.append(a - 2)
        if a == 1:
            #print(0)
            flag = 1
A.append(N - bre[len(bre) - 1] - 1)

if flag == 0:
    suu = [0, 1, 2]
    for i in range(2, max(A)):
        suu.append(suu[i] + suu[i-1] )
    #print(suu)
    for i in A:
        if count == 0:
            count = suu[i]
        else :
            count *= suu[i]
            count = count % 1000000007
    print(count)


### FIXED CODE ###

N, M = map(int, input().split())
A = [0 for i in range(N + 2)]
A[0] = 0
A[1] = 1
for i in range(M):
    a = int(input()) + 1
    A[a] = -1
for i in range(2, N+2):
    if A[i] ==  -1:
        A[i] = 0
    else:
        A[i] = A[i-1]+ A[i-2]
        A[i] = A[i] % 1000000007
    #print(A)
print(A[N + 1])
a1, a2, a3 = int(input().split(" "))

if(a1+a2+a3 >= 22):
  print("bust")
else:
  print("win")

### FIXED CODE ###

a1, a2, a3 = [int(i) for i in input().split()]

if(a1+a2+a3 >= 22):
  print("bust")
else:
  print("win")
from collections import deque

N, M = map(int, input().split())
Broken = deque()
for _ in range(M):
    broken = int(input())
    Broken.append(broken)

DP = [0] * (N+1)
DP[0] = 1

nex = Broken.popleft()

for i in range(1, N+1):
    if i == nex:
        if len(Broken) >0:
            nex = Broken.popleft()
        continue
    DP[i] = DP[i-1] + DP[i-2]
    DP[i] %= 10**9 + 7
print(DP[N])



### FIXED CODE ###

N, M = map(int, input().split())
Broken = set([])
for _ in range(M):
    broken = int(input())
    Broken.add(broken)

DP = [0] * (N+1)
DP[0] = 1

for i in range(1, N+1):
    if i in Broken:
        continue
    DP[i] = DP[i-1] + DP[i-2]
    DP[i] %= 10**9 + 7
print(DP[N])
n,k=map(int,input().split())
d=[i for i in input().split()]
while True:
    f=False
    for i in d:
        if i not in str(n):
            f=True
            break
    if f:
        break
    n+=1
print(n)

### FIXED CODE ###

a=sorted([int(i) for i in input().split()])
print("YES" if a==[5,5,7] else "NO")
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
lst = [[x, y] for x in range(101) for y in range(101)]
for i, j in lst:
    k = 0
    flag = True
    for x, y, h in xyh:
        H_ = calcH(x, i, y, j, h)
        if h == 0:
            flag = False if n != 1
        if k > 0:
            if H_ != H and flag:
                flag = False
                break
            elif H_ != H:
                H = H_
                flag = True
            else:
                flag = True
                continue
        else:
            H = H_
        k += 1
    if flag == False or H > Hmax:
        continue
    else:
        Cx = i
        Cy = j
        Ch = H
    break
print(Cx, Cy, Ch)

### FIXED CODE ###

def calcCh(cx, cy, x, y, h):
    return abs(x-cx)+abs(y-cy)+h
def calcH(cx, cy, ch, x, y, h):
    return max(ch - calcCh(cx, cy, x, y, 0), 0)
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
xyh = sorted(xyh, key = lambda x: x[2])[::-1]
lst = [[x, y] for x in range(101) for y in range(101)]
for Cx, Cy in lst:
    Ch = calcCh(Cx, Cy, *xyh[0])
    if all(xyh[i][2] == calcH(Cx, Cy, Ch, *xyh[i]) for i in range(n)):
        break
print(Cx, Cy, Ch)
N, K=map(int, input().split())
red=N-K

def cmb(n, r):
  m=1
  if(n==0 or r==0):
      return 1
  if(n<2*r):
      r=n-r
  for i in range(1,r+1):
      m=m*(n-i+1)/i
    
  return m

n = (N-K+1)
if(n>K):
  n=K
for i in range(1,n+1):
  ret = cmb(N-K+1,i)*cmb(K-1,i-1)
  print(int(ret)%(10^9+7))
  

### FIXED CODE ###

from operator import mul
from functools import reduce


def cmb(n, r):
	if n < r:
		return 0
	r = min(n - r, r)
	if r == 0:
		return 1
	numer = reduce(mul, range(n, n - r, -1))
	denom = reduce(mul, range(1, r + 1))
	return numer // denom % INF


N, K = map(int, input().split())
INF = 10 ** 9 + 7

for i in range(1, K + 1):
	print(cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF)
n=int(input())
a[n]={0}
for i in range(1,n):
    a[i]=int(input())



### FIXED CODE ###


def is_prime(n):

    if n == 2:
        return True
    elif n < 2 or n & 1 == 0:
        return False
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            return False
    return True

N = int(input())
cnt = 0
for i in range(N):
    e = int(input())
    if is_prime(e):
        cnt += 1
print(cnt)
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

#last = 1

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    
if last > 0:
    print(s)
else:
    print(sc)

### FIXED CODE ###

import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))
n = int(input())
s = str(input())
if (n % 2 == 0):
    if (s[:n/2] = s[n/2:]):
      print("Yes")
    else:
     print("No")
else:
  print("No")


### FIXED CODE ###

N = int(input())
S = input()
print("Yes" if S[:N//2] == S[N//2:] else "No")
import sys
from functools import lru_cache
sys.setrecursionlimit(1000000000000)

n, W = map(int, input().split())
w, v = [], []

for i in range(n):
    temp1, temp2 = map(int, input().split())
    w.append(temp1)
    v.append(temp2)

#print(w, v)
#dp[i] = max(dp[i-1], dp[i]) + dp[i-2]

@lru_cache(maxsize=None)
def solve(total, i):
    if i > n-1:
        return 0
    weight, val = w[i], v[i]
    if total + weight <= W:
        chose = val + solve(total + weight, i+1)
        unchose = solve(total, i+1)
        return max(chose, unchose)
    else:
        return 0

print(solve(0, 0))

### FIXED CODE ###

n, W = map(int, input().split())
w = [0]*(n+1)
v = [0]*(n+1)

#dp = [[None for i in range(W+1)] for j in range(n+1)]
dp = [[0 for i in range(W+1)] for j in range(n+1)]

for i in range(n):
    w[i], v[i] = map(int, input().split())

def knap(i, j):
    if dp[i][j] is not None:
        return dp[i][j]

    res = 0

    if i == n:
       	res = 0
    elif j < w[i]:
        res = knap(i+1, j)
    else:
        res = max(knap(i+1, j), knap(i+1, j-w[i]) + v[i])

    dp[i][j] = res
    return dp[i][j]

for i in reversed(range(n)):
    for j in range(W+1):
#        res = 0
        # if i == n-1:
        #     res = 0
        if j < w[i]:
            dp[i][j] = dp[i+1][j]
        else:
            dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]] + v[i])

#print(knap(0, W))
print(dp[0][W])
import numpy as np
N,M  = map(int,input().split())
coeff = np.zeros((M,N))
for i in range(M):
    inputs = list(map(int,input().split()))
    for switch in inputs[1:]:
        coeff[i][switch-1] = 1
onlist = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    vec = [int(num) for num in bin(i)[2:]]
    fill = N - len(vec)
    vec = np.append(np.zeros(fill),np.array(vec))
#     print(vec)
    if sum(onlist == np.matmul(coeff,vec)%2) == M:
        ans +=1
print(ans)

### FIXED CODE ###

import numpy as np
N,M  = map(int,input().split())
coeff = np.zeros((M,N))
for i in range(M):
    inputs = list(map(int,input().split()))
    for switch in inputs[1:]:
        coeff[i][switch-1] = 1
onlist = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    vec = [int(num) for num in bin(i)[2:]]
    fill = N - len(vec)
    vec = np.append(np.zeros(fill),np.array(vec))
#     print(vec)
    if sum(onlist == np.dot(coeff,vec)%2) == M:
        ans +=1
print(ans)