peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
n_l = [1]
n = 1
A = [int(a) for a in input().split()]
for i in range(1,N+1):
    a = A[i-1]
    n = (n - a) * 2
    n_l.append(n)
    if n <= 0:
        Good = False
        break
if n >= A[N]:
    counter = A[N]
    m = A[N]
    Good = True
else:
    Good = False
if Good:
    for i in range(N-1,-1,-1):
        n = n_l[i]
        m = min(m+A[i],n)
        counter += m
    print(counter)
else:
    print(-1)
# Judge status: Accepted
# https://atcoder.jp/contests/abc109/tasks/abc109_c

n, x = map(int, input().split())
nums = [int(i) for i in input().split()]

def gcd(x, y): #GCD
    # greatest_common_divisor
    if x < y:
        x, y = y, x
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)

ans = abs(x - nums[0])
for num in nums:
    d = abs(x - num)
    ans = gcd(d, ans)
print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    ABC = list(map(int, input().split()))
    ABC.sort()
    print('YES' if [5, 5, 7] == ABC else 'NO')


if __name__ == "__main__":
    main()
# Judge status: Accepted
x = int(input())
ans = (x//11)*2 if x%11 == 0 else (x//11)*2 + 1 if x%11 <= 6 else (x//11)*2 + 2
print(ans)
# Judge status: Wrong Answer
s = list(input())
t = list(set(s))

print("Yes") if len(s) == len(t) else print("No")
# Judge status: Wrong Answer
a = int(input())
b = int(input())
L = [1,2,3]
for i in L:
    if i == a or b:
        L.remove(i)
print(L[0])
# Judge status: Wrong Answer
N = int(input())
A_list = list(map(int, input().split()))
 
a_sum = 0
b_sum = 0
for i in range(N//2):
    tup = (A_list[2*i], A_list[2*i + 1]) if A_list[2*i] > A_list[2*i + 1] else (A_list[2*i + 1], A_list[2*i])
    a_sum += tup[0]
    b_sum += tup[1]

print(a_sum - b_sum)
# Judge status: Accepted
n, m = list(map(int, input().split()))

like = [True] * (m+1)

for i in range(n):
    ka = list(map(int, input().split()))
    for j in range(1, m+1):
        if j not in ka[1:]:
            like[j] = False

print(like[1:].count(True))
# Judge status: Wrong Answer
c = [list(map(int,input().split())) for i in range(3)]
import numpy as np
c = np.array(c)
if np.sum(c)%3 != 0:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
# D
# Floor Function

import math

A, B, N = map(int, input().split())

x = min(B-1,N)

print(math.floor(A*x/B)-A*math.floor(x/B))
# Judge status: Accepted
N = int(input())
A = map(int, input().split())
A = list(A)

stage_hight = []
for i, ai in enumerate(A):
	if i != 0 and ai < A[i-1]:
		stage_hight.append(A[i-1] - ai)
		A[i] = A[i-1]
print(sum(stage_hight))
# Judge status: Wrong Answer
n, x = list(map(int, input().split()))
l = list(map(int, input().split()))
d = 0
ans = 1

for num in range(n) :
    d = d + l[num]
    if d <= x:
        ans += 1
    else:
        print(ans)
        break
# Judge status: Wrong Answer
n = int(input())

ans = False
for c in range(1,101):
    for d in range(1,101):
        if (4 * c) + (7 * d) == n:
            ans = True
            break

if ans:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n,d=list(map(int,input().split()))
x=[input().split() for i in range(n)]

result=[]
result_hikaku=[]
for j in range(n-1):
    for k in range(j+1,n):
        cnt=0
        for l in range(d):
            cnt +=(int(x[j][l])-int(x[k][l]))**2
        result.append((cnt)**(1/2))
        result_hikaku.append(round((cnt)**(1/2)))

count=0
for m in range(len(result)):
    if result[m]==result_hikaku[m]:
        count+=1
print(count)
# Judge status: Wrong Answer
#n=int(input())
n,a,b=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dif=b-a-1
if dif%2==0:
    print(min(b-1,n-a))
else:
    print(dif//2+1)
# Judge status: Accepted
n, l = map(int, input().split())
ans = [l+i-1 for i in range(1, n+1)]
mn = min(ans, key=lambda x: abs(x))
print(sum(ans) - mn)
# Judge status: Accepted
n = int(input())

print((n-1)*n//2)
# Judge status: Accepted
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():

    s = list(input().rstrip())
    zero = 0
    one = 0
    for i in s:
        if i == "0":
            zero += 1
        else:
            one += 1
    print(2*min(zero,one))

if __name__=="__main__":
    main()
# Judge status: Accepted
# 台形の面積
# （上底 + 下底）* 高さ / 2

# 入力
a = int(input())
b = int(input())
h = int(input())

# 処理
answer = int((a + b) * h / 2)
print(answer)
# Judge status: Accepted
n,c,k = [int(i) for i in input().split()]
start = []
end   = []
for i in range(n):
    t = int(input())
    start.append(t)
    end.append(t+k)
    
start.sort()
end.sort()

ind = 0
cnt = 0
while(ind<n):
    time = end[ind]
    for i in range(1,c+1):
        next_ind = ind + i
        if next_ind==n or start[next_ind]>time:
            break
    ind = next_ind
    cnt += 1
print(cnt)
# Judge status: Accepted
input()
a=list(map(int,input().split()))
l=[1 if i%2==1 else 4 if i%4==0 else 2 for i in a]
print('YNeos'[(2 in l and l.count(1)>l.count(4)) or (2 not in l and l.count(1)>l.count(4)+1)::2])
# Judge status: Accepted
a,b,c,d=map(int,input().split())
if (c+b-1)//b<=(a+d-1)//d:print("Yes")
else:print("No")
# Judge status: Accepted
N = int(input())
A = []
B = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

count = 0
for i in range(N):
    # print(count+A[N-i -1], B[N-i -1], (count+A[N-i -1]) % B[N-i -1])
    if (count+A[N-i -1]) % B[N-i -1] == 0:
        continue
    else:
        count += B[N-i -1] - ((count+A[N-i -1]) % B[N-i -1])
print(count)
# Judge status: Accepted
N = int(input())
xs = map(int,input().split())
ans = "APPROVED"
for x in xs:
    if x%2 == 1 or x%3 == 0 or x%5 == 0:
        continue;
    ans ="DENIED"
print(ans)
# Judge status: Wrong Answer
N, M = map(int, input().split())
L_list = []
for i in range(M):
    A = list(map(int, input().split()))
    L_list.append(A)
min_range = L_list[0][0]
max_range = L_list[0][1]
for i in range(i, M):
    if L_list[i][0] >= min_range:
        min_range = L_list[i][0]
    if L_list[i][1] <= max_range:
        max_range = L_list[i][1]
print(max_range-min_range+1)
# Judge status: Accepted
from functools import reduce
X,Y = map(int,input().split())
x = (-X+2*Y) /3
y = (2*X-Y) /3
#ans=0のときをどっかで書く。indentめんどいからどうする？
MOD = 10**9+7
if int(x) == x and int(y) == y and x>=0 and y>=0 :
  sum1 = int(x+y)
  bunbo = min([int(x),int(y)])
  n1 = reduce(lambda a,b : (a*b) % MOD  ,range(sum1,sum1-bunbo,-1),1)
  n2 = reduce(lambda a,b : (a*b) % MOD ,range(bunbo,1,-1),1)
  n2inv = pow(n2,MOD-2,MOD) 
  print((n1*n2inv) % MOD)
else:
  print(0)
# Judge status: Wrong Answer
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(N)]

cd = [tuple(map(int, input().split())) for i in range(M)]


for a, b in ab:
    ret = -1
    dis = 10**20
    for i, x in enumerate(cd):
        c, d = x
        if dis > (c-a)**2 + (d-b)**2:
            dis = (c-a)**2 + (d-b)**2
            ret = i
    print(ret+1)
# Judge status: Accepted
a=int(input())
s=str(input())
if a<3200:
	print('red')
else:
	print(s)
# Judge status: Wrong Answer
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    ke="keyence"
    cunt=0
    for i in range(len(s)):
        if s[i]==ke[cunt]:
            cunt+=1
            if cunt==7:
                print("YES")
                break
    else:print("NO")

if __name__=='__main__':
    main()
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))

# 1以外の要素n-1個を、k-1で割る(1項ずつ重複させるため)。余りは1回と数えるので、切り上げる
print(-((-n+1) // (k-1)))
# Judge status: Wrong Answer
n,k=map(int,input().split())
s=input()
s=s.replace(s[k-1],s[k-1].lower())
print(s)
# Judge status: Wrong Answer
N = int(input())
a = list(map(int, input().split()))
#print(a)
ans = [0] * 8
free = 0

for r in a:
    if r > 3199:
        free += 1
    else:
        ans[r // 800] = 1

min_ = max(sum(ans), 1)
#max_ = min(sum(ans) + free, 8)
max_ = sum(ans) + free
print(min_, max_)
# Judge status: Accepted
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans = 0
X = 0
for i in b.keys():
    if X < b[i-1] + b[i] + b[i+1]:
        X = b[i-1] + b[i] + b[i+1]
print(X)
# Judge status: Accepted
N=int(input())
S=list(input())
x=N-((N//26)*26)
empty=[]
for i in S:
    if ord(i)+x>90:
        a=chr(ord(i)+x-26)
        empty.append(a)
    else:
        a=chr(ord(i)+x)
        empty.append(a)
y=''.join(empty)
print(y)
# Judge status: Accepted
a, b, c, k = map(int, input().split())

if (k % 2 == 1):
    print(-1 * (a - b))
else:
    print(a-b)
# Judge status: Wrong Answer
from collections import Counter

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

p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]

pc = Counter(p)
qc = Counter(q)

r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())
# Judge status: Accepted
x = int(input())

s = x // 11
a = x % 11
#print(s, a)
if 1 <= a <=6:
  print(2*s + 1)
elif 7 <= a < 11:
  print(2*s + 2)
elif a == 0:
  print(2*s)
# Judge status: Accepted
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
N = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

total = 0
for i in range(1, 1 + N + 1, 2):
    total += a[i]

print(total)
# Judge status: Wrong Answer
# coding: utf-8

# https://atcoder.jp/contests/abc099/tasks
# 15:00-


def main():
    N = int(input())

    ans = 0

    while True:
        if N < 6:
            ans += N
            return ans

        n = 0
        while 9**(n+1) <= N:
            n += 1
        
        m = 0
        while 6**(m+1) <= N:
            m += 1
        
        N -= max(9**n, 6**m)
        ans += 1


print(main())
# Judge status: Accepted
from math import sqrt
from itertools import permutations

def dict(p, q):
    return sqrt((p[0]-q[0])**2 + (p[1]-q[1])**2)

n = int(input())
coord = []
for _ in range(n):
    coord.append([int(i) for i in input().split()])

sum = cnt = 0
for c in permutations(coord):
    for i in range(n-1):
        sum += dict(c[i], c[i+1])
    cnt += 1

print(sum/cnt)
# Judge status: Accepted
from math import sqrt
from bisect import bisect_left

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


t = M
#約数全列挙
for i in range(1,int(sqrt(M))+2,1):
    if M % i ==0:
        count = 0
        if M % i == 0:
            if N <= i and i <= t:
                t = i
            if N <= M//i and M//i <= t:
                t = M//i

print(M//t)
# Judge status: Accepted
a, b= map(int, input().split())
num = abs(abs(a)-abs(b))
 
if a * b < 0:
    num += 1
elif a * b == 0 and a > b:
    num += 1
elif a * b > 0:
    if a < 0 and abs(a) < abs(b):
        num += 2
    elif a > 0 and abs(a) > abs(b):
        num += 2
print(num)
# Judge status: Accepted
import math
a, b, x = map(int, input().split())
c = (2*x)/(a**2)-b
if c <= 0:
    c = (2*x)/(a*b)
    print(math.degrees(math.atan2(b, c)))
else:
    print(math.degrees(math.atan2(b-c, a)))
# Judge status: Accepted
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ct=r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        k=2*j-i
        if k<=n-1:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ct-=1
print(ct)
# Judge status: Wrong Answer
n = int(input())
p = list(map(int,input().split()))

count = 0
for i in range(1,n-1):
    tmp = sorted([p[i-1],p[i],p[2]])
    if tmp[1] == p[i]:
        count+=1
print(count)
# Judge status: Wrong Answer
def main(n: int, h: list):
    m = h[0]

    for i in h:
        if i - 1 > m:
            print('No')
            return
        elif i + 1 > m:
            m = i

    print('Yes')


if __name__ == "__main__":
    n = int(input())
    m = list(map(int, input().split()))

    main(n, m)
# Judge status: Accepted
a, b = [i for i in input().split()]
A = a*int(b)
B = b*int(a)

if A > B:
  print(B)
  exit()

print(A)
# Judge status: Wrong Answer
n = int(input())
plst = list(map(int,input().split()))
cnt = 0
for i in range(len(plst)-1):
    if plst[i+1] - plst[i] != 1:
        cnt += 1
if cnt <= 2:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
def main():
    A, B, X = map(int, input().split())
    if A + B < X:
        print('NO')
    elif A > X:
        print('NO')
    else:
        print('YES')
main()
# Judge status: Wrong Answer
a,b = map(int,input().split())
if min(a,b)*2+(max(a,b)-min(a,b))*2<=16:
    print('Yey!')
else:
    print(':(')
# Judge status: Accepted
n=int(input())
arr=list(map(int,input().split()))
xors=0
for val in arr:
  xors^=val
ans=[]
for i in range(n):
  ans.append(xors^arr[i])
print(*ans)
# Judge status: Accepted
S = input()
ans = 0
prev, now = "", ""
for i in range(len(S)):
  now += S[i]
  if now != prev:
    ans += 1
    prev, now = now, ""
print(ans)
# Judge status: Wrong Answer
n,a,b = map(int,input().split())
dars = n // (a+b)
amari = n % (a+b)
if b == 0:
    print(n)
    exit()
if amari < b:
    ans = dars*a + amari
else:
    ans = dars*a + a
print(ans)
# Judge status: Accepted
N, A, B = [int(i) for i in input().split()]
ans = (B-A)//2
if (B-A) % 2 == 1:
    ans += min(A-1, N-B)+1
print(ans)
# Judge status: Wrong Answer
n = int(input())
w = list(map(int, input().split()))

m = sum(w)//2
for i in range(1,n):
  if sum(w[:i]) >= m:
    print(abs(sum(w[:i]) - sum(w[i:])))
    exit()
# Judge status: Accepted
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    c = 10 ** 9
    for i in range(1, N):
        a = A[:i]
        b = A[i:]
        c = min(c, abs(sum(a) - sum(b)))

    return c

print(solve())
# Judge status: Accepted
n, r = map(int, input().split())

if n<10:
  print(100*(10-n) + r)
else:
  print(r)
# Judge status: Accepted
s = list(input())

if len(s)%2!=0:
  point = int((len(s)-1)/2)
  count = 0
  for i in range(0,int((len(s)-1)/2+1)):
    if s[point-i]!=s[point+i]:
      count += 1
  print(count)
  exit()
elif len(s)%2==0:
  point1 = int(len(s)/2-1)
  point2 = int(len(s)/2)
  count = 0
  for i in range(0,int(len(s)/2)):
    if s[point1-i]!=s[point2+i]:
      count += 1
  print(count)
# Judge status: Accepted
a,b,k= map(int, input().split())
c = min(k, b-a+1)
x = [a+i for i in range(c)]
y = [b-i for i in range(c)]
z = sorted(list(set(x+y)))
for i in z:
    print(i)
# Judge status: Wrong Answer
n,a,b=map(int,input().split())
p=10**9+7
sub=((n*(n+1))/2)%p
sub=(sub*(n-1)/3)%p
sub1=(a*(a-1)/2)%p
sub2=(b*(b-1)/2)%p
print((sub-sub1-sub2)%p)
# Judge status: Wrong Answer
import math

n = int(input())

d = {}
for i in range(n):
    s = "".join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 0

_ans = 0
for k, v in d.items():
    if v == 0: continue
    _ans += math.factorial(v + 1) // 2

print(_ans)
# Judge status: Accepted
S=str(input())
count=0
for i in range(len(S)//2):
    if S[i]!=S[-(i+1)]:
        count+=1
print(count)
# Judge status: Accepted
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
p = na()
m = p[0]
ans = 0
for i in range(n):
    #print(m, p[i])
    if m >= p[i]:
        ans += 1
    m = min(m, p[i])
print(ans)
# Judge status: Accepted
N, X, Y = list(map(int, input().split()))
 
L = [0] * N
 
for i in range(1, N):
  for j in range(i + 1, N + 1):
    k = j - i
    k = min(k, abs(X - i) + 1 + abs(Y - j))
    L[k] += 1
 
for i in range(1, N):
  print(L[i])
# Judge status: Accepted
n = int(input())
d = list(map(int,input().split()))
m = 998244353
import collections
c = collections.Counter(d)
if c[0] == 1 and d[0] == 0:
    ans = 1
else:
    ans = 0
d = sorted(d)
for i in range(1,n):
    ans *= c[d[i]-1]
    ans %= m
print(ans)
# Judge status: Wrong Answer
n,m = map(int,input().split())
ac, wa=[], {}
for i in range(m):
  p,s = map(str, input().split())
  if s=='AC': ac.append(p)
  elif (s=='WA') and (p not in ac):
    if p not in wa.keys(): wa[p]=1
    else: wa[p]+=1
penalty = sum(wa.values())
clear = len(ac)
print('%d %d'%(clear,penalty))
# Judge status: Wrong Answer
n, k = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
sm = 0
for a, b in ab:
    sm += b
    if sm >= k:
        print(a)
        break
# Judge status: Accepted
from itertools import accumulate
import sys

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

for cnt in range(k):
    tmp = [0] * (n + 2)
    for i in range(n):
        power = arr[i]
        left = max(0, i - power + 1)
        right = min(n + 1, i + power + 2)
        tmp[left] += 1
        tmp[right] -= 1
    arr = list(accumulate(tmp))[1:-1]
    if cnt > 40:
        arr = [n] * n
        print(*arr)
        sys.exit()

print(*arr)
# Judge status: Accepted
import math
n = int(input())
li=list(map(int,input().split()))
li.sort(reverse = True)
al = 0
bo = 0
for i in range(0, n, 2):
    al += li[i]
    if (n % 2 == 1 and i == n - 1):
        break
    bo += li[i + 1]
print(al-bo)
# Judge status: Accepted
N=int(input())
ans=(N+1)*(N/2)
print(int(ans))
# Judge status: Wrong Answer
"""
回転した後に得られる点数 = 上と下を向いている面以外の面に書かれている数
6→5→6→...と選んでいけばよさそう。
"""
X = int(input())
if X < 6:
    print(1)
elif X < 11:
    print(2)
else:
    cnt = X // 11
    X -= cnt * 11
    if X == 0:
        print(cnt * 2)
    elif X < 6:
        print(cnt * 2 + 1)
    else:
        print(cnt * 2 + 2)
# Judge status: Wrong Answer
import math
x, y = map(int, input().split())
print(int(math.log2(y//x) + 1))
# Judge status: Accepted
import math
a, b, h, m = map(int, input().split())

m_a = m * 6
h_a = h * 30
if m > 0:
    h_a = h_a + m * 0.5
print(math.sqrt(a ** 2 + b ** 2 - (2 * a * b * math.cos(math.radians(max(m_a, h_a) - min(m_a, h_a))))))
# Judge status: Accepted
a, b = map(int, input().split())
s = input()
flg1 = s[:a].isdecimal()
flg2 = s[a] == "-"
flg3 = s[-b:].isdecimal()
flg = flg1 and flg2 and flg3
print(["No", "Yes"][flg])
# Judge status: Accepted
a, b = map(int, input().split())
 
if 1 <= a <= 9:
    if 1 <= b <= 9:
        print(a * b)
    else:
        print(-1)
else:
    print(-1)
# Judge status: Wrong Answer
from sys import stdin, stdout
from time import perf_counter

import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7





n,l = map(int, input().split())
s = [input() for _ in range(n)]
s.sort()
result = ''.join(s)
print(s)
# Judge status: Accepted
n = int(input())
arr = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1,n+1):
    bot=i%10
    if bot==0:
        continue
    top=i
    while top>=10:
        top=top//10
    arr[top][bot]+=1

ans=0
for i in range(10):
    for j in range(10):
        ans+=arr[i][j]*arr[j][i]
print(ans)
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
b, c, d = map(int, input().split())
#3桁の数
cin = 100*b+10*c+d
#倍数判定
if cin % 3==0:
  print('YES')
elif cin % 4==0:
  print('YES')
else:
  print('NO')
# Judge status: Wrong Answer
S = input()

if S == 'Sunny':
    print('cloudy')

elif S == 'cloudy':
    print('Rainy')

elif S == 'Rainy':
    print('Sunny')
# Judge status: Wrong Answer
## A - Cookie Exchanges
A, B, C = map(int, input().split())
if A == B == C:
    ans = -1
else:
    ans = 0
    while A%2 == B%2 == C%2 == 0:
        a = (B+C) // 2
        b = (C+A) // 2
        c = (A+B) // 2
        A = a
        B = b
        C = c
        ans += 1
print(ans)
# Judge status: Accepted
S = input()
hitachi = ['hi'*i for i in range(1,6)]
if S in hitachi:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n=int(input())
p=list(map(int,input().split()))
now=0
ans=0
for i in range(n):
    if now==1:
        now=0
        if (i+1)==p[i]:
            ans+=1
        else:
            ans+=1
    elif (i+1)==p[i]:
        now=1
print(ans+now)
# Judge status: Accepted
o = input()
e = input()
ans = ""
for i in range(len(e)):
  ans += o[i] + e[i]
if len(o) != len(e):
  ans += o[-1]
print(ans)
# Judge status: Accepted
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,K=MAP()
L=list(input().split())
L=set(L)
for i in range(N,100000):
  if set(str(i))&L==set():
    print(i)
    exit()
# Judge status: Wrong Answer
K=int(input())
i=0
current_num=0
while (i<K) :
  current_string=str(current_num)
  flag=True
  for k in range(len(current_string)-1) :
    if abs(int(current_string[k])-int(current_string[k+1]))>1 :
      flag=False
      break
  if flag==True :
    i+=1
  current_num+=1
  
print(current_num)
# Judge status: Accepted
import numpy as np
N = int(input())
A = np.array(input().split(), dtype = np.int32)
 
counter = np.bincount(A)
if len(counter) <= 2:
  answer = counter.sum()
else:
  answer = (counter[2:] + counter[1:-1] + counter[:-2]).max()
print(answer)
# Judge status: Accepted
N=input()
if N[-1]=='3':
  print('bon')
elif N[-1]=='0' or N[-1]=='1' or N[-1]=='6' or N[-1]=='8':
  print('pon')
else:
  print('hon')
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
k = int(input())

max_value = max([a, b, c])

res = max_value * k + a + b + c

print(res)
# Judge status: Accepted
def solve(n):
    su = 0
    for i in range(1, n+1):
        m = n//i
        su += m*(2*i + (m-1)*i)//2
    return su

n = int(input())
print(solve(n))
# Judge status: Accepted
h,a=map(int,input().split());print((h+a-1)//a)
# Judge status: Wrong Answer
s = int(input())
a = s//10**9+1; b = 10**9-s%10**9
print(0, 0, 1, a, 10**9, b)
# Judge status: Wrong Answer
n = int(input())

ans,c = 0,0

while 1:
    c+=1
    f=0
    for i in range(10):
        if ((ans%10)+((n%10)*i)%10)%10==1:
            ans += n*i
            #print(ans,i)
            f=1
            break
    if f==0:
        print(-1)
        exit()
    ans = ans//10
    if ans==0:
        break
print(c)
# Judge status: Accepted
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
l=[a,b,c,d,e]
s=[]
t=[]
x=0
for i in range(5):
    s.append(l[i]%10)
for i in range(5):
    if s[i]==0:
        t.append(l[i])
    else:
        t.append((l[i]//10+1)*10)
        
for i in range(1,10):
    if s.count(i)>0:
        x=10-i
        break
print(sum(t)-x)
# Judge status: Wrong Answer
n = int(input())
s = input()

ans = 0
for k in range(n):
    for j in range(k + 1):
        for i in range(j + 1):
            if j - i != k - j:
                if s[k] != s[j] != s[i]:
                    ans = ans + 1
print(ans)
# Judge status: Accepted
h, a = map(int, input().split())
ttk = h // a
if h%a != 0:
    ttk += 1
else:
    ttk = ttk
print(ttk)
# Judge status: Accepted
n = int(input())
ans = (n//500) * (1000)
rem = ((n%500)//5) * 5
ans = ans + rem
print(ans)
# Judge status: Accepted
from collections import deque

N = int(input())
S = list(input())

res = deque()
pcnt = 0
for s in S:
    if s == '(':
        pcnt += 1
    else:
        if pcnt:
            pcnt -= 1
        else:
            res.appendleft('(')
    res.append(s)
if pcnt:
    res.append(')' * pcnt)
print(*res, sep='')
# Judge status: Accepted
import collections as col


n,x,y = map(int,input().split())
dist = []
for i in range(1,n+1):
    for j in range(i+1,n+1):
        a = abs(i - j)
        b = abs(i - x) + 1 + abs(j - y)
        c = abs(i - y) + 1 + abs(j - x)
        dist.append(min(a,b,c))

cnt = col.Counter(dist)
for i in range(1,n): print(cnt[i])
# Judge status: Wrong Answer
a = ['a','e','i','u','e']
if input() in a:
  print('vowel')
else:
  print('consonant')