peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0] + 2 * sum(a[1:n // 2])
if n % 2:
    ans += a[n // 2]
print(ans)
# Judge status: Accepted
n=int(input())
moji=str(input())
cnt=0
for i in range(n):
  count = 0
  temp=moji[:i+1]
  lst=[]
  for j in range(i+1):
    if temp[j] in moji[i+1:] and temp[j] not in lst:
      count+=1
      lst.append(temp[j])
  if count > cnt:
    cnt=count
print(cnt)
# Judge status: Accepted
a, b, c = map(int, input().split())
if (a == b and a != c) or (a ==c and a != b) or (b == c and b != a):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
count = 0

for i in range(n+1):
    new = 0
    while i % 2 == 0 and i != 0:
        new += 1
        i /= 2
    if new > count:
        count = new
print(2**count)
# Judge status: Accepted
a = list(map(int,input().split()))
a.sort()
if a[0] == a[1]:
	if a[1] == a[2]:
		print("No")
	else:
		print("Yes")
else:
	if a[1] == a[2]:
		print("Yes")
	else:
		print("No")
# Judge status: Wrong Answer
n,m = map(int,input().split())
if n <= 1:
  n = 0
else:
  n = n * (n-1) / 2
if m <= 1:
  m = 0
else:
  m = m * (m-1) / 2
print(n+m)
# Judge status: Accepted
s = input()

count = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '0':
            count += 1
    else:
        if s[i] == '1':
            count += 1
print(min(len(s)-count, count))
# Judge status: Wrong Answer
n = int(input())
s = input()

if n % 2 == 1:
    print('No')
    exit()

for i in range(n // 2):
    if s[i] != s[n // 2 - 1 + i]:
        print('No')
        exit()

print('Yes')
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))
a = sorted(p)
b = 0
for i in range(n):
    if p[i] != a[i]:
        b += 1
if b == 2 or b == 0:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
import numpy as np

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

for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M,j:j+M] == B).all():
      print('Yes')
      quit()

print('No')
# Judge status: Wrong Answer
a, b = map(float, input().split())
print(int(a*b))
# Judge status: Accepted

k = int(input())
s = str(input())
if k < len(s):
    print(s[:k] + "...")
else:
    print(s[:k])
# Judge status: Wrong Answer
N,A,B = map(int,input().split())
S = input()

pass_num = 0

for i in S:
    if i == 'a':
        if (A + B)-1 >= pass_num:
            print('Yes')
            pass_num += 1
        else:
            print('No')
    elif i == 'b':
        if B-1 >= pass_num:
            print('Yes')
            pass_num += 1
        else:
            print('No')
    else:# i == 'c'
        print('No')
# Judge status: Wrong Answer
t = int(input())
for i in range(t):
  if i < 6:
    print(0)
  else:
    tmp = i - 3
    num = 0
    for x in range(tmp):
      x += 1
      for y in range(tmp-x):
        y += 1
        for z in range(tmp-x-y):
          z += 1
          if i == x**2 + y**2 + z**2 + x*y + x*z + y*z:
            num += 1
    print(num)
# Judge status: Accepted
#abc044 b
s=input()
moji=dict()
flag=True
for i in s:
    if i not in moji:
        moji[i]=1
    else:
        moji[i]+=1

for i in moji.values():
    if i%2==1:
        flag=False
        break
print("Yes" if flag else "No")
# Judge status: Accepted
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    X,N = map(int,input().split())
    P = set(map(int,input().split()))
    ans = -1
    M = INF
    for i in range(X - 105,X + 105):
        if i not in P:
            if M > abs(i - X):
                ans = i
                M = abs(i - X)
    print(ans)
if __name__ == '__main__':
    main()
# Judge status: Accepted
a,b,c,d,e = map(int,input().split())

x = [a,b,c,d,e]

for i in range(len(x)):
  if x[i] == 0:
    print(i+1)
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-

r, g, b = map(int, input().split())
n = r*100 + g*10 + b
print("{}".format(n))

if n % 4 == 0:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
from collections import Counter
c = Counter(input())
labels = ['a', 'b', 'c']
min_cnt = min(c[label] for label in labels)
cnt = [c[label] - min_cnt for label in labels]
for x in cnt:
    if x in (0, 1):
        continue
    print('NO')
    break
else:
    print('YES')
# Judge status: Wrong Answer
n = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(0, n-1):
    x = abs(p[i]-p[i+1])
    if x != 1:
        cnt += 1

if cnt < 3:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
a,b=map(int,input().split())
s=input()
print('Yes' if len(s)==a+b+1 and all(s[i] in '0123456789' if i!=a else s[i]=='-' for i in range(len(s))) else 'No')
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

total = 0
total += sum(b)
for i in range(n-1):
    if a[i] + 1 == a[i+1]:
        total += c[a[i]-1]
print(total)
# Judge status: Wrong Answer
A, B, C = input().split()

print(max(int(A+B) + int(C), int(B+C) + int(A), int(A+C) + int(B)))
# Judge status: Accepted
from math import sqrt
a, b = map(int, input().split())
i = 1
while i <= b:
  i *= 10
  a *= 10
X = a + b
if int(sqrt(X)) ** 2 == X:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n = int(input())
C = []
S = []
F = []
for _ in range(n-1):
  c,s,f = map(int, input().split())
  C.append(c)
  S.append(s)
  F.append(f)

for i in range(n-2):
  ans = C[i]+S[i]
  for j in range(i+1, n-1):
    if S[j] >= ans:
      ans += (S[j]-ans) + C[j]
    else:
      if (ans-S[j])%F[j] == 0: ans += C[j]
      else: ans += F[j] - (ans-S[j])%F[j] + C[j]
  print(ans)
print(C[-1]+S[-1])
print(0)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
N,H=map(int,input().split())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)


amax=max(A)
#print(amax)
b=[]
for i in range(N):
    if B[i]>=amax:
        b.append(B[i])
b.sort()
#print(b)
cnt=0
while b:
    if H>0:
        H-=b.pop()
        cnt+=1
    if H<=0:
        #print(cnt)
        exit()

cnt+=-(-H//amax)
print(cnt)
# Judge status: Accepted
import copy
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
count = 0
for i in range(len(a)-1):
    count += a[(i+1)//2]
print(count)
# Judge status: Accepted
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
a,b=map(int,input().split())
g=gcd(a,b)

c=1
for i in range(2,10**6+1):
  if g%i==0:
    c+=1
    while g%i==0:
      g//=i
if g!=1:
  c+=1
print(c)
# Judge status: Wrong Answer
abc = input()
abc_ls = abc.split()
a = int(abc_ls[0])
b = int(abc_ls[1])
print( a * b / 2 )
# Judge status: Wrong Answer
from fractions import gcd
n=int(input())
ans=int(input())
for i in range(1,n):
  t=int(input())
  ans=ans*t/gcd(ans,t)
print(ans)
# Judge status: Accepted
n, m = map(int,input().split())
l = [0]*m
r = [0]*m
for i in range(m):
    l1,r1 = map(int,input().split())
    l[i] = l1
    r[i] = r1
print(max(min(r) - max(l) + 1, 0))
# Judge status: Wrong Answer
s = list(input())
s = sorted(s)
if s[0] != s[1] and s[1] != s[2] and s[2] != s[3]:
     print('Good')
else:
     print('Bad')
# Judge status: Accepted
a = list(map(int, input().split()))
if(a[0] * 500 >= a[1]):
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
# 入力
A, B = map(int, input().split())

# 出力
if 1 <= A and B <= 13:
    if A == B:
        print('Draw')
    elif A != 1 and A > B:
        print('Alice')
    elif B != 1 and B > A:
        print('Bob')
    elif A == 1:
        print('Alice')
    elif B == 1:
        print('Bob')
# Judge status: Accepted
N = int(input())
As = [int(i) for i in input().split()]

ans = 0
while all([a % 2 == 0 for a in As]):
    As = [a // 2 for a in As]
    ans += 1

print(ans)
# Judge status: Accepted
import math
from decimal import Decimal

N, K = map(int, input().split())

win = 0

for i in range(1, N+1):
    if K - i < 1:
        win += 1
        continue

    win += (1/2)**(math.ceil(math.log2(K/i)))
    #print((math.ceil(math.log2(K/i))))

print('{:.10g}'.format(Decimal(win/N)))
# Judge status: Accepted
S = input()
leng = len(S)
ans = 1
for i in range(leng-1, 0, -1):
    if S[:(i // 2)] == S[i // 2:i]:
        ans = max(i, ans)
print(ans)
# Judge status: Accepted
A,B,C,K  = map(int,input().split())
ans = int((A-B)*((-1)**K))
print(ans if abs(ans)< 1e18 else "Unfair")
# Judge status: Accepted
import math
tmp = 0
big_dice = 0
a,b = map(int, input().split())
log2_b = math.log2(b)
if a > b:
  c = b
  big_dice = (a - b) / a
else:
  c = a
for i in range(1, c + 1):
  log2_i = math.log2(i)
  n = math.ceil(log2_b - log2_i)
  tmp = tmp + 0.5**n
print(tmp / a + big_dice)
# Judge status: Wrong Answer
a,b = map(int,input().split())

if (a+b) >24:
    print(a+b - 24)
else:
    print(a+b)
# Judge status: Wrong Answer
A, B, C = input().split(" ")
K = int(input())

A, B, C = int(A), int(B), int(C)

for i in range(K):
  if A > B:
    B = B*2
  elif B > C:
    C = C*2

if B > A and C > B:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
import math
import sys
def makestr(i):
    if (i % 2 == 0):
        return '0'
    else:
        return '1'
s = input()
candicate1 = ''
candicate2 = ''
for i in range(len(s)):
    candicate1 += makestr(i)
    candicate2 += makestr(i + 1)
ans1 = 0
ans2 = 0
for i in range(len(s)):
    if (candicate1[i] != s[i]):
        ans1 += 1
    else:
        ans2 += 1
print(min(ans1,ans2))
# Judge status: Wrong Answer
A,B,X = map(int,input().split())

if A<=X<=A+B:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
from collections import deque

N = int(input())
d = {i:[] for i in range(1, N+1)}
q = deque([(1, "a")])

while q:
    pos, s = q.popleft()
    if pos == N+1:
        break
    d[pos].append(s)
    size = len(set(s))
    for i in range(size+1):
        q.append((pos+1, s+chr(97+i)))

for i in d[N]:
    print(i)
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))


fi = 0
for i in range(n):
    if a[i] == 1:
        fi = i
        break

if (n - 1) % (k - 1) == 0:
    print((n - 1) // (k - 1))
else:
    print((n - 1) // (k - 1) + 1)
# Judge status: Accepted
sx, sy, tx, ty = map(int, input().split())
dx, dy = tx - sx, ty - sy

print('R' * dx + 'U' * dy + 'L' * dx + 'D' * dy, end='')
print('D' + 'R' * (dx + 1) + 'U' * (dy + 1) + 'L', end='')
print('U' + 'L' * (dx + 1) + 'D' * (dy + 1) + 'R')
# Judge status: Accepted
S = int(input())

_set = set()
_set.add(S)

_ = 10**7
cnt = 1
before_num = S

for n in range(_):
  cnt += 1
  _ = before_num
  
  if _%2==0:
    this_num = _/2
  else:
    this_num = 3*_+1
  _set.add(this_num)
  
  if len(_set) < cnt:
    ans = cnt
    break
  
  before_num = this_num
    
print(ans)
# Judge status: Accepted
def resolve():
    x, y = map(int, input().split())
    if y > 4*x:
        print('No')
        return
    if y < 2*x:
        print('No')
        return

    if y % 2 == 0:
        print('Yes')
        return
    print('No')
    return

resolve()
# Judge status: Wrong Answer
x,y,a,b,c = map(int,input().split())
print(sum(sorted(sorted(list(map(int,input().split())))[-x:] + list(map(int,input().split()))[-y:] + list(map(int,input().split())))[-x-y:]))
# Judge status: Wrong Answer
N = int(input())
A = []
for i in range(N):
        A.append(int(input()))
B = A.copy()
B.sort()
B.reverse()
print(B)
print(A)
for i in range(0,N):
        if A[i] == B[0]:
                print(B[1])
        else:
                print(B[0])
# Judge status: Wrong Answer
a, b = map(int, input().split())
s = input()

if a+b+1 >= 0 and a+b+1 <= 9:
    if "-" in s[a] and s.count("-") ==1:
        print("Yes")
    else:
        print("No")
else:
    print("No")
# Judge status: Accepted
S = input()
if S[2] == S[3] :
    if S[4] == S[5] :
        print("Yes")
    else :
        print("No")
else :
    print("No")
# Judge status: Accepted
import fractions
n = int(input())
p = 1
for i in range(n) :
    t = int(input())
    p = p*t//fractions.gcd(p,t)
print(p)
# Judge status: Accepted
n=int(input())
A=list(map(int,input().split()))
ans=10**20
sumA=sum(A)
x=0
for i in range(n-1):
  x+=A[i]
  ans=min(ans,abs(sumA-x*2))

print(ans)
# Judge status: Wrong Answer
n = int(input())
a = []
for _ in range(2):
    a.append(list(map(int, input().split(" "))))

res = 0
for i in range(n):
    res += a[0][i]

    if i + 1 == n:
        res += a[1][i]
        break

    sum_row_1 = sum(a[0][i + 1:n])
    sum_row_2 = sum(a[1][i + 1:n])
    if sum_row_1 <= sum_row_2:
        res += sum(a[1][i:n])
        break

    print(res)
# Judge status: Wrong Answer
N,M = map(int,input().split())
place = [list(map(int,input().split())) for _ in range(N)]
check = [list(map(int,input().split())) for _ in range(M)]
for x,y in place:
    tmp = 10**9
    for i in range(M):
        dis = ((x-check[i][0])**2 + (y-check[i][1])**2)**(1/2)
        if tmp > dis:
            tmp = dis
            ans = i+1
    print(ans)
# Judge status: Accepted
from math import floor
from fractions import gcd

A, B, C, D = map(int,input().split())
lcm = (C*D) // gcd(C,D)

bc = B // C
bd = B // D
bcd = B // lcm

ac = (A-1) // C
ad = (A-1) // D
acd = (A-1) // lcm

ans = B-bc-bd+bcd-(A-1-ac-ad+acd)
print(ans)
# Judge status: Wrong Answer
s = input()

howmany = len(s)
judge = "Yes"

for x in range(howmany):
  if x % 2 == 0:
    if s[x] != "L" and s[x] != "U" and s[x] != "D":
      judge = "No"
      break
  else:
    if s[x] != "R" and s[x] != "U" and s[x] != "D":
      judge = "No"
      break
      
print(judge)
# Judge status: Wrong Answer
n,k=map(int,input().split())
for i in range(k):
    d=int(input())
    a=set(int(i) for i in input().split())
print(n-len(set(a)))
# Judge status: Accepted
#!/usr/bin/env python3

def main():
    N = int(input())
    if N%1000 == 0:
        ans = 0
    else:
        ans = 1000 - N % 1000
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

dat = dict(zip(range(1, n+1), [k]*n))
cnt = 0

for i in range(1, n+1):
    for j in a:
        if i != j:
            dat[i] -= 1

for k in range(1, n+1):
    if dat[k] <= 0:
        print('No')
    else:
        print('yes')
# Judge status: Accepted
total = int(input())
a = (total // 500 * 1000) 
b = (total % 500) // 5 *5
print(a+b)
# Judge status: Accepted
n = int(input())
t, a = map(int, input().split())
listh = list(map(int, input().split()))
temp = 100000
index = 0

for i in range(n):
    c = t - listh[i] * 0.006
    diff = abs(c-a)
    if temp > diff:
        temp = diff
        index = i+1

print(index)
# Judge status: Wrong Answer
import math
n,k=map(int,input().split())
kari=1
ctr=0
while kari<=k:
	kari*=2
	ctr+=1
num=0
acc=0
p=0
for i in range(ctr+1):
	if 10/(2**i)<n:
		num=math.ceil(n-(10/(2**i)))
		pro=num-acc
		acc=num
		p+=(pro/n)*(1/2)**i
print(p)
# Judge status: Wrong Answer
a,b = map(int,input().split())
L = list(map(int,input().split()))
L.sort()
if b<2:
    print("No")
    exit()

if sum(L) >= a: 
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N,M=map(int,input().split())
num=[1]*N
ex=[0]*N
ex[0]=1
P=[]
ans=1
for i in range(M):
    x,y=map(int,input().split())
    num[x-1]-=1
    num[y-1]+=1
    if ex[x-1]==1 and ex[y-1]==0:
        ex[y-1]=1
    if num[x-1]==0:
        ex[x-1]=0
print(sum(ex))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
k = 0
m = a[0]
for i in range(1, n):
    if m > a[i]:
        k += m-a[i]
    else:
        m = a[i]
print(k)
# Judge status: Wrong Answer
A,B=map(int,input().split())
if A==B: print('Draw')
else: print('Alice' if (A > B or (A==1 and B==13)) else 'Bob')
# Judge status: Accepted
n=int(input())
s=input()

w_num=0
b_num=0
w_l=[0]
b_l=[0]

for i in s:
 if i=='.':
  w_num+=1
 else:
  b_num+=1
 w_l.append(w_num)
 b_l.append(b_num)

ans=10**5
for i in range(n+1):
 ans=min(ans,b_l[i]+(w_num-w_l[i]))
print(ans)
# Judge status: Accepted
x, y = map(int, input().split())
if y*x < 0:
    ans = abs(x + y) + 1
elif y*x == 0:
    if x < y:
        ans = y - x
    else:
        ans = x - y + 1
else:
    if x < y:
        ans = y - x
    else:
        ans = x - y + 2

print(ans)
# Judge status: Wrong Answer
import sys
a = sys.argv
if a == "aaa" and a == "bbb":
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
n=int(input())
a=2
b=1
c=3
i=0
while i<n:
  d=a
  e=b
  a=b
  b=c
  c=a+b+c
  i=i+1
print(a)
# Judge status: Wrong Answer
A=[]
A.append(int(input()))
A.append(int(input()))
A.append(int(input()))
A.append(int(input()))
A.append(int(input()))
count=0
rem=10
for t in A:
    if t%10==0:
        count+=t
    else:
        count+=(((t//10)+1)*10)
        if t%10<10:
            rem=t%10
print(count-10+rem)
# Judge status: Wrong Answer
n, m = map(int, input().split())

if n == m == 1:
    print(0)
elif min(n, m) == 1:
    print(max(n,m)-2)
elif min(n,m) == 2:
    print(0)
else:
    print((n-2) * (m-2))
# Judge status: Wrong Answer
n = int(input())
if n <= 9:
  print("ABC00"+str(n))
elif n <= 99:
  print("ABC0"+str(n))
elif n <= 999:
  print("ABC"+str(n))
elif n <= 1008:
  print("ABD00"+str(n-999))
elif n <= 1098:
  print("ABD0"+str(n-999))
else:
  print("ABD"+str(n-999))
# Judge status: Accepted
N,K = map(int,input().split())
A = list(map(int,input().split()))

def s(n,a):
  b = [0]*n
  for i in range(n):
    l = max(0,i-a[i])
    r = min(n-1,i+a[i])
    b[l] += 1
    if r < n - 1:
      b[r+1] -= 1
  for i in range(n-1):
    b[i+1] += b[i]
  return b

for i in range(min(41,K)):
  A = s(N,A)
  
print(*A)
# Judge status: Accepted
n,a,b = map(int, input().split())

def F(n,a,b):
    #ab間にある要素の数が偶数
    if (b-a)%2==0:
        return (b-a)//2
    #左端で止まる
    tmp = []
    #左側からみて
    x = (a-1)+(b-1)+1
    tmp.append(x//2)
    #右側からみて
    x = (n-a)+(n-b)+1
    tmp.append(x//2)
    return min(tmp)

print(F(n,a,b))
# Judge status: Wrong Answer
ABC = input().split()
print('YES' if ABC.count('5') == 2 and ABC.count('7') == 1 else 'N0')
# Judge status: Wrong Answer
N, K = map(int,input().split())
H = list(map(int,input().split()))

H.reverse()

cnt = 0

print(sum(H[K:]))
# Judge status: Accepted
s = input()
days = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

for i in range(len(days)):
  if days[i] == s:
    print(7 - i)
# Judge status: Wrong Answer
dic_s = {x:input() for x in 'abc'}

dic_i = {x:i for x,i in zip('abc',[0,0,0])}
dic_max = {x:len(dic_s[x]) for x in 'abc'}
nt = 'a'
while True:  
  if dic_max[nt] == dic_i[nt]:
    break
  else:
    nt = dic_s[nt][dic_i[nt]]
  dic_i[nt] += 1
print(nt.upper())
# Judge status: Wrong Answer
# https://atcoder.jp/contests/cf16-final/tasks/codefestival_2016_final_b

n = int(input())

i = 1
while i * (i + 1) // 2 <= n:
    i += 1
ans = []
while n > 0 and i > 0:
    if n >= i:
        n -= i
        ans.append(i)
    i -= 1
for a in ans:
    print(a)
# Judge status: Accepted
S = input()
cnt = 1
now = S[0]
tmp = ""
for s in S[1:]:
    tmp += s
    if now != tmp:
        cnt += 1
        now = tmp
        tmp = ""

print(cnt)
# Judge status: Accepted
from collections import Counter
N = int(input())
s_counter = Counter()
for _ in range(N):
    s = input()
    s_counter[s] += 1
M = int(input())
t_counter = Counter()
for _ in range(M):
    t = input()
    t_counter[t] += 1
max_profit = 0
for key in s_counter.keys():
    max_profit = max([max_profit, s_counter[key] - t_counter[key]])
print(max_profit)
# Judge status: Accepted
from itertools import combinations
import numpy as np

n,m,x = map(int, input().split())
q = [np.array(list(map(int, input().split()))) for _ in range(n)]
L=[]
for i in range(1,n+1):
    for j in list(combinations(q,i)):
        S = np.sum(j, axis=0)
        if all([k >= x for k in S[1:]]):
            L.append(S[0])

if len(L) >0:
    print(min(L))
else:
    print(-1)
# Judge status: Accepted
import numpy as np
N, K = (int(i) for i in input().split())  
A = [int(i) - 1 for i in input().split()] 
N = len(A)

def get_keys_from_value(d, val):
    return [k for k, v in d.items() if v == val][0]

now = 0
lis = []
p = {}
for i in range(N):
  now = A[now]
  if now in p:
    break
  
  p[now] = i
  lis.append(now)

if K < i:
  print(lis[K-1] + 1)
else:
  print(lis[(K-i-1) % (i - p[now]) + p[now]] + 1)
# Judge status: Accepted
N, K = map(int, input().split())
D = set(input().split())

n = N
while True:
    d = set(list(str(n)))
    check = D & d
    if len(check) == 0:
        break
    n += 1

print(n)
# Judge status: Accepted
a = []
for i in range(3):
  a.append(list(map(int,input().split())))
for i in range(int(input())):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        a[j][k] = 0
def bingo():
  for i in range(3):
    if sum(a[i]) == 0 or a[0][i] + a[1][i] + a[2][i] == 0:
      return 'Yes'
  if a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[2][0] == 0:
    return 'Yes'
  return 'No'
print(bingo())
# Judge status: Accepted
def c167(x):
    if x[1][:-1] == x[0]: return "Yes"
    else: return "No"

    
if __name__=="__main__":
    input1 = input()
    input2 = input()
    input3 = [input1,input2]
    print(c167(input3))
# Judge status: Wrong Answer
x, y = map(int, input().split())

if 0 <= x and x <= y:
    print(y-x)
elif x < 0 and 0 <= y:
    if abs(x) <= y:
        print(1 + y - abs(x))
    else:
        print(-y-x+1)
elif x < y and y < 0:
    print(y-x)
elif 0 <= y and y <= x:
    print(1-y+x+1)
elif y < 0 and 0 <= x:
    if abs(y) <= x:
        print(1+y+x)
    else:
        print(-y-x+1)
elif y < x and x < 0:
    print(1-y+x+1)
# Judge status: Accepted
def main():
    x = int(input())
    answer = (x // 11) * 2
    if 1 <= x % 11 <= 6:
        answer += 1
    elif 7 <= x % 11:
        answer += 2
    print(answer)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n = list(input())
n.sort(reverse=True)
print(int(n[0]+n[0]+n[0]))
# Judge status: Wrong Answer
n=int(input())
m=0
for x in range(1,n//2+1):
  y=n-x
  x,y=list(str(x)),list(str(y))
  z=sum(list(map(int,x)))+sum(list(map(int,y)))
  m=min(m,z)
print(m)
# Judge status: Accepted
N = int(input())
ls = []
for i in range(N):
    ls.append(int(input()))
sum1 = sum(ls)
ls.sort()
ans = 0
if sum1 % 10 != 0:
    ans = sum1
else:
    for i in range(N):
        if (sum1-ls[i]) % 10 != 0:
            ans = sum1-ls[i]
            break
print(ans)
# Judge status: Accepted
N = int(input())
Z = list(map(int, input().split()))
Z.sort(reverse=True)
A = sum([Z[i] if i % 2 == 0 else 0 for i in range(N)])
B = sum([Z[i] if i % 2 == 1 else 0 for i in range(N)])
print(A-B)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))

d = dict()
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

M = 0
N = 0
for x in d.items():
    if x[1] >= 4 and x[0] > M:
        M = x[0]
        N = x[0]
    elif x[1] >= 2 and x[0] > M:
        N = M
        M = x[0]
    elif x[1] >= 2 and x[0] > N:
        N = x[0]

print(M*N)
# Judge status: Wrong Answer
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for _ in range(N)]
print(CA)
max_=10**16
ans=max_
for bit in range(2**N):
  check=[0]*M
  ans_=0
  for i in range(N):
    if bit>>i&1:
      ans_+=CA[i][0]
      for j in range(M):
        check[j]+=CA[i][j+1]
  if all([k>=X for k in check]):
    ans=min(ans,ans_)
print(ans if ans!=max_ else -1)
# Judge status: Accepted
d,t,s = map(int, input().split())
if d/s <= t:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
x = int(input())
for i in range(10**6):
    if i*(i+1)//2 >= x:
        print(i)
        exit()
# Judge status: Wrong Answer
a,b,k = map(int,input().split())
ans = []
for i in range(1,101):
    if a % i == 0 and b % i == 0:
        ans.append(i)
print(ans[k-1])
# Judge status: Accepted
N=int(input())
for i in range(1,N+1):
    if i*108//100 == N:
        print(i)
        break
else:
    print(":(")
# Judge status: Accepted
a, b, x = map(int, input().split())

if a % x == 0:
  if b % x == 0:
    print(b // x - a // x + 1)
  else:
    print(b // x - a // x + 1)
else:
  if b % x == 0:
    print(b // x - a // x)
  else:
    print(b // x - a // x)