peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import numpy as np

N,M=map(int,input().split())
A=np.array([list(str(input())) for i in range(N)])
B=np.array([list(str(input())) for j in range(M)])
ans="No"

for i in range(N-M+1):
    for j in range(N-M+1):
        x=[s[j:M+j] for s in A[i:M+i]]
        if np.count_nonzero((x==B)==0) == 0:
            ans="Yes"

print(ans)
# Judge status: Accepted
import collections

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

b = collections.Counter(a)
b = list(b.values())
b.sort()
ans = 0
for i in range(len(set(a))-k):
    ans += b[i]
print(ans)
# Judge status: Accepted
def main():
    n = int(input())
    A = list(map(int,input().split()))

    A.sort(reverse = True)

    # print(A)
    B = [A[0]]
    for i in A[1:]:
        B.append(i)
        B.append(i)

    print(sum(B[:n-1]))


main()
# Judge status: Accepted
a,b,c=[int(i) for i in input().split()]
if a+b>=c:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a=list(input())
b=list(input())
ans=[]
for i in range(len(b)):
    ans.append(a[i])
    ans.append(b[i])
ANS=''.join(ans)
print(ANS if len(a)==len(b) else ANS+a[len(a)-1])
# Judge status: Wrong Answer
N, L = map(int, input().split())
s = list(input().split())

t = ''.join(sorted(s))
print(t)
# Judge status: Accepted
N=int(input())
K=int(input())
X=int(input())
Y=int(input())
if N<=K:
    ans=N*X
else:
    ans=K*X+(N-K)*Y
print(ans)
# Judge status: Accepted
n = int(input())
s = input()
if (n%2 == 1):
  print("No")
else:
  c = 0
  for i in range(int(n/2)):
    if (s[i] != s[i + int(n/2)]):
      c = 1
  if (c == 0):
    print("Yes")
  else:
    print("No")
# Judge status: Wrong Answer
A, B, C = map(str, input().split())

print(C+' '+B+' '+A)
# Judge status: Accepted
from collections import defaultdict
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
d = defaultdict(int)
for _ in range(n):
    a, b = LI()
    d[a] += b

d = sorted(d.items(), key=lambda x: x[0])
# print(d)
i = 0
ans = 1
cnt = 0
while cnt < k:
    ans = d[i][0]
    cnt += d[i][1]
    i += 1
print(ans)
# Judge status: Wrong Answer
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for _ in range(M)]
pay = 0
min_pay = 0
for i in range(M):
  pay = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]
  if i == 0:
    min_pay = pay
  min_pay = min(min_pay,pay)
for j in range(min(len(a),len(b))):
  min_pay = min(min_pay,a[j]+b[j])
print(min_pay)
# Judge status: Wrong Answer
S, T = map(str, input().split())
A, B = map(int, input().split())
U = input()

dict = {S: A, T: B}

dict[U] = dict[U] - 1

values = []
for k, v in dict.items():
    print(v, end=" ")
# Judge status: Accepted
n = int(input())
a = 0
for i in reversed(range(1,int(n**(1/2))+1)):
    if n % i == 0:
        a = i
        break
b = int(n / a)
print(a+b-2)
# Judge status: Wrong Answer
s = input()

t = 'a'
for i in range(1, len(s)):
    t += s[i]
    if s[i] == 'C':
        t += 'c'

if s[0] == 'A' and s[2:-1].count('C') == 1 and t.islower:
    print('AC')
else:
    print('WA')
# Judge status: Accepted
# C - Snack
from fractions import gcd
a,b = map(int,input().split())
print(a*b//gcd(a,b))
# Judge status: Wrong Answer
N, M = map(int, input().split())

H = list(map(int, input().split()))

good_H = [1] * N

for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] < H[B-1]:
        good_H[A-1] = 0
    elif H[A-1] > H[B-1]:
        good_H[B-1] = 0

print(good_H.count(1))
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))

mod = 10**9 + 7
res = 0
for i in range(60):
    cnt_one  = sum([a[j]&1 for j in range(n)]) #1とのandをとり，1の個数をカウント
    cnt_zero = n - cnt_one
    res += 2**i * cnt_one * cnt_zero
    a = [a[j]>>1 for j in range(n)] #各要素に対し，右に1ビットシフト
print(res % mod)
# Judge status: Wrong Answer
n,m=map(int,input().split())
d={}
for _ in range(n):
    a,b=map(int,input().split())
    d[a]=b
d2 = dict(sorted(d.items()))
def c(dic):
    s=0
    cost=0
    for x in d2.keys():
        for _ in range(d2[x]):
            cost+=x
            s+=1
            if s==m:
                return cost
print(c(d2))
# Judge status: Accepted
x = int(input())

a = x // 500
b = (x - (a * 500)) // 5
c = (a * 1000) + (b * 5)
print(c)
# Judge status: Accepted
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
a,b,c,d=0,w,0,h
for x,y,A in l:
    if A==1:
        a=max(a,x)
    elif A==2:
        b=min(b,x)
    elif A==3:
        c=max(c,y)
    else:
        d=min(d,y)
# print(f"b-a:{b-a},d-c:{d-c}")
print((b-a)*(d-c) if b-a>=0 and d-c>=0 else 0)
# Judge status: Wrong Answer
# https://atcoder.jp/contests/agc015/tasks/agc015_a

import math
n, a, b = map(int, input().split())

if b < a:
    print(0)
elif a != b and n == 1:
    print(0)
else:
    t = b - a + 1
    ans = math.factorial(t + n - 1) // (math.factorial(t) * math.factorial(n))
    print(ans)
# Judge status: Accepted
a = int(input())
b = int(input())
h = int(input())

print((a+b)*h//2)
# Judge status: Accepted
X = int(input())
now = 0
maxjump = 1
while now+maxjump < X:
    now += maxjump
    maxjump += 1
print(maxjump)
# Judge status: Accepted
N = str(input())
if "7" in N:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
A,B,C = map(int, input().split())
if A+B >= C:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
X = int(input())

ans = 0
check = 0
for i in range(1, 10**7):
    ans += i
    check += 1
    if X <= ans:
        print(check)
        break
# Judge status: Accepted
N,M = map(int,input().split())
X = sorted([list(map(int,input().split())) for n in range(N)])
G = 0
D = 0

for m in range(M):
  if D+X[m][1]<M:
    D+=X[m][1]
    G+=X[m][0]*X[m][1]
  else:
    G+=X[m][0]*(M-D)
    print(G)
    exit()
# Judge status: Accepted
n, m = map(int, input().split())

r = [False] * n
r[0] = True
l = [1] * n

for _ in range(m):
    x, y = map(int, input().split())
    l[x - 1] -= 1
    l[y - 1] += 1
    r[y - 1] = r[x - 1] | r[y - 1]
    if not l[x - 1]:
        r[x - 1] = False

c = 0
for i in range(n):
    if r[i] == True and l[i] > 0:
        c += 1

print(c)
# Judge status: Wrong Answer
n, m = map(int, input().split())
wa = [0]*(n+1)
ac = [False]*(n+1)
for i in range(m):
    p, s = input().split()
    p = int(p)
    if ac[p]:
        continue
    if s == 'WA':
        wa[p] += 1
    elif s == 'AC':
        ac[p] = 1
print(sum(ac[1:]), sum(wa[1:]))
# Judge status: Accepted
s = input()
x = 0
y = 0
for i in range(len(s)):
  if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
    x = x + 1
  else:
    if y < x:
      y = x
    x = 0
if y < x:
  y = x
print(y)
# Judge status: Wrong Answer
a, b, c = map(int,input().split())
ans = 0
l = [a]

while True:
    ans += 1
    x = b//2 + c//2
    y = a//2 + c//2
    z = a//2 + b//2
    if x%2 == 1 or y%2 == 1 or z%2 == 1:
        break
    else:
        a = x
        if a in l:
            print(-1)
            exit()
        else:
            l.append(a)
            b = y
            c = z

print(ans)
# Judge status: Wrong Answer
s=list(input().split())
t=list(input().split())
ans=0
for i in range(len(s)):
  if s[i]!=t[i]:
    ans+=1
print(ans)
# Judge status: Accepted
n=int(input())
s=input()
l=int(len(s))
m=0
if l%2==0:
  a=s[0:l//2]
  b=s[l//2:l]
  for i in range(n//2):
    if a[i]!=b[i]:
      m+=1
  if m==0:
        print("Yes")
  else:
        print("No")
else:
  print("No")
# Judge status: Accepted
def main():
    S = input()
    first = S[:2]
    second = S[2:]
    YYMM = False
    MMYY = False

    if "00" <= first <= "99" and "01" <= second <= "12":
        YYMM = True
    if "01" <= first <= "12" and "00" <= second <= "99":
        MMYY = True

    if YYMM and MMYY:
        ans = "AMBIGUOUS"
    elif YYMM:
        ans = "YYMM"
    elif MMYY:
        ans = "MMYY"
    else:
        ans = "NA"

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
print(sum(a[1:-n:2]))
# Judge status: Accepted
import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = [i - 1 for i in map(int, readline().split())]

m = 60
d = [A]
pre = A
for i in range(m):
    current = [pre[pre[j]] for j in range(n)]
    d.append(current)
    pre = current

route = 0
for i in range(m-1, -1, -1):
    if k >= (x := 1 << i):
        route = d[i][route]
        k -= x
print(route+1)
# Judge status: Accepted
n,k=map(int,input().split())
print(0 if n%k==0 else 1)
# Judge status: Wrong Answer
n,x,t = map(int,input().split())
if n % x == 0:
  print(n / x * t)
else:
  print(n / x * t + 1)
# Judge status: Accepted
print("Yes" if "9" in input() else "No")
# Judge status: Accepted
def isOK(s,t):
  m = [None] * 26
  for i,j in zip(s,t):
    num = ord(i) - ord("a")
    if m[num] == None:
      m[num] = j
    else:
      if m[num] != j:
        return False
  return True

s = input()
t = input()
if isOK(s,t) and isOK(t,s):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
def min(a,b):
	if a < b:
		return a
	return b

while t > 0:
	t -= 1
	# a,b = map(int,input().split())
	n = int(input())
	v = list(map(int,input().strip().split()))[0:n]
	i = 0
	ans = 0
	while i < n:
		j = i
		while j+1 < n and v[j+1] <= v[j]:
			j += 1
		l = j-i+1
		ans = max(ans,l)
		i = j+1
	print(ans-1)
# Judge status: Accepted
s=str(input())
t=str(input())
print("YES" if s[0]==t[2] and s[1]==t[1] and s[2]==t[0] else "NO")
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))

ans = 10**11
sum_A = sum(A)
l = 0

for a in A:
    l += a
    if abs(l - (sum_A - l)) < ans:
        ans = abs(l - (sum_A - l))

print(ans)
# Judge status: Wrong Answer
from collections import deque

n,m=map(int,input().split())
step=list(range(2,n+1))
broken=[]
for i in range(m):
    broken+=[int(input())]
mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
if m==0:
    dp[1]=1
elif not broken[0]==1:
    dp[1]=1
b=deque(broken)
if len(broken) != 0:
    bad_one = b.popleft()
else:
    bad_one = -1
for i in step:
    if i != bad_one:
        dp[i]=(dp[i-1]+dp[i-2])%mod
    elif i == bad_one and len(b) != 0:
        bad_one = b.popleft()
print(dp[n])
# Judge status: Accepted
b = input()

print("x" * len(b))
# Judge status: Accepted
N=int(input())

for i in range(26):
    for j in range(15):
        if 4*i+7*j==N:
            print("Yes")
            exit()
           
            
print("No")
# Judge status: Accepted
import math

N = int(input())

lower = N / 1.08

vl = math.ceil(lower)

if math.floor(vl * 1.08) == N:
  print(vl)
else:
  print(":(")
# Judge status: Wrong Answer
#!/usr/bin/env python3
# input
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
t.sort()
ans = 1
now = t[0]
cnt = 1
for i in range(n):
    if t[i] - now > k or cnt > c:
        plus_bit = 1
        now = t[i]
        cnt = 1
        ans += 1
    else:
        cnt += 1
print(ans)
# Judge status: Accepted
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
x=[[int(i) for i in input().split()] for i in range(m)]
ans=min(A)+min(B)

for s,t,u in x:
    tmp=A[s-1]+B[t-1]-u
    ans=min(ans,tmp)
print(ans)
# Judge status: Accepted
n = int(input())
for i in range(100,1000):
    if i >= n and i%100//10 == i%10 == i//100:
        print(i)
        break
# Judge status: Wrong Answer
n,m = map(int,input().split())
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append([str(a),b])
li = sorted(li)
coin = 0
cnt = 0
i = 0
while cnt != m:
    if li[i][1]>0:
        cnt+=1
        coin += int(li[i][0])
        li[i][1]-=1
    else:
        i+=1
print(coin)
# Judge status: Wrong Answer
import math
i = int(input())
print(math.sqrt(i))
# Judge status: Accepted
import math

n, k = map(int, input().split())
prob = 0
for i in range(1,n+1):
    if i <= k-1:
        x = math.floor(1+math.log2(((k-1)/i)))
       
        prob += (1/2)**x
    else:
        prob += 1
print(prob/n)
# Judge status: Accepted
N = int(input())
A = [ int(input()) for i in range(N)]

_A =sorted(A, reverse=True)
A_max = _A[0]
A_second_max = _A[1]

for i in range(N):
    if A[i] == A_max:
        print(A_second_max)
    else:
        print(A_max)
# Judge status: Accepted
from collections import Counter
input();a=Counter(map(int,input().split()))
print(sum([j if i>j else j-i for i,j in a.items()]))
# Judge status: Wrong Answer
n = int(input())

if n%2 == 1:
  ans = (n-1)/2+1 / n
else:
  ans = 1/2
print(ans)
# Judge status: Accepted
N, M = list(map(int, input().split()))

def comb2(x):
    return x * (x - 1) / 2

print(int(comb2(N) + comb2(M)))
# Judge status: Accepted
N = int(input())
lamps = [0] * N
next_ = 0
count = 0
buttons = list(map(lambda x: int(x) - 1, (input() for _ in range(N))))
while True:
    count += 1
    lamps[next_] = 1
    next_ = buttons[next_]
    if next_ == 1:
        break
    if lamps[next_]:
        count = -1
        break

print(count)
# Judge status: Wrong Answer
n = int(input()) 
a_list = list(map(int, input().split()))

if a_list == list(range(1, len(a_list) + 1)):
    print(0)

cond_idx = 0
for num in range(1, len(a_list)):
    if num == 1:
        if num not in a_list:
            print(-1)
            break
    
    if num in a_list[cond_idx:]:
        cond_idx += a_list[cond_idx:].index(num)
#         print(num, cond_idx)
    else:
        print(n - num + 1)
        break
# Judge status: Accepted
x,y=map(int,input().split())
if y%2!=0:
    print("No")
    exit()

if 2*x<=y<=4*x:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
s = input()
s = s[::-1]
j = 0
p = len(s)
while True:
    if s[j:j+5] == 'maerd':
        j += 5
    elif s[j:j+7] == 'remaerd':
        j += 7
    elif s[j:j+5] == 'esare':
        j += 5
    elif s[j:j+6] == 'resare':
        j += 6
    else:
        print('NO')
        break
    if j == p:
        print('YES')
        break
# Judge status: Accepted
import sys
input = sys.stdin.readline
from collections import Counter

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

C = Counter(A)
cannot = set()
L= max(A)
ans = 0
for a in A:
    if a in cannot: continue
    if C[a] == 1:
        ans += 1
    ind = 1
    while a*ind <= L:
        cannot.add(a*ind)
        ind += 1

print(ans)
# Judge status: Accepted
f = input()
g = input()
g = list(g)
g.reverse()
p = (''.join(g))
if p == f:
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]

h.sort()
inf = float('inf')
min_ = inf

for i in range(n - k):
    if h[i+k-1] - h[i] < min_:
        min_ = h[i+k-1] - h[i]
print(min_)
# Judge status: Accepted
a,b,c,d = input()
print("Yes" if a==b==c or b==c==d else "No")
# Judge status: Wrong Answer
N = int(input())

if N == 1:
    print(1)
else:
    s = 0
    l = []
    for i in range(1, N):
        s += i
        l.append(i)
        if s > N:
            break
    # print(l)

    for i in range(len(l)):
        if s-l[i] == N:
            l.pop(i)
            break

    for i in l:
        print(i)
# Judge status: Wrong Answer
N = int(input())
W = [input() for i in range(N)]
if all(W[i+1][0]==W[i][-1] and W[i] not in W[:i] for i in range(N-1)):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n, *a = map(int, open(0).read().split())
a.sort()
ans = 1e10
for i in range(1, n):
    x, y = a[0], a[i]
    while y%x:
        y -= y//x*x
        x, y = y, x
    ans = min(ans, x)
print(ans)
# Judge status: Accepted
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(n-2):
  if (p[i]<p[i+1]<p[i+2]) or (p[i]>p[i+1]>p[i+2]):
    ans+=1
print(ans)
# Judge status: Accepted
P,Q,R = map(int,input().split())
print(P+Q+R-max(P,Q,R))
# Judge status: Wrong Answer
A,B=map(float,input().split())
X=A*(B*100)/100
print(int(X))
# Judge status: Accepted
N=int(input())
*P,=map(int,input().split())

i=c=0
while i<N:
  if P[i]==i+1:
    c+=1
    i+=1
  i+=1
print(c)
# Judge status: Accepted
A,B,C= map(int, input().split())
cot = 0
while True:
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        break
    else:
        tempA = (B + C)//2
        tempB = (A + C)//2
        tempC = (B + A)//2
        A = tempA
        B = tempB
        C = tempC
        cot += 1

        if cot > 1000000:
            print(-1)
            exit(0)
            
print(cot)
# Judge status: Accepted
n, m = map(int, input().split())
if m%2 == 1:
  # for i in range(m):
  #   print(str(i+1) + ' ' + str(2*m-i))
  for i in range(int((m-1)/2)):
    print(str(i+1) + ' ' + str(m-i))
  for i in range(int((m+1)/2)):
    print(str(m+i+1) + ' ' + str(2*m-i+1))
else:
  for i in range(int(m/2)):
    print(str(i+1) + ' ' + str(m-i+1))
  for i in range(int(m/2)):
    print(str(i+m+2) + ' ' + str(2*m-i+1))
# Judge status: Wrong Answer
import sys
S = input()
if len(S) != 10:
    sys.exit()
if S[0:8] != '2017/01/':
    sys.exit()
if 1 <= int(S[-2:]) <= 31:
    sys.exit()

print(S.replace('2017','2018'))
# Judge status: Accepted
N = [int(i) for i in list(input())]

# コーナーケース
if len(N) == 1:
    print(N[0])
    exit()
elif set(N[1:]) == set([9]):
    print(N[0] + (len(N) - 1) * 9)
    exit()

ans = 0
s = 0
for i in range(len(N)):
    if N[i] == 0:
        continue
    ans = max(ans, s + (N[i] - 1) + 9 * (len(N) - 1 - i))
    s += N[i]

print(ans)
# Judge status: Accepted
s = list(input())
if ('N' in s) == ('S' in s) and ('E' in s) == ('W' in s):
  print('Yes')
else:
  print('No')
# Judge status: Accepted
import itertools
n,m,q=map(int,input().split())
a=[0 for i in range(q)]
b=[0 for i in range(q)]
c=[0 for i in range(q)]
d=[0 for i in range(q)]
for i in range(q):
    a[i],b[i],c[i],d[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
ans=0

for i in itertools.combinations_with_replacement(range(1,m+1),n):
    tmp=0
    for j in range(q):
        if i[b[j]] - i[a[j]] == c[j]:
            tmp+=d[j]
    ans=max(ans,tmp)
print(ans)
# Judge status: Wrong Answer
s = input()
sl = list(s[i] for i in range(len(s)))


cnt = 0
 
for i in range(len(s)-2):
    if sl[i] == sl[i+1]:
        sl[i+2] = "0"
        cnt += 1
if s[-3] != "0" and s[-2] == s[-1]:
    cnt += 1
 
print(len(s) - cnt)
# Judge status: Accepted
N = int(input())
S = input()

ans = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for d in range(N):
        j = i+d
        k = j+d
        if k < N:
            if S[i] != S[j] and S[k] != S[j] and S[k] != S[i]:
                ans -= 1
print(ans)
# Judge status: Accepted
N = int(input())
s = [int(input()) for _ in range(N)]

s.sort()
mod = [i%10 for i in s]
ans = sum(s)

if ans%10 == 0:
    if mod.count(0)==N:
        ans=0
    else:
        for i in range(N):
            if mod[i]!=0:
                ans -=s[i]
                break
            
print(ans)
# Judge status: Wrong Answer
from collections import Counter
N = int(input())
A = [int(input()) for _ in range(N)]
counter = Counter(A)
if counter.most_common()[0][0] >= N//2:
    print(counter.most_common()[0][0])
    exit()
ans = 0
while True:
    tmp = -1
    for i in range(N):
        if A[i] > tmp:
            tmp = A[i]
            A[i] = -1
    if tmp == -1:
        break
    ans += 1
print(ans)
# Judge status: Accepted
n, k = map(int, input().split())
ans = l = 0
for i in input():
    ans += (n==i)
    n = i
    l += 1
print(min(ans+2*k, l-1))
# Judge status: Accepted

from collections import Counter

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

MOD = 998244353
ctr = Counter(X)

if X[0] == 0 and ctr[0] == 1:
    ans = 1
    for i in range(1, max(X) + 1):
        ans *= pow(ctr[i - 1], ctr[i], MOD)
        ans %= MOD
    print(ans)
else:
    print(0)
# Judge status: Accepted
N = int(input())
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

T = [int(input()) for _ in range(N)]
ans = T[0]
for e in T:
    ans = lcm(e,ans)
print(ans)
# Judge status: Accepted
s = "0" + input()
n = len(s)
S = []
for i in range(n-1,-1,-1):
    S.append(int(s[i]))

ans = sum(S)
ans0 = ans
D = [[0] * 3 for i in range(n)]
D[0] = [S[0], S[0]+1, 10-S[0]]
for i in range(1, n):
    D[i][0] = min(D[i-1][0], D[i-1][1]) + S[i]
    D[i][1] = D[i-1][2] + S[i] + 1
    D[i][2] = min(D[i-1][0]+10-S[i], D[i-1][1]+10-S[i], D[i-1][2]+9-S[i])

# print(D)
print(min(D[-1][:2]))
# Judge status: Accepted
# ABC 066 C
N = int(input())
A = input().split()
from collections import deque

tmp = deque([])
for i,a in enumerate(A):
    if i %2!=0:
        tmp.appendleft(a)
    else:
        tmp.append(a)
if N%2!=0:
    tmp.reverse()
print(' '.join(tmp))
# Judge status: Accepted
import sys
import fractions
N,M=map(int, input().split())
A = [int(a) for a in input().split()]
A2 = [a>>1 for a in A]

lcm = A2[0]
for i in range(1, N):
    lcm = lcm * A2[i] // fractions.gcd(lcm, A2[i])
    if lcm>M:
        print(0)
        sys.exit()
    
B = sum([1 for a in A if lcm%a==0])
if B>0:
    print(0)
else:
    print((M//lcm+1)//2)
# Judge status: Accepted
X = int(input())

count = 0

if X == 1:
  print("1")
  quit()
if X == 2:
  print("2")
  quit()

for i in range(1, X):
  count += i
  if count >= X:
    print(i)
    quit()
# Judge status: Wrong Answer
n=int(input())
l=list(map(int,input().split()))
res=0
if(n<2):
    print(0)
else:
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if(l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]):
                    if(l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j]):
                        res+=1
print(res)
# Judge status: Accepted
n = input()

if n[len(n) - 1] == '3':
  print('bon')
elif n[len(n) - 1] == '0' or n[len(n) - 1] == '1' or n[len(n) - 1] == '6' or n[len(n) - 1] == '8':
  print('pon')
else:
  print('hon')
# Judge status: Accepted
a, b = map(int, input().split())

if a > b:
    print(a + a - 1)
elif a == b:
    print(a + b)
else:
    print(b + b - 1)
# Judge status: Accepted
N, W = map(int, input().split())

import numpy as np

dp = np.zeros(W + 1, dtype=int)

for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])

print(dp.max())
# Judge status: Wrong Answer
k,x = map(int, input().split())
prob = [i for i in range(x-k+1,x+k)]
print(prob)
# Judge status: Accepted
#!/usr/bin/env python3
import sys


YES = "yes"  # type: str
NO = "no"  # type: str


def solve(S: str):
    print(YES if len(S) == len(set(S)) else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()
# Judge status: Accepted
def main():
    P, Q, R = (int(x) for x in input().split())
    print(min(P + Q, Q + R, R + P))


if __name__ == "__main__":
    main()
# Judge status: Accepted
print(len(set([int(i) for i in input().split()])))
# Judge status: Accepted
N = int(input())
ans = "No"
for i in range(N // 7 + 1):
    for j in range((N - i*7) // 4 + 1):
        if 7*i + 4*j == N:
            ans = "Yes"
print(ans)
# Judge status: Accepted
n = str(input())
total = 0
for i in range(len(n)):
    total += int(n[i])
if total % 9 == 0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
def gen_pattern(N, pre=""):
  for c in range(0x61, ord(max(pre or "\x60"))+2):
    pat = pre+chr(c)
    if len(pat) == N:
      yield pat
    else:
      yield from gen_pattern(N, pat)

for pattern in gen_pattern(int(input())):
  print(pattern)
# Judge status: Wrong Answer
given = input()

data = given.strip().split()
X = int(data[0])
Y = int(data[1])

i = 0
ashi = 0
while (i < X):
    ashi = 2 * (X - i) + 4 * i
    if ashi == Y:
        print("Yes")
        break
    i = i + 1

if i == X:
    print("No")