peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
def ll():
    return list(map(int,input().split()))
def l():
    return int(input())
n,l = ll()
x = [int(i) for i in range(l, n + l)]
if 0 in x:
    print(sum(x))
elif abs(x[0])<abs(x[-1]):
    print(sum(x)-x[0])
else:print(sum(x)-x[-1])
# Judge status: Accepted
N = int(input())
A = list(map(lambda x:int(x), input().split(" ")))
R = [0 for i in range(N)]

for a in A:
    R[a - 1] += 1

for r in R:
    print(r)
# Judge status: Accepted
n = int(input())
if n == 0:
  print(0)
  exit(0)
s = ""
while n != 0:
  m = abs(n % -2)
  s = str(m) + s
  n = (n - m) // -2
print(s)
# Judge status: Accepted
N = int(input())
S = [int(input()) for _ in range(N)]
#print(S)

s = ()
nex = 1

for i in range(N):
    #print(S[nex-1])
    nex = S[nex-1]
    if nex == 2:
        print(i+1)
        break
    if i == N-1:
        print(-1)
# Judge status: Accepted
n = int(input())
nums = [int(i) for i in input().split()]
box = [0] * n
for i in range(1, n + 1)[::-1]:
    c = i * 2
    ball = nums[i - 1]
    while c <= n:
        ball = ball ^ box[c - 1]
        c += i
    box[i - 1] = ball

ans = box.count(1)
print(ans)
ball = []
for i in range(n):
    if box[i] == 1:
        ball.append(i + 1)
print(*ball)
# Judge status: Accepted
s = input()

print('x' * len(s))
# Judge status: Wrong Answer
import math
n = int(input())
a = math.ceil(n/2)/n
# Judge status: Wrong Answer
D = input()
if D==25:
  print("Christmas") 
if D==24:
  print("Christmas Eve")
if D==23:
  print("Christmas Eve Eve") 
if D==22:
  print("Christmas Eve Eve Eve")
# Judge status: Accepted
N = int(input())
times = [int(input()) for _ in range(5)]
bottle_neck = min(times)
print((N + bottle_neck - 1) // bottle_neck + 4)
# Judge status: Accepted
import sys


def input():
    return sys.stdin.readline()[:-1]


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


def Base_10_to_n(X, n):
	if (int(X/n)):
		return Base_10_to_n(int(X/n), n)+str(X%n)
	return str(X%n)

print(len(Base_10_to_n(N, K)))
# Judge status: Wrong Answer
n,k = map(int,input().split())
print(n % k)
# Judge status: Wrong Answer
import math

r=int(input())
k=math.pi

t=math.floor(2*k*r)

print(t)
# Judge status: Accepted
n,a,b = list(map(int,input().split()))

cnt = int(n/(a+b))


print(a*cnt + min(a,(n-(cnt*(a+b)))))
# Judge status: Accepted
N = int(input())
S = input()

d = [0]
o = c = 0
for i in range(N):
    if S[i] == '(':
        o += 1
    else:
        c += 1
    d.append(o - c)
x = min(d)
print('(' * -x + S + ')' * (d[-1] - x))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
s = 0

for i in range(n):
    s += b[a[i] - 1]
    if i < n - 1:
        if a[i] + 1 == a[i+1]:
            s += c[a[i]-1]
print(s)
# Judge status: Wrong Answer
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
for _ in range(m):
    A.sort()
    b,c = map(int,input().split())
    index = bisect.bisect_right(A,c)
    if index == 0:
        pass
    elif b >= index:
        for i in range(0,index):
            A[i] = c
    else:
        A = [ c for _ in range(b)]
print(sum(A))
# Judge status: Wrong Answer
from collections import deque

x,y,a,b,c=map(int, input().split())
pi=list(map(int,input().split()))
qi=list(map(int,input().split()))
ri=list(map(int,input().split()))
pi.sort(reverse=True)
qi.sort(reverse=True)
ri.sort(reverse=True)
ri=deque(ri)

apple=pi[:a]+qi[:b]
apple.sort(reverse=True)
apple=deque(apple)
while min(apple) <= ri[0]:
    c=ri.popleft()
    apple[-1]=c
    if len(ri)==0:
        break
print(sum(apple))
# Judge status: Accepted
a, b, c = [int(i) for i in input().split()]

cnt = 0
history = set()
while True:
  if (a, b, c) in history:
    print(-1)
    exit(0)
  if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
    print(cnt)
    exit(0)
  a, b, c = sorted([a, b, c])
  history.add((a, b, c))
  na = b // 2 + c // 2
  nb = a // 2 + c // 2
  nc = a // 2 + b // 2
  a = na
  b = nb 
  c = nc
  cnt += 1
# Judge status: Accepted
N = int(input())
if not N % 11:
  print(N // 11 * 2)
elif N % 11 <= 6:
  print(N // 11 * 2 + 1)
else:
  print(N // 11 * 2 + 2)
# Judge status: Accepted
s, t = input().split()
a, b = map(int, input().split())
u = input()
balls = {s: a, t: b}
if u in balls.keys():
  balls[u] -= 1
print('{} {}'.format(balls[s], balls[t]))
# Judge status: Accepted
S = input()
ans = []
for s in S:
    if s == "0":
        ans.append(0)
    elif s == "1":
        ans.append(1)
    else:
        if ans:
            ans.pop(-1)
print(*ans, sep='')
# Judge status: Accepted
# AGC017A

def f(n, p, a):
    odd = sum(i % 2 for i in a)
    if odd == 0:
        if p == 0:
            return 2**n
        elif p == 1:
            return 0
    else:
        return 2**(n-1)
        
n, p = map(int, input().split())
a = list(map(int, input().split()))
print(f(n, p, a))
# Judge status: Accepted
N = int(input())
scores = list(int(input()) for _ in range(N))
ans = sum(scores)
if ans % 10 != 0:
    print(ans)
    exit()

scores.sort()
for score in scores:
    if score % 10 != 0:
        ans -= score
        print(ans)
        exit()
print('0')
# Judge status: Accepted
from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)
n = int(input())
for i in range(n):
    d1[input()] += 1
m = int(input())
for i in range(m):
    d2[input()] += 1

ans = 0
for k, v in d1.items():
    ans = max(ans, v - d2[k])
print(ans)
# Judge status: Accepted
a = list(input())
b = list(input())
c = list(input())

turn = a.pop(0)
while True:
  if turn == 'a':
    if a :
      turn = a.pop(0)
    else:
      print("A")
      break
  elif turn == 'b':
    if b :
      turn = b.pop(0)
    else:
      print("B")
      break
  elif turn == 'c':
    if c :
      turn = c.pop(0)
    else:
      print("C")
      break
# Judge status: Wrong Answer
W, a, b = map(int, input().split())

A = a + W

if b - A <= 0:
    print(0)
else:
    print(b-A)
# Judge status: Wrong Answer
a,b=map(int,input().split())
print(a+a-b)
# Judge status: Accepted
n, m, *XY = map(int, open(0).read().split())
A = [1] * n
B = [0] * n
B[0] = 1
for x, y in zip(XY[::2], XY[1::2]):
  x, y = x-1, y-1
  A[x] -= 1
  A[y] += 1
  if B[x]:
    B[y] = 1
  if A[x] == 0:
    B[x] = 0
print(sum(B))
# Judge status: Wrong Answer
import math

a,b=map(int,input().split())
if a>=b:
    print(b)
else:
    print(math.ceil(b/a))
# Judge status: Accepted
a,b,k=map(int,input().split())
ans=0
for i in range(min(a,b)):
    if a%(min(a,b)-i)==0 and b%(min(a,b)-i)==0:
        ans+=1
        if ans==k:
            print(min(a,b)-i)
            break
# Judge status: Accepted
N = int(input())
if N%111==0:
    print(N)
else:
    print((N//111+1)*111)
# Judge status: Wrong Answer
from collections import deque
k=int(input())
q=deque(list(range(1, 10)))
ans,x,y,tmp=0,0,0,0
for i in range(k):
  ans=q.popleft()
  x,y=ans*10,ans%10
  tmp=10*x+y
  if y != 0:
    q.append(tmp-1)
  q.append(tmp)
  if y != 9:
    q.append(tmp+1)
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline

S=tuple(input().strip())
N=len(S)+1
sets = []
count = 0

for c in S:
    d = 1 if c == '<' else -1
    if count * d < 0:
        sets.append(count)
        count = d
    else:
        count += d
sets.append(count)

sum = 0
for i in range(len(sets)):
    k=sets[i]
    if k > 0:
        sum += (k*(k+1))//2
    else:
        sum += (k*(k-1))//2
        if i > 0:
            sum -= min(sets[i-1], -k)

print(sum)
# Judge status: Accepted
import re
n, a, b, c, d = map(int, input().split())
road = input()
if c < d:
    if re.search('##', road[a:d]) is None:
        print('Yes')
    else:
        print('No')

elif c > d:
    if re.search('##', road[a:]) is None and re.search('\.\.\.', road[b-2:d+1]) is not None:
        print('Yes')
    else:
        print('No')
# Judge status: Wrong Answer
n = int(input())
i = int(n / 111)
if n % 111 != 0:
    i += 1
    print(i)
print(i * 111)
# Judge status: Wrong Answer
abc = list(map(int, input().split()))
k = int(input())

abc.sort()
abc[2] = abc[2] * 2 * k

print(sum(abc))
# Judge status: Accepted
X, K, D = map(int, input().split())
X = abs(X)
r = X % D
t = X // D
if t >= K:
    ans = abs(X - K * D)
elif (K - t) % 2 == 0:
    ans = r
else:
    ans = D - r
print(ans)
# Judge status: Accepted
a = input().rstrip()
if a.isupper():
  print("A")
else:
  print("a")
# Judge status: Accepted
K,X = map(int,input().split())
ans = [str(i) for i in range(X-K+1,X+K)]
print(" ".join(ans))
# Judge status: Accepted
A, B, C = map(int, input().split())

for i in range(B):
    if i*A%B==C:
        print('YES')
        exit()

print('NO')
# Judge status: Accepted
n = int(input())
a = [int(_) for _ in input().split()]

ans = 1000000000
for i in range(-100, 101):
    val = 0
    for j in a:
        val += (i-j)**2
    ans = min(ans, val)
print(ans)
# Judge status: Wrong Answer
str = input()
str[3] == '8'
print(str)
# Judge status: Accepted
n=int(input())
s=[0]*n
for i in range(n):
  s[i]=int(input())
s.sort()
ans=sum(s)
temp=0
if ans%10==0:
  for i in range(n):
    if s[i]%10==0:
      temp=temp+1
    else:
      print(ans-s[i])
      break
  if temp==n:
    print(0)
else:
  print(ans)
# Judge status: Accepted
from collections import Counter
N, M = map(int, input().split())
A = list(map(int, input().split()))

A = Counter(A)

for _ in range(M):
    b, c = map(int, input().split())
    A[c] += b

A = sorted(A.items(), key=lambda x: x[0], reverse=True)

ans = 0
for key, value in A:
    if N - value >= 0:
        ans += key * value
        N -= value
    else:
        ans += N * key
        break

print(ans)
# Judge status: Accepted
import math

n = int(input())

a = math.factorial(n)
b = 10**9 + 7

print(a%b)
# Judge status: Accepted
N = int(input())

dp = [[0]*3 for _ in range(N)]
dp[0] = list(map(int, input().split()))

for i in range(1, N):
  h = list(map(int, input().split()))
  for j in range(3):
    dp[i][j] = max([dp[i-1][k]+h[j] for k in range(3) if k != j])

print(max([dp[N-1][j] for j in range(3)]))
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
b=set(a)
ans=0
for i in b:
  if a.count(i)%2==1:
    ans+=1
print(ans)
# Judge status: Accepted
import math
n = int(input())

a = []
b = []

for i in range(n):
  c, d= map(int, input().split())
  a.append(c)
  b.append(d)

a.reverse()
b.reverse()

tot = 0
for i in range(n):
  if (a[i]+tot)%b[i] == 0:
    continue
  x = b[i] - (a[i]+tot)%b[i]
  tot += x
print (tot)
# Judge status: Wrong Answer
s = input()
S = list(s)
if S[2] == S[3] and S[4] == S[5]:
    print('Yes')
else:
    print('No)')
# Judge status: Wrong Answer
import math
s = int(input().replace(' ',''))
if math.sqrt(s)**2 ==s:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
T=input()
u=T.translate(str.maketrans({'?': 'D'}))
print(u)
# Judge status: Wrong Answer
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort(reverse=True, key=lambda x: (x[1], x[0]))

    ans = 0
    d = 0

    for a, b in ab:
        if a + d <= m:
            ans += b
            d += 1
        if d == m:
            break
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
# Judge status: Wrong Answer
b,c=[int(x) for x in input().split()]
if c>b:
    print("unsafe")
else:
    print("safe")
# Judge status: Accepted
import math 
n,d=map(int,input().split())
print(math.ceil(n/(d*2+1)))
# Judge status: Wrong Answer
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
a =[]
def cal(n):
  ans = T-n*6
  return ans
  
for i in H:
  a.append(int((A-cal(i))))
  
print(a.index(min(a))+1)
# Judge status: Wrong Answer
import sys
import numpy as np

# input = sys.stdin.readline

n = int(input())

print(round(n))
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
tot = sum(A)
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[i-1]
cmin = abs(tot-2*B[1])
for i in range(2,N):
    cmin = min(cmin,abs(tot-2*B[i]))
print(cmin)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  a[i] -= i+1

b = round(sum(a)/n, 0)
ans = 0
for i in range(n):
  ans += abs(a[i]-b)

print(int(ans))
# Judge status: Accepted
import sys
import math
input=sys.stdin.readline

n,h=map(int,input().split())

once=[]
infinity=[]

for i in range(n):
  a,b=map(int,input().split())
  once.append(b)
  infinity.append(a)
  
once.sort(reverse=True)

pin=max(infinity)

once2=[]
for i in range(n):
  if once[i]>pin:
    once2.append(once[i])
  
  else:
      break

ans=0
for i in once2:
    ans+=1
    h-=i
    if h<=0:
        print(ans)
        exit()

ans+=math.ceil(h/pin)


print(ans)
# Judge status: Wrong Answer
D = int(input())
if D ==  25:
  a = 'Christmas'
elif D == 24:
  a = 'Christmas Eve'
elif D == 23:
  a = 'Christmas Eve Eve'
elif D == 22:
  a = 'christmas Eve Eve Eve'
print(a)
# Judge status: Accepted
import numpy as np

f = open(0)
N = int(f.readline())
xy = np.fromstring(f.read(), dtype=np.int64, sep=' ').reshape((-1, 2)).T.copy()
x = xy[0]
y = xy[1]
c1 = x + y
c2 = x - y
ans = max(c1.max() - c1.min(), c2.max() - c2.min())
print(ans)
# Judge status: Accepted
N,X = map(int,input().split())
A = list(map(int,input().split()))
A = [0] + A + [0]
cnt = 0
for i in range(1,N+1):
    S = A[i]+A[i+1]
    if S>X:
        d = S-X
        cnt += d
        A[i+1] = max(0,A[i+1]-d)
print(cnt)
# Judge status: Accepted
A, B, C, K = map(int, input().split())
print(B - A) if K % 2 else print(A - B)
# Judge status: Wrong Answer
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    if a[0] > a[1]:
        print("Alice")
    elif a[0] == a[1]:
        print("Draw")
    else:
        print("Bob")
# Judge status: Accepted
n,a,b = [int(x) for x in input().split()]

INF = (10**9 + 7)

def c(n,r,p):
    r = min(r,n-r)
    numer = 1
    denom = 1
    for i in range(1,r+1):
        numer = numer * (n+1-i) % p
        denom = denom * i % p
    return numer * pow(denom,p-2,p) % p

ans = pow(2,n,INF) - 1 - c(n,a,INF) - c(n,b,INF)

while ans < 0:
    ans += INF
print(ans)
# Judge status: Accepted
S = input()
ans = 0
for i in range(len(S)):
  for j in range(i, len(S)):
    if all('ACTG'.count(c) == 1 for c in S[i:j+1]):
      ans = max(ans, j+1-i)
print(ans)
# Judge status: Accepted
n = int(input())
l = list(map(int, input().split()))
l.sort()

import bisect

count = 0
for i in range(n-1):
    for j in range(i+1, n):
            ab = l[i] + l[j]
            right = bisect.bisect(l, ab-1)
            left = j + 1
            count += (right - left)

print(count)
# Judge status: Accepted
import sys
import bisect
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
CB = [None] * M
for i in range(M):
    b, c = map(int, sys.stdin.readline().split())
    CB[i] = (c, b)
CB.sort(reverse=True)

i = 0
ans = 0
for c, b in CB:
    x = bisect.bisect_left(A, c, i)
    count = min(x - i, b)
    ans += c * count
    i += count
for j in range(i, N):
    ans += A[j]
print(ans)
# Judge status: Accepted
H, A = map(int, input().split())
print((H-1)//A+1)
# Judge status: Accepted
S = input()
T = input()
f = "UNRESTORABLE"

# 後ろから見ていって、部分文字列を当てはめる
S_r = S[::-1]
T_r = T[::-1]
for i in range(len(T),len(S)+1):
    S_ = S_r[i-len(T):i]
    flg = True
    for t,s in zip(T_r, S_):
        if s != "?" and s != t:
            flg = False
    if flg:
        ans = S_r[:i-len(T)] + T_r + S_r[i:]
        print(ans[::-1].replace("?","a"))
        exit()
print(f)
# Judge status: Accepted
N = int(input())
W = list(map(int, input().split()))

S1 = W[0]
S2 = sum(W[1:])
abs_min = abs(S1-S2)

for i in range(1, N-1):
    S1 += W[i]
    S2 -= W[i]
    abs_min = min(abs_min, abs(S1-S2))

print(abs_min)
# Judge status: Accepted
X,Y=map(int,input().split())

c=0

while(X<=Y):
    X=X*2
    c+=1
print(c)
# Judge status: Accepted
s = input()
if s[-1] == 's':
    print(s+'es')
else:
    print(s+'s')
# Judge status: Wrong Answer
x = int(input())
print('Yes' if x == 7 or x == 5 or x == 3 else 'No')
# Judge status: Accepted
l = list(map(int,input().split()))
l = sorted(l)
if l[2] == l[0] + l[1]: print('Yes')
else: print('No')
# Judge status: Wrong Answer
x = int(input())

if 6 < x < 11:
    print(2)
    exit()
elif 1 <= x <= 6:
    print(1)
    exit()

if x % 11 == 0:
    print((x // 11) * 2)
else:
    print((x // 11) * 2 + 1)
# Judge status: Accepted
n=int(input())
a = [int(input()) for _ in range(n)]
ans=0
a.sort()
for i in range(n):
    if sum(a)%10 == 0:
        if a[i]%10 == 0:
            pass
        else:
            a[i]=0
    else:
        print(sum(a))
        exit(0)
print(0)
# Judge status: Wrong Answer
n,k=map(int,input().split())
cnt=0
j=17
for i in range(1,n+1):
    if i>=k:
        cnt+=1
    else:
        while i*(2**j)>k:
            j-=1
        cnt+=1/2**(j+1)
print(format(cnt/n,'.12f'))
# Judge status: Wrong Answer
h,w  = map(int,input().split())
if h == 1 or w == 1:
    ans = 2
    print(ans)
else:
    ans = 2*(h-2)+2*(w-2)+4
    ans = (h*w) -ans
    print(ans)
# Judge status: Accepted
N = int(input())
arr = list(map(int, input().split()))
two_count = 0
four_count = 0
for i in arr:
    if i % 4 == 0:
        four_count += 1
        continue
    if i % 2 == 0:
        two_count += 1
        continue
ans = N - ((two_count//2)*2 + (four_count*2) + 1 if four_count > 0 else 0)
if ans <= 0 or two_count == N:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n = input()
print(sum([int(n[i]) for i in range(len(n))]))
# Judge status: Wrong Answer
str = input().split(" ")
num = input().split(" ")

goal = int(str[1])
arr = {}

for i in num:
	i = int(i)

	if arr.get(i, False):
		arr[i] += 1
	else:
		arr[i] = 1

arr = dict(sorted(arr.items(), key=lambda d: d[1], reverse=True))

count = 0
if len(arr.items()) >= goal:
	for index, (i, key) in enumerate(arr.items()):
		if (index + 1) > goal:
			count += key
else:
	count = goal - len(arr.items())

print(count)
# Judge status: Accepted
# 「ABC-154-C」の類題
S = input()
 
n1 = len(S)
n2 = len(set(S))
 
if n1 == n2: print('yes')
else: print('no')
# Judge status: Accepted
s = list(str(input()))
k = int(input())
for i in range(len(s)):
    if s[i] != "a":
        num = 26-(ord(s[i])-ord("a"))
        if k >= num:
            k -= num
            s[i] = "a"
s[-1] = chr(ord("a")+((ord(s[i])-ord("a")+k)%26))
print("".join(s))
# Judge status: Wrong Answer
N=int(input())
count=0
max=0
max_number=1

if N==1:
  print(1)

for i in range(1,N+1):
  while i>=1:
    if i%2==0:
      i=i//2
      count+=1
    else:
      break
  if count>=max:
    max=count
    max_number=1
print(max_number)
# Judge status: Accepted
n = int(input())
ans = 0
for i in range(1, n+1):
    y = n // i
    ans +=( y * (y+1)* i)//2

print(ans)
# Judge status: Accepted
s=input()
q=int(input())
cnt=0 #反転の回数の偶奇を記憶
right=""
left=""
for i in range(q):
	query=list(input().split())
	if query[0]=="1":
		cnt+=1
	else:
		if (cnt+int(query[1]))%2==0:
			right+=query[2]
		else:
			left+=query[2]
if cnt%2==0:
	print(left[::-1]+s+right)
else:
	print(right[::-1]+s[::-1]+left)
# Judge status: Accepted
n=int(input())
A=[int(_) for _ in input().split()]
B=[int(_) for _ in input().split()]
C=[int(_) for _ in input().split()]
ans=sum(B)
for i in range(n-1):
    if A[i+1]==A[i]+1:
        ans+=C[A[i]-1]

print(ans)
# Judge status: Accepted
n, m = [int(i) for i in input().split()]

if 2*n >= m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 4)
# Judge status: Accepted
n = int(input())
a = [int(x) for x in input().split()]

status = 0
ans = 1
for i in range(1, n):
    if status == 0:
        if a[i-1] < a[i]:
            status = 1
        elif a[i-1] > a[i]:
            status = 2
    elif status == 1:
        if a[i-1] > a[i]:
            ans += 1
            status = 0
    elif status == 2:
        if a[i-1] < a[i]:
            ans += 1
            status = 0
print(ans)
# Judge status: Accepted
n,k = map(int,input().split())
A = list(map(int,input().split()))
import math
ans = math.ceil(((n-1)/(k-1)))
print(ans)
# Judge status: Wrong Answer
a, b, c, x, y = map(int, input().split())

m = 100000000
for i in range(max(x, y)*2):
    total = a*(max(0, x-i//2)) + b*(max(0, y-i//2)) + c*i
    if total < m:
        m = total

print(m)
# Judge status: Accepted
n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _  in range(m)]

for i in range(n-m+1):
  if B[i] in A[i]:
    for j in range(m-1):
      if B[i+j] not in B[i+j]:
        print("No")
        exit()
    print("Yes")
    exit()
  else:
    print("No")
    exit()
# Judge status: Accepted
def solve(n, k, xs):

    tmp = n
    num = len(xs)
    
    while True:
        if num == len([i for i in xs if i not in str(tmp)]):
            break
        else:
            tmp += 1
    
    return tmp

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    xs = [i for i in input().split()]
    print(solve(n, k, xs))
# Judge status: Accepted
n,m,q = map(int,input().split())
abcd = [list(map(int,input().split())) for _ in range(q)]
s = [[1]]
for i in range(1,n):
    s_ = []
    for j in s:
        for k in range(j[-1],m+1):
            s_.append(j+[k])
    s = s_
    
ans = 0
for i in s:
    ans_ = 0
    for j in abcd:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            ans_ += j[3]
    ans = max(ans, ans_)

print(ans)
# Judge status: Accepted
n= int(input())
ans=0
if(n%2==0):
    n=n//10
    while(n>0):
        ans = ans+n
        n= n//5
print(ans)
# Judge status: Accepted
n,k = map(int,input().split())
r,s,p = [int(i) for i in input().split()]
T = input()

point = {"r":p,"p":s,"s":r}

ans = 0
for i in range(min(n,k)):
    before = T[i]
    counter = 0
    for s in T[i::k]:
        if before == s:
            counter += 1
        else:
            ans += (counter+1)//2 * point[before]
            before = s
            counter = 1
    ans += (counter+1)//2 * point[before]
print(ans)
# Judge status: Wrong Answer
x=input("|AB| |BC| |CA|")
ab,bc,ca=x.split()
ab=int(ab)
bc=int(bc)
ca=int(ca)
x=ab*bc/2
print(x)
# Judge status: Wrong Answer
n = int(input())
a = input().split(" ")

flag = False
for i in range(n-1):
    for j in range(n-1):
        if a[i] == a[j]:
            Flag = True
            break
    if flag:
        break

print('NO' if flag else 'YES')
# Judge status: Accepted
D = int(input())
c = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
#T = [int(input()) for i in range(D)]
SUM = 0
last = [0] * 28
for d in range(1, D + 1):
    i = S[d - 1].index(max(S[d - 1]))
    print(i + 1)
# Judge status: Accepted
import sys
input = sys.stdin.readline

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

if(a+b+c >=22):
	print('bust')
else: print('win')
# 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: Accepted
# -*- coding: utf-8 -*-
A, B, C = map(int, input().split())
K = int(input())

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

if C > B and B > A:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
n=int(input())
d=sorted(list(map(int,input().split())))
print(d[n//2]-d[n//2-1])
# Judge status: Accepted
a, b, x = map(int, input().split())

print(b//x - (a-1)//x)
# Judge status: Wrong Answer
hap=0
yen=int(input())
hap=1000*(yen//500)+(yen%5)*5
# Judge status: Accepted
N = int(input())
wa = 0
for i in range(1,N+1):
	if i % 3 != 0 and i % 5 != 0:
		wa += i
print(wa)
# Judge status: Accepted
from math import gcd
from functools import reduce

MOD = 10 ** 9 + 7

def calc_lcm(x, y):
    return x * y // gcd(x, y)

def calc_lcm_list(numbers):
    return reduce(calc_lcm, numbers, 1)
  
  
N, *A = map(int, open(0).read().split())
lcm = calc_lcm_list(A)
print(sum(lcm * pow(v, MOD - 2, MOD) for v in A) % MOD)
# Judge status: Wrong Answer
N = int(input())
cnt = 0

for i in range(N):
    if (N - i*7) % 4 == 0:
        cnt += 1

print("Yes" if cnt > 0 else "No")
# Judge status: Wrong Answer
#
from collections import Counter

a,b,c = map(int,input().split())
if(abs(b-a)==abs(c-b)):
    print("YES")
else:
    print("NO")