Harryxun/stf_run huggingface dataset:
N,M=map(int,input().split())
keep=[]
lis=[]
ac=0
wa=0
for i in range(M):
    ps=input().split()
    keep.append(ps)
for j in range(M):
    if not keep[j][0] in lis:
        if keep[j][1]=="AC":
            ac+=1
            lis.append(keep[j][0])
        else:
            wa+=1
print(ans,wa)

### FIXED CODE ###

N,M=map(int,input().split())
keep=[]
lis=[]
ac=[0]*N
wa=[0]*N
WA=0
for i in range(M):
    ps=input().split()
    keep.append(ps)
    
for j in range(M):
    if keep[j][1]=="AC":
        ac[int(keep[j][0])-1]=1
    elif ac[int(keep[j][0])-1]==0:
        wa[int(keep[j][0])-1]+=1
AC=sum(ac)
for k in range(N):
    WA+=ac[k]*wa[k]
    
print(AC,WA)
n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, 0
while g <= n//9:
    g = 3 * g + 1
    gap.append(g)
m = len(gap)
gap = [gap[i] for i in range(m-1, -1, -1)]
for i in gap:
    for idx in range(i, n):
        j = idx - i
        while j >= 0 and data[j] > data[j+i]:
            data[j+i], data[j] = data[j], data[j+i]
            j -= i
            cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
    print(data[i])



### FIXED CODE ###

import sys

def shellSort(data, cnt, g, n):
    for idx in range(g, n):
        j = idx - g
        v = data[idx]
        while j >= 0 and data[j] > v:
            data[j+g] = data[j]
            j -= g
            cnt += 1
        data[j+g] = v
    return data, cnt

n, gap = int(input()), []
a = ([int(i) for i in sys.stdin.readlines()], 0)
g = 0
while g <= n//9:
    g = 3 * g + 1
    gap.append(g)
m = len(gap)
for i in gap[::-1]:
    a = shellSort(a[0], a[1], i, n)
print(m)
print(" ".join(map(str, gap[::-1])))
print(a[1])
for i in range(n):
    print(a[0][i])
X = input()
Y = X.count("A")
Z = X.count("B")
if (Y == 3 or X ==3):
  print("Yes")
else
  print("No")

### FIXED CODE ###

X = input()
Y = X.count("A")
Z = X.count("B")
if (Y == 3 or Z == 3):
  print("No")
else:
  print("Yes")
a=input()strip().split(" ")

b=[int(i) for i in a]

c=b[0]+b[1]

if(c>=10):
    print("error")
else:
    print(c)


### FIXED CODE ###

a=input().strip().split(" ")

b=[int(i) for i in a]

c=b[0]+b[1]

if(c>=10):
    print("error")
else:
    print(c)
K,N=map(int,input().split())
A=[int(_) for _ input().split()]
a=0
for i in range(N-1):
  tmp=A[i+1]-A[i]
  if a<tmp:
    a=tmp
print(K-a)

### FIXED CODE ###

K,N=map(int,input().split())
A=[int(_) for _ in input().split()]
a=K-A[N-1]+A[0]
for i in range(N-1):
  tmp=A[i+1]-A[i]
  if a<tmp:
    a=tmp

print(K-a)
if N<=104:
    print(0)
elif N<=134:
    print(1)
elif N<=164:
    print(2)
elif N<=188:
    print(3)
else:
    print(4)

### FIXED CODE ###

N = int(input())
if N<=104:
    print(0)
elif N<=134:
    print(1)
elif N<=164:
    print(2)
elif N<=188:
    print(3)
elif N<=194:
    print(4)
else:
    print(5)
N=int(input())
S=input()
K=int(input())
for i in S:
  if S[K]==S[i]:
    S[i]='*'
print(S)

### FIXED CODE ###

input()
S=input()
k=int(input())
for s in S:print(s if s==S[k-1] else "*",end="")
n,m=list(map(int,input().split()))
lists=[]
for i in range(n):
  lists.append()
for i in range(n):
  am=int(input())
  bm=int(input())
  lists[am-1]+=1
  lists[bm-1]+=1
for i in range(n):
  print(str(list[i])+"\n")

### FIXED CODE ###

n,m=list(map(int,input().split()))
lists=[]
for i in range(n):
  lists.append(0)
for i in range(m):
  am,bm=list(map(int,input().split()))
  lists[am-1]+=1
  lists[bm-1]+=1
for i in range(n):
  print(lists[i])
def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    # [[cx, cy, H]]
    candidates = []

    first = sorted(conds, reverse=True, key=lambda x:x[2])[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(first[0]-cx)+abs(first[1]-cy)+first[2]
            for n in range(1, N):
                cond = conds[n]
                if cond[2] == 0:
                    if abs(cond[0]-cx)+abs(cond[1]-cy) < cond[2]: 
                        ansflg = False
                        break
                else:
                    if abs(cond[0]-cand[0])+abs(cond[1]-cand[1])+cond[2] != H:
                        ansflg = False
                        break
            else:
                print("{} {} {}".format(cx, cy, H))
                exit()


if '__main__' == __name__:
    resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    first = sorted(conds, reverse=True, key=lambda x:x[2])[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(first[0]-cx)+abs(first[1]-cy)+first[2]
            for n in range(N):
                cond = conds[n]
                if cond[2] == 0:
                    if abs(cond[0]-cx)+abs(cond[1]-cy) < H: 
                        break
                elif abs(cond[0]-cx)+abs(cond[1]-cy)+cond[2] != H:
                    break
            else:
                print("{} {} {}".format(cx, cy, H))
                exit()


if '__main__' == __name__:
    resolve()
l=map(int,raw_input().split())
c=3
for i in l:
    if l.count(i)==3:
        c= 1
        break
    elif l.count(i)==2:
        c= 2
        break
print c
vvvvv

### FIXED CODE ###

l=map(int,raw_input().split())
c=3
for i in l:
    if l.count(i)==3:
        c= 1
        break
    elif l.count(i)==2:
        c= 2
        break
print c
import numpy as np
import itertools

h,w,k = list(map(int, input().split()))

matrix = np.empty((h,w), dtype = 'str')

for i in range(h):
    matrix[i] = list(input())

if np.count_nonzero(matrix=='#') == k:
    cnt = 1
else:
    cnt = 0

for n_row in range(h+1):
    for n_col in range(w+1):
        for r in itertools.combinations(range(h), n_row):
            for c in itertools.combinations(range(w), n_col):
                if not r and not c:
                    continue
                chg_matrix = matrix.copy()
                chg_matrix[:,c] = '&'
                chg_matrix[r,:] = '&'
                if np.count_nonzero(chg_matrix=='#') == k:
                    cnt += 1

print(cnt)

### FIXED CODE ###

import itertools
import numpy as np

h,w,k = list(map(int, input().split()))

matrix = np.empty((h,w), dtype = 'str')

for i in range(h):
    matrix[i] = list(input())

if np.count_nonzero(matrix=='#') == k:
    cnt = 1
else:
    cnt = 0

for n_row in range(h+1):
    for n_col in range(w+1):
        for r in itertools.combinations(range(h), n_row):
            for c in itertools.combinations(range(w), n_col):
                if not r and not c:
                    continue
                chg_matrix = matrix.copy()
                chg_matrix[:,c] = '&'
                chg_matrix[r,:] = '&'
                if np.count_nonzero(chg_matrix=='#') == k:
                    cnt += 1

print(cnt)
li = input().split()
if li[1] == "+":
  print(li[0] + li[2])
else :
  print(li[0] - li[2])

### FIXED CODE ###

li = input().split()
if li[1] == "+":
    print(int(li[0]) + int(li[2]))
else :
    print(int(li[0]) - int(li[2]))
a = input().split()
s = input()
if a >= 3200:
	print(s)
else:
	print('Red')

### FIXED CODE ###

a = int(input())
s = input()
if a >= 3200:
	print(s)
else:
	print('red')
board =  input().split()

counter = 0

if board[0] == "1":
  counter++
if board[1] == "1":
  counter++
if board[2] == "1":
  counter++
  
print(counter)

### FIXED CODE ###

board =  input()
 
counter = 0
 
if board[0] == "1":
  counter+=1
if board[1] == "1":
  counter+=1
if board[2] == "1":
  counter+=1
  
print(counter)
n = int(input())
t = list(map(int,input().split()))
a = max(t)
if a < sum(t.remove(a)):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

n = int(input())
t = list(map(int,input().split()))
a = max(t)
if a < (sum(t) - a):
  print("Yes")
else:
  print("No")
n=int(input())
t=list(map(int,input().split()))
m=int(input())
for i in range(m):
    a,b=map(int,input().split())
    total=t
    total2[a]=b
    print(sum(total2))

### FIXED CODE ###

import copy
n=int(input())
t=list(map(int,input().split()))
m=int(input())
for i in range(m):
    a,b=map(int,input().split())
    total=copy.copy(t)
    total[a-1]=b
    print(sum(total))
#Expired?
X, A, B = map(int, input().split())
Count = -A+B
if Count <= 0:
    print("delicious")
elif Cunt <= X:
    print("safe")
else:
    print("dangerous")

### FIXED CODE ###

#Expired?
X, A, B = map(int, input().split())
Count = -A+B
if Count <= 0:
    print("delicious")
elif Count <= X:
    print("safe")
else:
    print("dangerous")
n,p=map(int,input().split())
s=input()
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    s=s[::-1]
    M=[0]*n
    M[0]=1
    tmp=0
    for i in range(n):
        tmp+=((int(s[i])*10**i)%p)
        ans+=M[tmp%p]
        M[tmp%p]+=1
print(ans)

### FIXED CODE ###

n,p=map(int,input().split())
s=input()
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    M=[0]*p
    M[0]=1
    tmp=0
    for i in range(n):
        tmp+=(int(s[-i-1])*pow(10,i,p))
        tmp%=p
        ans+=M[tmp]
        M[tmp]+=1
print(ans)
import sys
def main():
    input = sys.stdin.readline
    Dy = [0,1,0,-1]
    Dx = [1,0,-1,0]
    H, W, K = map(int, input().split())
    y1,x1,y2,x2 = map(int, input().split())
    C = ["@" + input() for _ in range(H)]
    C = ["@"*(W+2)] + C + ["@"*(W+2)]
    Closed = [[False]*(W+2) for _ in range(H+2)]
    Nexts = [[[(y+dy, x+dx) for x in range(W+2)] for y in range(H+2)] for dy, dx in zip(Dy, Dx)]
    def root(y, x, Next):
        yp, xp = Next[y][x]
        if not Closed[yp][xp]:
            return yp, xp
        else:
            yp, xp = root(yp, xp, Next)
            Next[y][x] = (yp, xp)
            return yp, xp
    def remove(y, x):
        for i in range(2):
            y1, x1 = Nexts[i][y][x]
            y2, x2 = Nexts[i+2][y][x]
            Nexts[i+2][y1][x1] = (y2, x2)
            Nexts[i][y2][x2] = (y1, x1)
        Closed[y][x] = True
    q = [(y1, x1)]
    remove(y1, x1)
    ans = 0
    while q:
        q_new = []
        for y0, x0 in q:
            if (y0, x0) == (y2, x2):
                print(ans)
                exit()
            for Next in Nexts:
                while True:
                    y, x = root(y0, x0, Next)
                    if abs(y-y0)+abs(x-x0) > K or C[y][x] != ".":
                        break
                    remove(y, x)
                    q_new.append((y, x))
        q = q_new
        ans += 1
    print(-1)

main()


### FIXED CODE ###

Dy = [0,1,0,-1]
Dx = [1,0,-1,0]
H, W, K = map(int, input().split())
y1,x1,y2,x2 = map(int, input().split())
C = ["@" + input() + "@" for _ in range(H)]
C = ["@"*(W+2)] + C + ["@"*(W+2)]
L = [[1]*(W+2) for _ in range(H+2)]
R = [[1]*(W+2) for _ in range(H+2)]
U = [[1]*(W+2) for _ in range(H+2)]
D = [[1]*(W+2) for _ in range(H+2)]
q = [(y1, x1)]
ans = 0
while q:
    q_new = []
    for y0, x0 in q:
        if (y0, x0) == (y2, x2):
            print(ans)
            exit()
        for dy, dx, Next in zip(Dy, Dx, [L, R, U, D]):
            y, x = y0, x0
            sum_next = 0
            Path = [(y, x)]
            while True:
                sum_next += Next[y][x]
                y = y0 + dy * sum_next
                x = x0 + dx * sum_next
                if sum_next > K:
                    break
                if C[y][x] == "@":
                    break
                Path.append((y, x))
                q_new.append((y, x))
            for path_y, path_x in Path:
                Next[path_y][path_x] = abs(path_y-y) + abs(path_x-x)
    q = q_new
    ans += 1

print(-1)
w, h, x, y = map(int, input().split())

cnt = 0

s1 = float((abs(w - x) * abs(h)) / x)
s2 = float((abs(w - 0) * abs(h - y)) / y)

cnt = [s1,s2]
ans = cnt.count(max(cnt))
if ans > 1:
    print(max(cnt), '1')
else:
    print(max(cnt), '0')

### FIXED CODE ###

w, h, x, y = map(int, input().split())

area = w * h / 2

flag = 0

if x == w/2 and y == h/2:
    flag = 1

print(area, flag)
m = int(input())
d = []
c = []
s = 0
ans = -1
for i in range(m):
  d,c = map(int,input().split())
  s += d*c
  ans += c + (d*c) // 10 - len(str(d*c)) + 1

while s >= 10:
  tmp = s
  l = []
  while tmp > 0:
    l.append(tmp%10)
    tmp //= 10
  ans += len(l) - 1 + sum(l)//10 - len(str(sum(l))) + 1
  s = sum(l)
print(ans)

### FIXED CODE ###

h, w, k = map(int, input().split())
a = []
ans = []
no = [True] * h
for i in range(h):
    a.append(input())
    ans.append([0] * w)

color = 1
last_i = 0
for i in range(h):
    last_j = 0
    found = False
    for j in range(w):
        if a[i][j] == '#':
            for k in range(last_i, i+1):
                for l in range(last_j, j+1):
                    ans[k][l] = color
            last_j = j+1
            color += 1
            found = True
    if found:
        last_i = i+1

for i in range(h):
    for j in range(w-1):
        if ans[i][j+1] == 0:
            ans[i][j+1] = ans[i][j]
for i in range(h-1):
    for j in range(w):
        if ans[i+1][j] == 0:
            ans[i+1][j] = ans[i][j]

for i in range(h):
    for j in range(w):
        print(ans[i][j], end=' ')
    print('')
tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dict = {}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dict[tmp[d]] = str(i)+' '+str(d)
result ={}
cost ={}
def calcost(L,R,D):
    if int(R)<D:
        cost[R]=0
        return 0
    elif (int(R)-int(L))<D:
        return 0
    else:
        posi1 = dict[R].split()
        posi2 = dict[str(int(R)-D)].split()
        costs = abs(int(posi2[0])-int(posi1[0])) + abs(int(posi2[1])-int(posi1[1]))
        cost[R] = costs
        return costs + calcost(L,str(int(R)-D),D)

for n in range(1,H*W):
    calcost(str(1),str(n),D)

Q = int(input())
for j in range(Q):
    tmpx = input()
    if tmpx in result:
        print(result[tmpx])
    else:
        tmp = tmpx.split()
        result[tmpx] = cost[tmp[1]]-cost[tmp[0]]
        print(result[tmpx])

### FIXED CODE ###

tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dictx ={}
dicty ={}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dictx[tmp[d]] = i
        dicty[tmp[d]] = d
cost ={}
def calcost(R):
    if int(R)<=D:
        cost[R] = 0
        return 0
    else:
        costs = abs(dictx[R]-dictx[str(int(R)-D)]) + abs(dicty[R]-dicty[str(int(R)-D)])
        cost[R] = costs + cost[str(int(R)-D)]
        return cost[R]

for n in range(1,H*W+1):
    calcost(str(n))
Q = int(input())
for j in range(Q):
    tmp = input().split()
    print(str(cost[tmp[1]]-cost[tmp[0]]))
N,K=map(int,input().split())
H=list(map(int,input().split()))
cost =10000
DP=[0]*N
DP[0]=0
DP[1]=abs(H[1]-H[0])
for i in range(2,N):
  cost=10000
  for k in range(1,K+1):
    if (i-k)==-1:
      break
    cost=min(cost,(abs(H[i]-H[i-k])+DP[i-k]))
    #print(H[i],H[i-k],DP[i-k])
    DP[i]=cost
    #print(DP[i],i)
print(DP[N-1])

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
cost=0
t1,t2=0,0
A=[0]*(N)
i=1
while i<N:
  if i==1:
    A[i]=abs(H[i]-H[i-1])
    #print(i,A[i])
  elif i==2:
    t1=abs(H[i]-H[i-2])
    t2=abs(H[i]-H[i-1])+abs(H[i-2]-H[i-1])
    A[i]=min(t1,t2)
    #print(i,A[i],t1,t2)
  else:
    t1=abs(H[i]-H[i-1])+A[i-1]
    t2=abs(H[i]-H[i-2])+A[i-2]
    A[i]=min(t1,t2)
    #print(i,A[i],t1,t2)
  i=i+1
#print(A)
print(A[N-1])
(n, m) = map(int, raw_input().split())

assert m * 2 + 1 <= n

p, q = 1, n

st1 = set()
st2 = set()
for i in xrange(m):
    if n % 2 == 0 and i == m - 1:
        q -= 1

    print p, q

    assert p not in st1 and q not in st1
    st1 |= set([p, q])

    cur = set([q - p, (p - q + n) % n])
    # print sorted(cur)
    assert not (st2 & cur)
    st2 |= cur

    p += 1
    q -= 1


### FIXED CODE ###

def solve(n, m):
    assert m * 2 + 1 <= n
    res = []

    maxi = (n - 1) / 2
    if maxi % 2 == 0:
        maxi -= 1
    p = 1
    for i in xrange(maxi, 0, -2):
        q = p + i
        res.append([p, q])
        p += 1

    p = maxi + 1 + 1
    maxi += 1
    for i in xrange(maxi, 1, -2):
        q = p + i
        if q > n:
            continue
        res.append([p, q])
        p += 1

    st1 = set()
    st2 = set()
    assert len(res) >= m
    for (a, b) in res:
        assert 1 <= a <= n
        assert 1 <= b <= n
        assert a != b
        assert not (set([a, b]) & st1)
        st1 |= set([a, b])
        diff = abs(a - b)
        assert not (set([diff, n - diff]) & st2)
        st2 |= set([diff, n - diff])
    return res[:m]

solve(9, 4)
solve(6, 2)
solve(7, 3)
solve(15, 6)
solve(12, 5)
solve(10000, 4999)

'''
for i in xrange(1, 100):
    for j in xrange(1, (i - 1) / 2 + 1):
        # print i, j
        solve(i, j)
'''

(n, m) = map(int, raw_input().split())

assert m * 2 + 1 <= n

for a, b in solve(n, m):
    print a, b
import numpy as np

H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = np.zeros((H, W), dtype=np.int64)
for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP[hh - 1][ww - 1] = 1

hhh = max(h)
www = max(w)
hhhh = []
wwww = []
for i in range(H):
    if h[i] == hhh:
        hhhh.append(i)
for i in range(W):
    if w[i] == www:
        wwww.append(i)
check = 0

for i in hhhh:
    for j in wwww:
        if DP[i][j] == 0:
            check = 1
            break
print(hhh + www - (1 - check))


### FIXED CODE ###

H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = set()
for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP.add((hh - 1, ww - 1))

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

for i in hhhh:
    for j in wwww:
        if (i, j) not in DP:
            print(hhh + www)
            exit()
print(hhh + www - 1)
n = int(input())
h = list(map(int,input().split()))
ans = 0
ans_list = []
for i in range(n-1):
    if h[i]>= h[i+1]:
        ans += 1
        ans_list.append(ans)
    else:
        ans = 0
print(max(ans_list))

### FIXED CODE ###

n = int(input())
h = list(map(int,input().split()))
c = 0
d = 0

for i in range(n-1):
    if h[i]>= h[i+1]:
        c += 1
        d = max(d,c)
    else:
        c = 0
print(d)
N = int(input())
h = list(map(int,input().split()))

N -= 1

def step(i):
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[1]-h[0])
  elif abs(h[i-1]-h[i]) <= abs(h[i-2]-h[i]):
    return step(i-1) + abs(h[i-1]-h[i])
  else:
    return step(i-2) + abs(h[i-2]-h[i])
  
print(step(N))


### FIXED CODE ###

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

dp = [0]*N

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,N):
  dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))

print(dp[N-1])
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print(x)
    #print(y)
    
    #それぞれの出現値が同じ場合
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
        
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            x += 1
            y += 1
            return selection(l1, l2, x ,y)
            
    #出現回数を比較し、少ない方を2番目の出現値で返す
    if l1[x][1] > l2[y][1]:
        y -= 1
    else:
        x -= 1
    
    return x, y
    

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    
    x, y = selection(even_c, odd_c, 0 ,0)
    
    #全部ばらばら
    if(even_c[x][1] + odd_c[y][1] == 2):
        print(len(m) - 2)
        return
    
    #全部一緒
    if even_c[x][1] == odd_c[y][1] and even_c[x][0] == odd_c[y][0]:
        print(len(m) - even_c[x][1])
        return
    
    print( len(m) - (even_c[x][1] + odd_c[y][1]) )
    
if __name__ == '__main__':
    main()
    

### FIXED CODE ###

import sys
from collections import Counter
 
def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    #偶数列 奇数列
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    #頻値を取り出す
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    ans = -1
    
    #print(even_c)
    #print(odd_c)
    #print(len(even_c))
    
    #最頻値の比較
    if even_c[0][0] != odd_c[0][0]:
        ans = len(m) - (even_c[0][1] + odd_c[0][1])
    
    #偶数列と奇数列の最頻値の数字が同じかつ、全て同じ数字じゃない
    elif even_c[0][0] == odd_c[0][0] and len(even_c) > 1:
        ans1 = len(m) - (even_c[0][1] + odd_c[1][1])
        ans2 = len(m) - (even_c[1][1] + odd_c[0][1])
        ans = ans1 if ans1 <= ans2 else ans2
    
    #全て同じ
    else:
        ans = even_c[0][1]
        
    #出力
    print(ans)
    
if __name__ == '__main__':
    main()
s=input()
n=int(input())
q=[list(map(int,input().split())) for i in range(n)]
atama=0
x=0
for i in range(n):
  if q[i][0]==2:
    x+=1

oshiri=len(s)+x-1
ans=[None]*(s+x)
x=0
for i in range(n)[::-1]:
  if q[i][0]==1:
    x+=1
  else:
    if (q[i][1]+x)%2==0:
      ans[oshiri]=q[i][2]
      oshiri-=1
    else:
      ans[atama]=q[i][2]
      atama+=1

if x%2==1:
  s=s[::-1]

for i in range(len(s)):
  ans[i+atama]=s[i]

print(ans,sep='')

### FIXED CODE ###

s=input()
n=int(input())
q=[list(map(str,input().split())) for i in range(n)]
atama=0
x=0
for i in range(n):
  if q[i][0]=='2':
    x+=1

oshiri=len(s)+x-1
ans=[]
for i in range(len(s)+x):
    ans.append('x')
x=0
for i in range(n)[::-1]:
  if q[i][0]=='1':
    x+=1
  else:
    if (int(q[i][1])+x)%2==0:
      ans[oshiri]=q[i][2]
      oshiri-=1
    else:
      ans[atama]=q[i][2]
      atama+=1

if x%2==1:
  s=s[::-1]

for i in range(len(s)):
  ans[i+atama]=s[i]

answer=ans[0]
for i in range(1,len(ans)):
    answer+=ans[i]
    
print(answer)
n = int(input())
m = 10**12
for i in int(n**0.5//1):
  if n%i==0:
    m=min(m,i+(n/i)-2)
print(m)

### FIXED CODE ###

n = int(input())
 
b = 10**12
a = int((n**0.5)//1)
for i in range(1,a+1):
  if n%i==0:
    b = min(b,int(i+(n//i)-2))
print(b)