Harryxun/stf_run huggingface dataset:
H, W = map(int, input().split())

for h in range(1, H-1)
	A = h * W
	B = int((H - h)//2) * W
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a1 = []
	a1.append(D)
	A1 = min(a1)

for h in range(1, H-1)
	A = h * W
	B = int(W//2) * (H - h)
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a2 = []
	a2.append(D)
	A2 = min(a2)

H, W = W, H

for h in range(1, H-1)
	A = h * W
	B = int((H - h)//2) * W
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a3 = []
	a3.append(D)
	A3 = min(a3)

for h in range(1, H-1)
	A = h * W
	B = int(W//2) * (H - h)
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a4 = []
	a4.append(D)
	A4 = min(a4)

print(int(min(A1, A2, A3, A4)))

### FIXED CODE ###

H, W = map(int, input().split())
a1, a2, a3, a4 = [], [], [], []

for h in range(1, H):
	A = h * W
	B = int((H - h)//2) * W
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a1.append(D)
A1 = min(a1)

for h in range(1, H):
	A = h * W
	B = int(W//2) * (H - h)
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a2.append(D)
A2 = min(a2)

H, W = W, H

for h in range(1, H):
	A = h * W
	B = int((H - h)//2) * W
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a3.append(D)
A3 = min(a3)

for h in range(1, H):
	A = h * W
	B = int(W//2) * (H - h)
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a4.append(D)
A4 = min(a4)

print(int(min(A1, A2, A3, A4)))
n, m = list(map(int, input()))
if n*n == m*n:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n, m = list(map(int, input().split()))
if n*n == m*n:
  print('Yes')
else:
  print('No')
k = int(input())
list=[]
import math import gcd

for i in range(k+1):
    for j in range(k+1):
        for m in range(k+1):
            n = math.gcd(i,j)
            a = math.gcd(n,m)
            list.append(int(a))

ans = sum(list)
print(ans)


### FIXED CODE ###

from math import gcd
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        ans_=gcd(i,j)
        for l in range(1,k+1):
            ans+=gcd(ans_,l)
print(ans)
o = input()
e = input()
ans = ""
for i in len(o):
  ans += o[i]
  if len(e) > i:
    ans += e[i]
print(ans)

### FIXED CODE ###

o = input()
e = input()
ans = ""
for i in range(len(o)):
  ans += o[i]
  if len(e) > i:
    ans += e[i]
print(ans)
N = int(input()) 
  
grid = []
p, q, r = (0, 0, 0)
for _ in range(n):
    (l, m, n) = map(int, input().split())
    grid.append([l, m, n])
    if N:
        p = l
        q = m
        r = n
 
 
for cx in range(101):
    for cy in range(101):
        h = r + abs(p - cx) + abs(q - cy)
        if all(c == max(h - abs(a - cx) - abs(b - cy), 0) for a, b, c in grid):
            print("{} {} {}".format(cx, cy, h))
            exit(0)

### FIXED CODE ###

n = int(input()) 
  
data = []
p, q, r = (0, 0, 0)
for _ in range(n):
    (l, m, n) = map(int, input().split())
    data.append([l, m, n])
    if n:
        p = l
        q = m
        r = n
 
 
for x in range(101):
    for y in range(101):
        h = r + abs(p - x) + abs(q - y)
        if all(c == max(h - abs(a - x) - abs(b - y), 0) for a, b, c in data):
            print("{} {} {}".format(x, y, h))
            exit(0)
n = int(input())
ans = 0
for i in range(1,n + 1):
    if 10 <= i < 100 or 1000 <= i < 10000 or i == 100000:
        ans += 0
    else:
        ans += 1
print(ans)

### FIXED CODE ###

a, b, c = map(int,input().split())
print(b + c - a if b + c - a > 0 else 0)
S = input()

N = len(S) + 1
t = [0] * N
for i in range(N - 1):
    if S[i] == '<':
        t[i + 1] = t[i] + 1
for i in range(N - 1, -1, -1):
    if S[i] == '>':
        t[i + 1] = max(t[i], t[i + 1] + 1)
print(sum(t))

### FIXED CODE ###

S = input()

N = len(S) + 1
t = [0] * N
for i in range(N - 1):
    if S[i] == '<':
        t[i + 1] = t[i] + 1
for i in range(N - 2, -1, -1):
    if S[i] == '>':
        t[i] = max(t[i], t[i + 1] + 1)
print(sum(t))
N = int(input())
Alist = list(map(int, input().split()))
memo = [{} for i in range(N)]

def ddp(cur_N, ai):
    if ai in memo[cur_N]:
        return memo[cur_N][ai]
    if cur_N >=N-1:
        return ai
    aj = Alist[cur_N+1]
    ret = max([ai + ddp(cur_N+1, aj), -1*ai + ddp(cur_N+1, -1*aj)])
    memo[cur_N][ai] = ret
    return ret
print(ddp(0, Alist[0]))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
N = int(input())
Alist = list(map(int, input().split()))
memo = [{} for i in range(N)]

def ddp(cur_N, ai):
    if ai in memo[cur_N]:
        return memo[cur_N][ai]
    if cur_N >=N-1:
        return ai
    aj = Alist[cur_N+1]
    ret = max(ai + ddp(cur_N+1, aj), -1*ai + ddp(cur_N+1, -1*aj))
    memo[cur_N][ai] = ret
    return ret
print(ddp(0, Alist[0]))
data = input().split()

 A = int(data[0])
 B = int(data[1])
 K = int(data[2])

while K >= 1:
	if A % 2 == 0:
		B += A / 2
	else:
		A -= 1
		B += A / 2	
	K--
print(A + " " + B)


### FIXED CODE ###

A, B, K = input().split()

A = int(A)
B = int(B)
K = int(K)

for i in range(K):
	if i % 2 == 0:
		A //= 2
		B += A 
	else:
		B //= 2
		A += B 
print(str(A) + " " + str(B))
import sys

N = input()


N = N.splitlines()


AC_num = 0
WA_num = 0
TLE_num = 0
RE_num = 0


N_num = int(N[0])

if N_num < 1 or N_num > 100000:
    print('error')
    sys.exit()


for i in range(N_num):
    #print(i+1)
    
    if 'AC' == N[i+1]:
        AC_num += 1
        #print(AC_num)
    
    elif 'WA' == N[i+1]:
        WA_num += 1
        #print(WA_num)

    elif 'TLE' == N[i+1]:
        TLE_num += 1
        #print(TLE_num)
    
    elif 'RE' == N[i+1]:
        RE_num += 1
        #print(RE_num)
        
    else:
        print('nun')

print('AC','x',AC_num)
print('WA','x',WA_num)
print('TLE','x',TLE_num)
print('RE','x',RE_num)


### FIXED CODE ###

N_num = int(input())

N = []

for i in range(N_num):
    N.append(input())
    

AC_num = 0
WA_num = 0
TLE_num = 0
RE_num = 0

for i in range(N_num):
    #print(i+1)
    
    if 'AC' == N[i]:
        AC_num += 1
        #print(AC_num)
    
    elif 'WA' == N[i]:
        WA_num += 1
        #print(WA_num)

    elif 'TLE' == N[i]:
        TLE_num += 1
        #print(TLE_num)
    
    elif 'RE' == N[i]:
        RE_num += 1
        #print(RE_num)


print('AC x {}'.format(AC_num))
print('WA x {}'.format(WA_num))
print('TLE x {}'.format(TLE_num))
print('RE x {}'.format(RE_num))
N = int(input())
nums = list(map(int, input().split()))
count = 0
max_count = 0
right = 1
while True:
    if nums[right] <= nums[right-1]:
        count +=1
        right += 1
    else:
        count = 0
        right += 1
        
    if max_count < count:
        max_count = count
    
    if right == N:
        break
    
print(max_count)

### FIXED CODE ###

N = int(input())
nums = list(map(int, input().split()))
count = 0
max_count = 0
right = 0
while True:
    if right == N-1:
        break
    
    if nums[right+1] <= nums[right]:
        count += 1    
    else:
        count = 0
        
    if max_count < count:
        max_count = count
        
    right += 1
    
print(max_count)
x = int(input())
y = [int(i) for i in input().split()]
print("{0}".format(x3),end='')
for i in range(x-2, 0-1, -1):
    print(' {0}'.format(y[i]), end='')

### FIXED CODE ###

input()
a = input().split()
a.reverse()
print(" ".join(a))
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(str, input().split())
data = list(n)

cntOne = 0
cntZero = 0

for i in range(len(data)):
    if data[i] == "0":
        cntZero += 1
    else:
        cntOne += 1

ans(int(2*min(cntOne, cntZero)))

### FIXED CODE ###

import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(str, input().split())
data = list(n)

cntOne = 0
cntZero = 0

for i in range(len(data)):
    if data[i] == "0":
        cntZero += 1
    else:
        cntOne += 1

ans = int(2*min(cntOne, cntZero))
print(ans)
a,b=int(input()).split()

result = a * b
print(result)

### FIXED CODE ###

a,b=(int(x) for x in input().split())

result = a * b
print(result)
import pandas as pd
a = int(input())
b = []
for i in range(a):
    b.append(input())
b = pd.Series(b) 
c = b.mode().tolist()
c.sort()
for i in c:
    print(i)

### FIXED CODE ###

import collections
a = int(input())
l = []
for i in range(a):
    l.append(input())
counted = collections.Counter(l)
 
m = max(counted.values())
 
chars = [key for key, value in counted.items()
             if value == m]
chars.sort()
 
for i in chars:
    print(i)
N = int(input())
arr = list(map(int,input().split()))
import math
gcd = arr[0]
for i in arr:
    gcd = math.gcd(gcd,i)
print(gcd)

### FIXED CODE ###

def gcd(a,b):
    if a < b:
        return gcd(b,a)
    else:
        if a%b == 0:
            return b
        else:
            return gcd(b,a%b)
N = int(input())
src = sorted(list(map(int,input().split())))
ans = src[0]
for i in range(1,N)[::-1]:
    ans = gcd(ans,src[i])
print(ans)
a=1000000007

def isuu(m,n):
    result=1
    i=0
    while i<n:
        result=(result*m)%a
        if result==1:
            return [0,i]
        i+=1
    return [1,result]


m,n=[int(i) for i in input().split(" ")]

i=isuu(m,n)
if i[0]==1:
    print(i[1])
else:
    print((m**(n%i[1]))%a)

### FIXED CODE ###

from functools import lru_cache
mod=1000000007

m,n=[int(i) for i in input().split(" ")]

@lru_cache()
def power(m,n,mod):
    if n==0:
        return 1
    elif n==1:
        return m
    elif n%2==0:
        return ((power(m,n//2,mod)%mod) * (power(m,n//2,mod)%mod))%mod
    else:
        return (power(m,n-1,mod)*m)%mod

print(power(m,n,mod))
if a.isdigit()==True and b.isdigit()==True and c.isdigit()==True and k.isdigit()==True:
    a = int(a)
    b = int(b)
    c = int(c)
    k = int(k)
    if a>=0 and b>=0 and c>=0:
        if k>=1 and k<=(a+b+c) and (a+b+c)<=2*(10**9):
            if k < a:
                print(k)
            elif k >= a and k <= (a+b):
                print(a)
            else:
                print(a - (k - b - a))

### FIXED CODE ###

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

result = 0
t = min(a, k)
result += t
k -= t
t = min(b, k)
k -= t
t = min(c, k)
result -= t
print(result)
s1,s2,s3 = map(int,input().split())
print(s1[0].capitalize() + s2[0].capitalize() + s3[0].capitalize())

### FIXED CODE ###

s1,s2,s3 = input().split()
print(s1[0].capitalize() + s2[0].capitalize() + s3[0].capitalize())
t,x=map(int,input().split())
print(round((t/x),4)))

### FIXED CODE ###

t,x=map(int, input().split())
print(t/x)
import collections


n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:(x[1]),reverse=True)
even = sorted(collections.Counter(even).items(),key=lambda x:(x[1]),reverse=True)

if len(odd) == 1 and len(even) == 1:
    if odd[0][0] == even[0][0]:
        print(n//2)
    else:
        print(0)
elif len(odd) == 1 or len(even) == 1:
    if len(odd) == 1:
        print((n//2 - odd[0][1]) + (n//2 - even[1][1]))
    elif len(even) == 1:
        print((n//2 - odd[1][1]) + (n//2 - even[1][1]))
else:
    if odd[0][1] + even[1][1] > odd[1][1] + even[0][1]:
        print((n//2 - odd[0][1]) + (n//2 - even[1][1]))
    else:
        print((n//2 - odd[1][1]) + (n//2 - even[0][1]))

### FIXED CODE ###

import collections

n = int(input())
odd = []
even = []
for i, j in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(), reverse=True, key=lambda x: x[1])
even = sorted(collections.Counter(even).items(), reverse=True, key=lambda x: x[1])

if len(odd) == 1 and len(even) == 1 and odd[0][0] == even[0][0]:
    print(n // 2)
elif odd[0][0] == even[0][0]:
    if odd[0][1] == even[0][1]:
        for i in range(2):
            if odd[i][1] == even[i][1]:
                continue
            elif odd[i][1] > even[i][1]:
                print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
                break
            elif odd[i][1] < even[i][1]:
                print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
                break
        else:
            print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
else:
    print((n // 2 - odd[0][1]) + (n // 2 - even[0][1]))
n, m = map(int, input().split())
A = list(map(int, input().split()))
all = sum(A)

cnt = 0
for x in A:
  if 4 * m * x >= all:
    cnt++;
  
if cnt >= m:
  print("Yes")
else :
  print("No")


### FIXED CODE ###

n, m = map(int, input().split())
A = list(map(int, input().split()))
all = sum(A)

cnt = 0
for x in A:
  if 4 * m * x >= all:
    cnt += 1
  
if cnt >= m:
  print("Yes")
else :
  print("No")
n, m = map(int, input().split())
a_pos = [0]*(n+1)
for i in range(m):
    a_pos[int(input())] = 1
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 0 if aL[1] == 1 else 1
for i in range(2, n+1):
    if a_pos[i] == 1:
        dp[i] = 0
    else:
        dp[i] = (dp[i-2] + dp[i-1]) % mod

print(dp[-1])

### FIXED CODE ###

n, m = map(int, input().split())
a_pos = [0]*(n+1)
for i in range(m):
    a_pos[int(input())] = 1
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 0 if a_pos[1] else 1
for i in range(2, n+1):
    if a_pos[i] == 1:
        dp[i] = 0
    else:
        dp[i] = (dp[i-2] + dp[i-1]) % mod

print(dp[-1])
(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A. append([int(j) for j in input().split() ])

for i in ronge(m):
    b.append(int(input()))


for i in range(n):
m = 0
for j in range(m):
    s += A[j][j] * b[j]
   print(s)

### FIXED CODE ###

if __name__ == '__main__':
    n, m = [int(i) for i in input().split()]
    A = [[int(i) for i in input().split()] for j in range(n)]
    b = [int(input()) for i in range(m)]
    c = [sum(map(lambda x,y: x*y, A[i], b)) for i in range(n)]
    print('\n'.join([str(i) for i in c]))
N,A,B = int.input()
M = A+B
if (M%2==1):
    print("Borys")
else:
    print("Alice")

### FIXED CODE ###

n, a, b = map(int,input().split())
m = a + b
if (m % 2==1):
    print("Borys")
else:
    print("Alice")
N = int(input())
mod = 10**9+7
if N == 1:
  print(0)
elif N == 2:
  print(2)
else:
  ans = 10*8*6*(10**(3(N-3)))
  print((ans*2)%mod)


### FIXED CODE ###

n = int(input())
mod = 10**9+7
a = 10**n-9**n-9**n+8**n
print(a%mod)
n, m = list(map(int, input().split()))
root_list = []
for _ in range(m):
    tmp = list(map(int, input().split()))
    if tmp[0] != tmp[1] and tmp not in root_list
    root_list.append(list(map(int, input().split())))

answer_list = [0] * (n-1)
done_list = [1]
already_list = [1]
while len(root_list) > 0 and 0 in answer_list:
    if len(done_list) == 0:
        break
    tmp_list = []
    copy_root_list = root_list.copy()
    for num in done_list:
        for l in root_list:
            if l[1] == num:
                if answer_list[int(l[0]-2)] == 0:
                    answer_list[int(l[0]-2)] = num
                    tmp_list.append(l[0])
                    already_list.append(l[0])
                    copy_root_list.remove(l)
                else:
                    copy_root_list.remove(l)
            elif  l[0] == num and l[0] != l[1]:
                if answer_list[int(l[1]-2)] == 0:
                    answer_list[int(l[1]-2)] = num
                    tmp_list.append(l[1])
                    already_list.append(l[1])
                    copy_root_list.remove(l)
                else:
                    copy_root_list.remove(l)
    root_list = copy_root_list
    done_list = tmp_list

if 0 not in answer_list:
    print("Yes")
    for i in answer_list:
        print(int(i))
else:
    print("No")
    

### FIXED CODE ###

from collections import deque

n, m = list(map(int, input().split()))
root_dict = {}

for _ in range(m):
    a, b = list(map(int, input().split()))
    if a not in root_dict:
        root_dict[a] = deque([b])
    else:
        root_dict[a].append(b)
    if b not in root_dict:
        root_dict[b] = deque([a])
    else:
        root_dict[b].append(a)

visited = [1] + [-1] * (n-1)

done = deque([1])

while done:
    x = done.popleft()
    while root_dict[x]:
        i = root_dict[x].popleft()
        if visited[i-1] < 0:
            visited[i-1] = x
            done.append(i)

if -1 in visited:
    print("No")
else:
    print("Yes")
    for i in range(1, n):
        print(visited[i])
import math
a,b,c =map(int,input().split())
if math.sqrt(a)+math.sqrt(b)=math.sqrt(c):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b,c=map(int,input().split())
if 0>=c-a-b:
  print("No")
  exit()
if 4*a*b<(c-a-b)**2:
  print("Yes")
else:print("No")
n, m = map(int, input().split())
A = list(map(lambda x:list((int(x),1)), input().split()))
#print(A)
for i in range(m):
    b,c = map(int, input().split())
    A.append([c,b])
A.sort(reverse = True)
sum = 0
rem = n
for i in range(len(A)):
    sum += A[i][0] * min(A[i][1],rem)
    rem -= min(A[i][1],rem)
    if rem == 0: break
print(sum)

### FIXED CODE ###

n, m = map(int, input().split())
A = list(map(lambda x:list((int(x),1)), input().split()))
#print(A)
for i in range(m):
    b,c = map(int, input().split())
    A.append([c,b])
A.sort(reverse = True)
sum = 0
rem = n
for i in range(len(A)):
    sum += A[i][0] * min(A[i][1],rem)
    rem -= min(A[i][1],rem)
    if rem == 0: break
print(sum)
N, D = map(int, input().split())
print(int(N//(2*D+1.001) + 1))

### FIXED CODE ###

r = int(input())
print(3*r*r)
# -*- coding: utf-8 -*-
def get_numbers():
    return map(int, input().split())

a, b = get_numbers()
if a % 2 == 1:
    ans = a
    numbers = list(range(a + 1, b + 1))
else:
    ans = 0
    numbers = list(range(a, b + 1))

mod = len(numbers) % 4


if mod == 0:
    print(ans ^ 0)
elif mod == 1:
    print(ans ^ 0 ^ b)
elif mod == 2:
    print(ans ^ 1)
elif mod == 3:
    print(ans ^ 1 ^ b)

### FIXED CODE ###

# -*- coding: utf-8 -*-
def get_numbers():
    return map(int, input().split())


def xor(n):
    if n % 4 == 3:
        return 0
    if n % 4 == 0:
        return n
    if n % 4 == 1:
        return 1
    if n % 4 == 2:
        return 1 ^ n


a, b = get_numbers()
print(xor(a - 1) ^ xor(b))
#create environment
import numpy as pd
num = 1
i = 1
k = 1
df = pd.DataFrame()
count_num = 0
f = lambda x: (x**2)

#input1 N D (numeric)
N, D = map(int, input().split())
#input2
for l in range(1, N):
  a = map(int, input().split())
  if a is none:
    break
  df[l] = a

# make combination
df_new = df.T
#print(df_new)
for i in range(0, len(df_new.index)):
  for j in range(k, len(df_new.index)):
#    print_str = str(i) + '-' + str(j)
#    print(print_str)
    k = k + 1
    df_new_ij = df_new.loc[[i,j],:]
    obj_num = np.sqrt(df_new_ij.apply(f).cumsum().iloc[1,:].cumsum()[len(df['a'])-1])
    
    if obj_num == round(obj_num):
      count_num = count_num + 1

#print
print(count_num)






### FIXED CODE ###

import math
n, d = map(int, input().split())
x = []
ans=0
for i in range(n):
        o = list(map(int, input().split()))
        x += [o]
for i in range(n):
        for j in range(i+1,n):
                dis_net = 0
                dis=0
                for u in range(d):
                        dis += (x[i][u] - x[j][u])** 2
                dis_net = math.sqrt(dis)
                if dis_net % 1 == 0 and dis_net>=1:
                        ans += 1
print(ans)
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)
s=input()
q=int(input())
query=[]
for i in range(q):
    query.append(input())
rev=0
bef=""
aft=""
for i in range(q):
    if query[i][0]=="1":
        rev+=1
    else:
        n,f,c=query[i].split()
        if (rev+int(f))%2==0:
            aft=aft+c
        else:
            bef=c+bef
seqfin=bef+s+aft
if rev%2==0:
    print(seqfin)
else:
    for i in range(len(seqfin)):
        print(seqfin[len(seq)-i-1],end="")

### FIXED CODE ###

s=input()
q=int(input())
query=[]
for i in range(q):
    query.append(input())
rev=0
bef=""
aft=""
for i in range(q):
    if query[i][0]=="1":
        rev+=1
    else:
        n,f,c=query[i].split()
        if (rev+int(f))%2==0:
            aft=aft+c
        else:
            bef=c+bef
seqfin=bef+s+aft
if rev%2==0:
    print(seqfin)
else:
    print(seqfin[::-1])
N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    l, r = 0, 1
    for i in range(M):
        X[l] = 1
        X[r] = 1
        print(l+1, r+1)
        if i < M - 1:
            while X[l] != 0 or X[(l+i+2)%N]:
                l += 1
            r = (l + i + 2) % N
else:
    for i in range(M):
        print(N-i-1, i+1)

### FIXED CODE ###

N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    X = [0 for _ in range((N-1)//2)]
    l, r = 1, N // 2
    for i in range((N//2)//2):
        X[i] = [l, r]
        l += 1
        r -= 1
    l, r = N, N // 2 + 2
    for i in range((N-1)//2-(N//2)//2):
        X[i+(N//2)//2] = [l, r]
        l -= 1
        r += 1
    for i in range(M):
        print(X[i][0], X[i][1])
else:
    for i in range(M):
        print(N-i, i+1)
N=int(input())
sum=0
for i range(N):
  l, r =map(int, input().split())

### FIXED CODE ###

n=int(input())
sum=0
for i in range(n):
  l, r =map(int, input().split())
  sum+=(r-l+1)
print(sum)
n,m = map(int, input().split())
if m == 0:
  print(1)
  exit()
g = [[] for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
v = [-1 for i in range(n)]
ans = [0]*(n+1)
def dfs(x,y):
  for i in g[x]:
    if v[i] == -1:
      v[i]=1
      ans[y]+=1
      dfs(i,y)
for i in range(n):
  if v[i]!=-1:
    continue
  v[i]=0
  dfs(i,i)
print(max(ans)+1)

### FIXED CODE ###

from collections import deque
n,m = map(int, input().split())
if m == 0:
  print(1)
  exit()
g = [[] for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
v = [-1 for i in range(n)]
ans = []
for i in range(n):
  if v[i]!=-1:
    continue
  v[i]=0
  an=1
  d = deque([i])
  while len(d):
    x = d.popleft()
    for i in g[x]:
      if v[i] == -1:
        d.append(i)
        v[i]=1
        an+=1
  ans.append(an)
print(max(ans))
S,T = input().split()
a=0
for i in range(len(S)):
  if S[i]==T[i]:
      a=a+1
  else:
      a=a+0
print(a)

### FIXED CODE ###

s,t = input(), input()
a = 0
for i in range(len(s)):
    if s[i]!=t[i]:
        a = a + 1
print(a)
from math import gcd
A, B, C, D = map(int, input().split())
A-=1
lcm=C*D//gcd(C,D)
#B以下の個数
b = B-(B//C)-(B//D)-B//lcm
#A以下の個数
a = A-(A//C)-(A//D)-A//lcm
print(b-a)


### FIXED CODE ###

from fractions import gcd
A, B, C, D = map(int, input().split())
A-=1
lcm=C*D//gcd(C,D)
#B以下の個数
b = B-(B//C)-(B//D)+B//lcm
#A以下の個数
a = A-(A//C)-(A//D)+A//lcm
print(b-a)