peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import sys
n = int(input())
dp=[sys.maxsize]*(n+1)
def beki(arg):
  res=0
  t=1
  while t < n:
    t=t*arg
    res+=1
  return res

dp[0]=0
a = beki(9)
b = beki(6)

for i in range(n):
  dp[i+1]=min(dp[i+1],dp[i]+1)
  for j in range(1,a+1):
    if i+9**j > n:
      break
    dp[i+9**j]=min(dp[i+9**j],dp[i]+1)
  for j in range(1,b+1):
    if i+6**j > n:
      break
    dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
print(dp[n])
# Judge status: Accepted
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
L=p[a-x:a]+q[b-y:b]+r
L.sort()
L.reverse()
print(sum(L[0:x+y]))
# Judge status: Wrong Answer
import numpy as np
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()
ans=0
if l[0]!=l[1]:
    ans+=1
for i in range(1,n-1):
    if l[i]!=l[i-1] and l[i]!=l[i+1]:
        ans+=1
if l[n-1]!=l[n-2]:
    ans+=1
print(ans)
# Judge status: Accepted
S=input()
N=len(S)
M=(N-1)//2
def iskaibun(T):
    K=len(T)
    for i in range(K):
        if T[i]==T[-i-1]:
            pass
        else:
            return False
    return True

if iskaibun(S) and iskaibun(S[:M]) and iskaibun(S[M+1:]):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, x = map(int, input().split())
Ls = list(map(int, input().split()))
ans = 1
temp = 0
for l in Ls:
  temp += l
  if temp <= x:
    ans += 1
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline

def main():
    H, N = map(int, input().split())
    inf = float('inf')
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    dp = [inf] * (H+10**4+1)
    dp[0] = 0
    for h in range(H+1):
        for a, b in AB:
            dp[h+a] = min(dp[h+a], dp[h]+b)
    print(min(dp[H:]))


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
W, H, x, y = map(int, input().split())
S = W*H/2
if W//2 == x and H//2 == y:
    print(S, 1)
else:
    print(S, 0)
# Judge status: Wrong Answer
n = int(input())
tsk = []
for i in range(n):
	a,b = map(int,input().split())
	tsk.append([a,b])

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

t = 0
ans = 'Yes'

for i in range(n):
	l = tsk[i]
	t += l[0]
	if t<=l[1]:
		ans = 'No'
		break
print(ans)
# Judge status: Accepted
#! python3

def main():
    d, n = map(int, input().split())
    dd = 100**d
    if n%100 != 0:
        ans = n*dd
    else:
        ans = (1+n)*dd
    print(ans)
main()
# Judge status: Accepted
def digit(N,n):#nは正の整数、N進法での桁数、許容は１０＾１０００
    if n<N:
        return 1
    else:
        return 1+digit(N,n//N)

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

m=Y//X
print(digit(2,m))
# Judge status: Accepted
n, m = map(int, input().split())
a = input().split()
a = [int(_) for _ in a]

total_amount = sum(a)
threshold = 1/(4*m) * total_amount
clear_a = [_ for _ in a if _ >= threshold]
if len(clear_a) >= m:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
ch=input()

if ch[2]==ch[3] and ch[4]==ch[5]:
  print("Yes")
print("No")
# Judge status: Accepted
n, m = map(int, input().split())
cl = [1 for _ in range(n)]
rl = [1]+[0 for _ in range(n-1)]

for i in range(m):
    x_n, y_n = map(int, input().split())
    cl[x_n-1] -= 1
    cl[y_n-1] += 1
    if rl[x_n-1] == 1 and cl[x_n-1]>0:
        rl[y_n-1] = 1
    elif rl[x_n-1] == 1 and cl[x_n-1] == 0:
        rl[x_n-1] = 0
        rl[y_n-1] = 1
    elif rl[x_n-1] == 0:
        pass
print(sum(rl))
# Judge status: Accepted
n,k = map(int, raw_input().split(' '))
r,s,p = map(int, raw_input().split(' '))
seq = raw_input()

import collections
q,i = collections.deque(), 0
while(i < len(seq)):
	u = q.popleft() if len(q) == k else [0,0,0]
	q.append( [ max(u[1], u[2]) + (r if seq[i]  == 's' else 0) ,max(u[0], u[2]) + (s if seq[i]  == 'p' else 0) ,max(u[0], u[1]) + (p if seq[i]  == 'r' else 0)])
	i +=1
print sum([max(cc) for cc in q] or [0])
# Judge status: Wrong Answer
N = int(input().rstrip())
INPUT = list(map(int, input().rstrip().split(' ')))

for count in range(10):
    for i in range(N):
        p, mod = divmod(INPUT[i], 2)
        if mod == 0:
            INPUT[i] = p
        else:
            break
    else:
        continue
    print(count)
    break
# Judge status: Accepted
N = input()

b = N in ["3","5","7"]

if b:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N = int(input())
D = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Ans = [["a"]]
for i in range(1, 10):
    before = Ans[i - 1]
    # print(before)
    next = []
    for j in before:
        L = set(list(j))
        # print(L)
        for k in range(len(L) + 1):
            # print(j)
            next.append(j + D[k])
    Ans.append(next)
# print(Ans)
print(*Ans[N - 1], sep="\n")
# Judge status: Accepted
n,k = map(int, input().split())
a = list(map(int, input().split()))

nums = [0]*n
nums[k-1] = sum(a[:k])
for i in range(k,n):
  nums[i] = nums[i-1] + a[i] - a[i-k]

for i in range(k,n):
  if nums[i-1] < nums[i]: print("Yes")
  else: print("No")
# Judge status: Accepted
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]
li = []
for ab in AB:
    if ab[0] == 1:
        li.append(ab[1])
    if ab[1] == N:
        li.append(ab[0])
se = set(li)
if len(se) != len(li):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
# Judge status: Accepted
n = int(input())
s1 = set()
s2 = set()
a = 1
b = 1
while a <= n:
    if a % 3 == 0:
        s1.add(a)
    a += 1
while b <= n:
    if b % 5 == 0:
        s2.add(b)
    b += 1
s3 = set(range(1,n + 1))
s12 = s1 | s2
s4 = s3 - s12
c = 0
for x in s4:
    c += x
print(c)
# Judge status: Accepted
N = int(input())
S = [str(input()) for i in range(N)]

SS = set(S)
print(len(SS))
# Judge status: Accepted
n = input()
p = [int(z) for z in input().split()]
c=0
for i in range(1,len(p)-1):
      if (p[i-1]<=p[i]<=p[i+1] or p[i+1]<=p[i]<=p[i-1]):
            c+=1
print(c)
# Judge status: Wrong Answer
K = 12
table = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in table:
  if len(table) > K:
    break
  x = i % 10
  for j in range(max(0, x - 1), min(x + 2, 10)):
    table.append(i * 10 + j)

print(table[K-1])
# Judge status: Accepted
from collections import deque
S = deque(list(input()))
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 1 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
D = list(S)
print ("".join(D) if f % 2 == 0 else "".join(D[::-1]))
# Judge status: Accepted
date=input()
date_changed = date[:3] + '8' + date[4:]
print(date_changed)
# Judge status: Accepted
import math

n = int(input())

m = n-1
for k in range(2, int(math.sqrt(n)) + 1):
  if n % k == 0:
    m = k + n//k - 2
    
print(m)
# Judge status: Accepted
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])
b = np.arange(1,n+1, dtype=int)
a -= b 
a -= int(np.median(a))
print(sum(np.abs(a)))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
ans = 0

for num in range(1, n+1, 2):
    if a[num-1] % 2 != 0:
        ans += 1
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
if a >= 13 :
  print(b)
elif a >= 6 :
  print(b//2)
else :
  print(0)
# Judge status: Wrong Answer
N = int(input())

n = 1
ans = 10**5

def calucurate(M):
    n = 0
    while M > 0:
        n += M%10
        M //= 10
    return n

while n < N:
    t = N - n
    m = calucurate(t) + calucurate(n)
    ans = min(ans,m)
    n += 1
# Judge status: Accepted
n, p = map(int, input().split())
A = list(map(int, input().split()))

cnt_even = 0
for i in range(n):
	if A[i] % 2 == 0:
		cnt_even += 1

if cnt_even == n:
	if p == 0:
		print(2 ** n)
	else:
		print(0)
else:
	print(2 ** (n - 1))
# Judge status: Accepted
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(A, i)*(N-bisect.bisect_right(C, i)) for i in B))
# Judge status: Accepted
#標準出力からの読み込み
n = int(input())

#判定ロジック
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

output = 0
divisor = num_divisors_table(n-1)

output = sum(divisor)

print(output)
# Judge status: Wrong Answer
s = input()
t = input()
num = 0
for i in range(len(s) - len(t) + 1):
    # a = s[i:]
    # print(a)
    cnt = 0
    for j in range(len(t)):
        if i + j >= len(t):
            continue
        if t[j] == s[i + j]:
            cnt += 1
    num = max(num, cnt)

print(len(t) - num)
# Judge status: Wrong Answer
n = int(input()); a = list(map(int, input().split()))
a.sort(); x = 0
for i in range(n, 2*n): x += a[i]
print(x)
# Judge status: Wrong Answer
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N-1):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
if H>0:
  n = H//a if H%a==0 else H//a+1
  ans += n
  print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
n = input()

s1 = n[:a]
s2 = n[a]
s3 = n[a+1:]

if s1.isdigit() and s2=='-' and s3.isdigit():
    print('Yes' , flush=True)
else:
    print('No' , flush=True)
# Judge status: Accepted
import sys

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

if a % 2 == 0 or b % 2 == 0:
    print("Even")
else:
    print("Odd")
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
mn = 10**9
for i in range(-100,101):
    x = 0
    for j in a:
        x += (j-i)**2
    mn = min(mn,x)
print(mn)
# Judge status: Wrong Answer
a,b,x = map(int,input().split())
print("YES" if a + b > x and a < x else "NO")
# Judge status: Wrong Answer
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
ans = 'Yes'
n = min(len(s), len(t))
if s[:n] == t[:n]:
    if len(s) > len(t):
        ans = 'No'
else:
    for sc, tc in zip(s, t):
        if sc == tc:
            continue
        if sc > tc:
            ans = 'No'
        else:
            ans = 'Yes'
        break
print(ans)
# Judge status: Accepted
X = int(input())
for i in range(-120,120):
    for j in range(-120,120):
        if i**5 - j**5 == X:
            print(i,j)
            exit()
# Judge status: Accepted
n = int(input())
lim = n
count = 0
for b in range(1,lim):
    add = int((n-1)/b)
    count += add
print(count)
# Judge status: Wrong Answer
N=int(input())
A=[[0 for n in range(9)] for n in range(9)]

for n in range(N):
    head=int(str(n)[0])
    tail=n%10
    if head!=0 and tail!=0:
        A[head-1][tail-1]+=1

count=0

for i in range(9):
    for j in range(9):
        count+=A[i][j]*A[j][i]

print(count)
# Judge status: Wrong Answer
N = int(input()) 
tmp = N // 1000
answer = (tmp+1)*1000 -N
print(int(answer))
# Judge status: Wrong Answer
s = input()
for i in s:
    if s.count(i) != 1:
        print('No')
        exit
print('Yes')
# Judge status: Accepted
n=int(input())
al=list(map(int,input().split()))

import fractions
ans=0
left=[0]
for i in range(1,n):
    ans=fractions.gcd(ans,al[i-1])
    left.append(ans)
#print(left)
right=[0 for i in range(n+1)]
for i in range(1,n+1):
    right[n-i]=fractions.gcd(right[n-i+1],al[n-i])
#print(right)

ans=0

for i in range(n):
    ans=max(ans,(fractions.gcd(left[i],right[i+1])))
print(ans)
# Judge status: Accepted
l,r,d = map(int,input().split(" "))
x = r//d - (l-1)//d
print(x)
# Judge status: Wrong Answer
a = int(input())
print((a+1)/2)
# Judge status: Wrong Answer
def main():
    import sys
    input = sys.stdin.readline
    D, N = map(int, input().split())
    if N != 100:
        print(N, end="")
        for i in range(D):
            print("00", end="")
        print("")
    else:
        print(100 ** (D+1) + 1)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
S = input()
T = "ACGT"
ans = 0
cnt = 0
for s in S:
    if s in T:
        cnt += 1
    else:
        if cnt > ans:
            ans = cnt
        cnt = 0
print(ans)
# Judge status: Accepted
N,M=map(int, input().split())
if N==M:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
n = int(input())
s = list(map(int,input().split()))
a = 0
for i in range(n):
  if i%2 == 0 and s[i]%2 ==1:
    a+=1
print(a)
# Judge status: Accepted
a, b, c, d = map(int, input().split())

big = max(c, d)
small = min(c, d)
lcm = 0
for i in range(1, 10 ** 8):
    surplus = big % small
    if surplus == 0:
        lcm = c * d // small
        break
    
    big = small
    small = surplus
    

c_num = b // c - (a - 1) // c
d_num = b // d - (a - 1) // d
cd_num = b // lcm - (a - 1) // lcm
num = b - a + 1

#print(num, c_num, d_num, cd_num, lcm)
ans = num - (c_num + d_num - cd_num)

print(ans)
# Judge status: Accepted
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
counter = 0
content = 0
ans = 0
h = []
heapq.heapify(h)
for i in range(m):
  while counter < n and ab[counter][0]==i+1:
    heapq.heappush(h,-ab[counter][1])
    counter+=1
    content+=1
  if content != 0:
    ans-=heapq.heappop(h)
    content-=1
print(ans)
# Judge status: Wrong Answer
import math

K = int(input())

n_pre = math.log(K/100, 1.01)

print(math.ceil(n_pre))
# Judge status: Wrong Answer
s = list(input())
ans = list("keyence")
x = 0

for c in s:
    if c == ans[x]:
        x += 1
    if x == 7:
        print("YES")
        exit()

print("NO")
# Judge status: Accepted
n,m = [int(x) for x in input().split()]
ab = []
for _ in range(m):
    tmp = [int(x) for x in input().split()]
    ab.append(tmp)

start = [x[1] for x in ab if x[0] == 1]
goal = [x[0] for x in ab if x[1] == n]

ans = "IMPOSSIBLE"

if len(set(start) & set(goal)) > 0:
    ans = "POSSIBLE"

print(ans)
# Judge status: Accepted
X = int(input())
list=[X]
count=1
while count <= 1000000:
    if X%2 == 0:
        X=X/2
    else:
        X=3*X+1
    count+=1
    if list.count(X) ==1:
        print(count)
        break
    list.append(X)
# Judge status: Accepted
N = int(input())
c = list(input())

if 'R' in c and 'W' in c:
  R = int(c.count('R'))
  c[0:R] = []
  print(c.count('R'))
else:
  print(0)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

cnt = [[0] * 2 for _ in range(61)]

for i in range(61):
    mask = 1 << i
    for j in range(n):
        if mask & a[j] >= 1:
            cnt[i][1] += 1
        elif mask & a[j] == 0:
            cnt[i][0] += 1
        else:
            continue

ans = 0
mod = 10**9 + 7
for i in range(61):
    ans += cnt[i][1] * cnt[i][0] * pow(2, i, mod)
    ans %= mod

print(ans)
# Judge status: Wrong Answer
N = int(input())
A_list = [int(e) for e in input().split()]

all_A_xor = A_list[0]
#print(A_list[0],bin(A_list[0]))

for i in range(1,N):
    #print(A_list[i],bin(A_list[i]))
    all_A_xor ^= A_list[i]

#print(all_A_xor,bin(all_A_xor))

ans = [A^all_A_xor for A in A_list]
print(ans)
# Judge status: Accepted
A, B=map(int, input().split())
if A<=5:
  print(0)
elif 6<=A<=12:
  print(B//2)
else:
  print(B)
# Judge status: Wrong Answer
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
p=[]
q=0
for c in a:
    t=0
    for d in p:
        if c%d==0:
            t=1
            break
    if t==0:
        q+=1
        p.append(c)
print(q)
# Judge status: Accepted
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    x,a,b = map(int, input().split())
    if abs(x-a)>abs(x-b):
        print('B')
    else:
        print('A')


if __name__ == '__main__':
    main()
# Judge status: Accepted
a,b = map(int,input().split())
s = list(input())
t1 = s[:a]
t2 = s[a]
t3 = s[a+1:]

t1 = ''.join(t1)
t3 = ''.join(t3)

def is_int(s):
    try:
        int(s)
        return True
    except ValueError:
        return False

if is_int(t1) == True and is_int(t3) == True and t2 == '-':
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
count = [0 for i in range(n+1)]
tmp = 0
for i in a:
  if i > n:
    tmp+=1
  else:
    count[i] += 1
  
ans = 0
for i in range(n+1):
  ans += min(abs(count[i] - i), count[i])
print(ans+tmp)
# Judge status: Wrong Answer
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
if x < a[0]:
    print(0)
    exit()

for i in range(N):
    if x >= a[i]:
        x = x - a[i]
        count += 1
    else:
        break
if x > 0:
    print(count - 1)
else:
    print(count)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
print(a)
Alice=[]
Bob=[]
for i in range(n):
            if i%2==0:
                        Alice.append(a[i])
            else:
                        Bob.append(a[i])
#print('Alice',Alice)
#print('Bob',Bob)

print((sum(Alice))-(sum(Bob)))
# Judge status: Accepted
def main():
    A, B, C = map(int, input().split())
    if B - A == C - B:
        print('YES')
    else:
        print('NO')
main()
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
cm = 1000
p1 = p2 = a[0]
for i in range(1,n):
    #print(i,a[i],p1,p2)
    if(a[i]>=p2):
        p2 = a[i]
    elif(a[i]<p2):
        cm += (cm//p1)*(p2-p1)
        p1 = p2 = a[i]
cm += (cm//p1)*(p2-p1)
print(cm)
# Judge status: Accepted
S = input().split()

#冷蔵庫
A = int(S[0])
#電子レンジ
B = int(S[1])
#割引券
M = int(S[2])



a = list(map(int,input().split()))
b = list(map(int,input().split()))
total_mini = min(a) + min(b)


for i in range(M):
    m = list(map(int,input().split()))
    amount = a[m[0]-1] + b[m[1]-1] - m[2]

    if total_mini > amount:
        total_mini = amount


print(total_mini)
# Judge status: Wrong Answer
x = int(input())
f = True
ans = 0
if x%2!=0:
  ans += 1
while f:
  ans+=1
  a = x//2
  if a < 1:
    f = False
  x = a
print(ans)
# Judge status: Accepted
d=[]

for i in range(5):
    s=int(input())
    if s%10 == 0:
        d.append((s,s,s%10))
    else:
        d.append((s,s+(10-s%10),10-s%10))

d.sort(key=lambda d:d[2])
result=0
result=sum(d[i][1] for i in range(len(d)-1)) + d[-1][0]

print(result)
# Judge status: Accepted
W,a,b = map(int, input ().split ())
if a < b:
  A,B = W+a,b
  if A >= B:
    print (0)
  else:
    print (B-A)
else:
  A,B = a,W+b
  if B >= A:
    print (0)
  else:
    print (A-B)
# Judge status: Accepted
import os, sys, re, math

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

price = 0 if A <= 5 else B // 2 if A <= 12 else B
print(price)
# Judge status: Wrong Answer
s = input().split()

N = int(s[0])
K = int(s[1])

i=1
while N > K **(i-1):
  if N < K**i:
    print(i)
  elif N == K**i:
    print(i+1)
  i += 1
# Judge status: Accepted
nk = list(map(int, input().split()))
N = nk[0]
K = nk[1]

d = input().split()
a = True
for i in range(N, 90001):
  a = True
  for j in d:
    if str(i).count(j) > 0:
      a = False
      break
  if a:
    print(i)
    break
# Judge status: Wrong Answer
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

s = [0] * (N+1)
p = 1
h = []
while True:
    h.append(p)
    s[p] = 1
    p = A[p]

    if s[p] != 0:
        break

last = h.index(p)
leng = len(h) - last
rem = (K - last) % leng
print(h[last:][rem])
# Judge status: Accepted
N=input()
L=len(N)
if int(N[0]*L)>=int(N):
    print(int(N[0]*L))
else:
    print(int((N[0])*L)+111)
# Judge status: Accepted
def main():
    x,y = map(int, input().split())

    if y>=x:
        print(min(y-x,abs(y+x)+1))
    else:
        print(min(abs(y+x)+1,abs(y-x)+2))


if __name__ == '__main__':
    main()
# Judge status: Accepted
n,k,q=map(int,input().split())
ans=[k-q]*n
h=[]
for i in range(q):
	h.append(int(input()))
for j in h:
	ans[j-1]+=1
for k in ans:
	if k>=1:
		print('Yes')
	else:
		print('No')
# Judge status: Accepted
import numpy as np

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

xy45 = [[xy[i][0] - xy[i][1], xy[i][0] + xy[i][1]] for i in range(N)]
xy45 = np.array(xy45)

print(max(max(xy45[:, 0]) - min(xy45[:, 0]), max(xy45[:, 1]) - min(xy45[:, 1])))
# Judge status: Accepted
s = list(input())
q = int(input())
a = []
f = False #さかさま
for i in range(q):
    x = list(input().split())
    if x[0]=='1':
        f = not f
    else:
        if f:
            if x[1]=='1': s.append(x[2])
            else: a.append(x[2])
        else:
            if x[1]=='1': a.append(x[2])
            else: s.append(x[2])
a.reverse()
s = a+s
if f:s.reverse()
print(''.join(s))
# Judge status: Accepted
import math
N = int(input())
if N % 2 == 1:
    print(0)
else:
    div10 = N // 10
    sum_val = div10
    if sum_val > 0:
        count_5 = math.floor(math.log(div10, 5))
        for i in range(count_5):
            sum_val += div10 // pow(5, i + 1)
    print(sum_val)
# Judge status: Wrong Answer
n = int(input())

res = []
for i in range(n):
  city, value = input().split()
  value = int(value)
  res.append([city, value, i])
res_s = sorted(res, key = lambda x: (x[0], x[1]))
for i in range(n):
  res_s[i].append(i)
ans = sorted(res_s, key = lambda x: x[2])
for i in range(n):
  print(ans[i][3])
# Judge status: Accepted
n,m,k= map(int, input().split())

for i in range(n+1):
    for j in range(m+1):
        x=i*m+j*n-2*(i*j)
        if k==x:
            print('Yes')
            exit()
print('No')
# Judge status: Accepted
import sys
import heapq
input = sys.stdin.readline

n = int(input())
query = []
for i in range(n):
    x, l = map(int, input().split())
    query.append([x+l, x-l])

# 貪欲
heapq.heapify(query)

finish, start = heapq.heappop(query)
time = finish
count = 1
while len(query) > 0:
    finish, start = heapq.heappop(query)
    if start >= time:
        time = finish
        count += 1
    else:
        continue
print(count)
# Judge status: Accepted
N=int(input())
A=list(int(input()) for _ in range(5))

mini=min(A)        
print(int((N-1)/mini)+5)
# Judge status: Accepted
N, M = map(int, input().split())

min_NM = min(N,M)
max_NM = max(N,M)

if min_NM == 1 and max_NM == 1:
    print(1)
elif min_NM == 1:
    print(max_NM-2)
else:
    if min_NM == 2:
        print(0)
    else:
        ans = (N-2)*(M-2)
        print(ans)
# Judge status: Wrong Answer
S = input()

if 'N' in S:
  if not 'S' in S:
    print('No')
    exit()
if 'S' in S:
  if not 'N' in S:
    print('No')
    exit()
if 'E' in S:
  if not 'W' in S:
    print('No')
    exit()
if 'W' in S:
  if not 'E' in S:
    print('No')
    exit()
print('YES')
# Judge status: Wrong Answer
l = int(input())

def f(x,y):
    z = l-x-y
    if z<1 or z>l:
        print(x,y,z)
        return -1
    return x*y*z

def fp(x,y):
    dx = y*(l-x-y) - x*y
    dy = x*(l-x-y) - x*y
    return dx,dy

x = 1.0
y = 1.0
while True:
    dx,dy = fp(x,y)
    if dx<10**-8 and dy<10**-8:
        print(f(x,y))
        exit()

    x += dx * 10**-4
    y += dy * 10**-4
# Judge status: Wrong Answer
import math

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

p = 0
for i in range(n):
    if aa[i] == 1:
        p = i
        break

x = 0
k -= 1
x += math.ceil(p / k)
x += math.ceil((n - p - 1) / k)
print(x)
# Judge status: Wrong Answer
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [(A[i], 1) for i in range(N)]
for _ in range(M):
    B, C = map(int, input().split())
    BC.append((C,B))
BC = sorted(BC,reverse = True)
ans = 0
a = 0
count = N
for c,b in BC:
  print(b,c)
  lamb = min(count,b)
  ans += c * lamb
  count -= lamb

print(ans)
# Judge status: Accepted
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
a = ls[n // 2] - ls[(n // 2) - 1]
print(a)
# Judge status: Accepted
N,M = map(int,input().split())
dic = {}
for _ in range(N):
  a, b = map(int,input().split())
  if a in dic:
    dic[a] += b
  else:
    dic[a] = b
List = sorted(dic)
ans = 0
i = 0
while M > 0:
  M -= dic[List[i]]
  ans = List[i]
  i += 1
print(ans)
# Judge status: Accepted
# coding:utf-8

N = int(input())
X = [el for el in map(int, input().split(' '))]
ans = 2 ** 63 - 1

for point in range(100):
    tmp = 0
    for x in X:
        tmp += (x - point) ** 2
    if ans > tmp:
        ans = tmp

print(ans)