Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(N):
    ans = math.gcd(ans,x[i+1]-x[i])
print(ans)


Fixed submission:
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(N):
    ans = gcd(ans,x[i+1]-x[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(N-1):
    ans = gcd(ans,x[i+1]-x[i])
print(ans)


Fixed submission:
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(N):
    ans = gcd(ans,x[i+1]-x[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(N-1):
    ans = gcd(ans,x[i+1]-x[i])
print(ans)


Fixed submission:
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(N):
    ans = gcd(ans,x[i+1]-x[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
cnt = 0
i = 10
dp = [0,1,2,3,4,5,1,2,3,1]
while i<=N:
    idx_n,idx_s = 0,0
    while i-(9**idx_n)>=0:
        idx_n += 1
    idx_n -= 1
    while i-(6**idx_s)>=0:
        idx_s += 1
    idx_s -= 1
    dp.append(min(1+dp[i-(9**idx_n)],1+dp[i-(6**idx_s)]))
    i += 1
print(dp[N])


Fixed submission:
N = int(input())
cnt = 0
i = 10
dp = [0,1,2,3,4,5,1,2,3,1]
while i<=N:
    idx_n,idx_s = 0,0
    while i-(9**idx_n)>=0:
        idx_n += 1
    idx_n -= 1
    while i-(6**idx_s)>=0:
        idx_s += 1
    idx_s -= 1
    dp.append(min(1+dp[i-(9**idx_n)],1+dp[i-(6**idx_s)]))
    i += 1
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int,input().split())
D = [[int(i) for i in input().split()] for _ in range(C)]
c = [[int(i) for i in input().split()] for _ in range(N)]
modl = [[] for i in range(3)]
for i in range(N):
    for j in range(N):
        modl[((i+1)+(j+1))%3].append(c[i][j])
ans = float('inf')
for i in range(C):
    total = 0
    tmp1 = 0
    for e in modl[0]:
        tmp1 += D[e-1][i]
    total += tmp1
    for j in range(C):
        if i!=j:
            tmp2 = 0
            for e in modl[1]:
                tmp2 += D[e-1][j]
            total += tmp2
            for k in range(C):
                tmp3 = 0
                if i!=k and j!=k:
                    for e in modl[2]:
                        tmp3 += D[e-1][k]
                    total += tmp3
                    ans = min(ans,total)
                    total -= tmp3
            total -= tmp2
print(ans)


Fixed submission:
N,C = map(int,input().split())
D = [[int(i) for i in input().split()] for _ in range(C)]
c = [[int(i) for i in input().split()] for _ in range(N)]
modl = [[0 for i in range(C)] for i in range(3)]
for i in range(N):
    for j in range(N):
        modl[((i+1)+(j+1))%3][c[i][j]-1] += 1
ans = float('inf')
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i==j or i==k or j==k:
                continue
            total = 0
            for l in range(C):
                total += D[l][i]*modl[0][l]+D[l][j]*modl[1][l]+D[l][k]*modl[2][l]
            ans = min(ans,total)
print(ans)
Buggy python submission (verdict: Runtime Error):
INF = 10**18
A,B,C,K = map(int,input().split())
print((B-A if K%2==1 else A-B)


Fixed submission:
INF = 10**18
A,B,C,K = map(int,input().split())
print((B-A if K%2==1 else A-B))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
d = []
ele = []
for i in range(len(s)):
    if not s[i] in d:
        d.append(s[i])
    ele = []
    ele.append(s[i])
    for j in range(i+1,len(s)):
        ele.append(s[j])
        substr = ''.join(ele)
        if not substr in d and len(substr)<=K:
            d.append(substr)
d.sort()
print(d[K-1])


Fixed submission:
s = input()
K = int(input())
d = []
ele = []
for i in range(len(s)):
    for j in range(0,K):
        substr = s[i:i+j+1]
        if not substr in d and len(substr)<=K:
            d.append(substr)
d.sort()
print(d[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
d = []
ele = []
for i in range(len(s)):
    if not s[i] in d:
        d.append(s[i])
    ele = []
    ele.append(s[i])
    for j in range(i+1,len(s)):
        ele.append(s[j])
        if not ''.join(ele) in d:
            d.append(''.join(ele))
d.sort()
print(d[K-1])


Fixed submission:
s = input()
K = int(input())
d = []
ele = []
for i in range(len(s)):
    for j in range(0,K):
        substr = s[i:i+j+1]
        if not substr in d and len(substr)<=K:
            d.append(substr)
d.sort()
print(d[K-1])
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [input() for i in range(H)]
dx=[0,-1,1,0]
dy=[1,0,0,-1]
flag = True
for i in range(W):
    for j in range(H):
        if s[i][j]=='#':
            cnt = 0
            for k in range(4):
                if 0<=j+dx[k] and j+dx[k]<H and 0<=i+dy[k] and i+dy[k]<W:
                    if s[i+dy[k]][j+dx[k]]=='#':
                        cnt += 1
            if cnt==0:
                flag=False
print('Yes' if flag else 'No')



Fixed submission:
H,W = map(int,input().split())
s = [input() for i in range(H)]
dx=[0,-1,1,0]
dy=[1,0,0,-1]
flag = True
for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            cnt = 0
            for k in range(4):
                if 0<=j+dx[k] and j+dx[k]<W and 0<=i+dy[k] and i+dy[k]<H:
                    if s[i+dy[k]][j+dx[k]]=='#':
                        cnt += 1
            if cnt==0:
                flag=False
print('Yes' if flag else 'No')

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [input() for i in range(H)]
dx=[0,-1,1,0]
dy=[1,0,0,-1]
flag = True
for i in range(W):
    for j in range(H):
        if s[i][j]=='#':
            cnt = 0
            for k in range(4):
                if 0<=j+dx[k] and j+dx[k]<W and 0<=i+dy[k] and i+dy[k]<H:
                    if s[i+dy[k]][j+dx[k]]=='#':
                        cnt += 1
            if cnt==0:
                flag=False
print('Yes' if flag else 'No')


Fixed submission:
H,W = map(int,input().split())
s = [input() for i in range(H)]
dx=[0,-1,1,0]
dy=[1,0,0,-1]
flag = True
for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            cnt = 0
            for k in range(4):
                if 0<=j+dx[k] and j+dx[k]<W and 0<=i+dy[k] and i+dy[k]<H:
                    if s[i+dy[k]][j+dx[k]]=='#':
                        cnt += 1
            if cnt==0:
                flag=False
print('Yes' if flag else 'No')
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
ans = []
for i in range(A,A+K):
    if i <= B:
        ans.append(i)
for i in range(B-K+1,B+1):
    if not i in ans and A <= i:
        ans.append(i)
for i in ans:


Fixed submission:
A,B,K = map(int,input().split())
ans = []
for i in range(A,A+K):
    if i <= B:
        ans.append(i)
for i in range(B-K+1,B+1):
    if not i in ans and A <= i:
        ans.append(i)
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n, y = map(int,input().split())
flag = False

for i in range(y//10000+1):
    for j in range(y//5000+1):
        tmp = y - 10000*i - 5000*j
        k = tmp//1000
        if i+j+k == n and k >= 0:
            print('{0} {1} {2}'.format(i,j,k))
            flag = True
            break
    if flag:
        break
if not flag:
    print('-1 -1 -1')


Fixed submission:
n, y = map(int,input().split())
flag = False

for i in range(y//10000+1):
    for j in range(y//5000+1):
        tmp = y - 10000*i - 5000*j
        k = tmp//1000
        if i+j+k == n and k >= 0:
            print('{0} {1} {2}'.format(i,j,k))
            flag = True
            break
    if flag:
        break
if not flag:
    print('-1 -1 -1')
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = [list(map(int,input().split())) for i in range(N)]
used = [False for i in range(N)]
def dfs(p,K,d=0,ans=[[],[]],s=float('inf')):
    if K==d:
        s = abs(max(ans[0])-min(ans[0]))*abs(max(ans[1])-min(ans[1]))
        return s
    for i in range(len(p)):
        if used[i]:
            continue
        used[i] = True
        ans[0].append(p[i][0])
        ans[1].append(p[i][1])
        s = min(s,dfs(p,K,d+1,ans))
        del ans[0][d]
        del ans[1][d]
        used[i] = False
    return s
print(dfs(p,K))


Fixed submission:
N,K = map(int,input().split())
X,Y = [],[]
p = []
for i in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
    p.append([x,y])
X.sort(),Y.sort()
ans = abs(X[N-1]-X[0])*abs(Y[N-1]-Y[0])
for xi in range(N):
    for xj in range(xi+1,N):
        for yi in range(N):
            for yj in range(yi+1,N):
                lx,rx = X[xi],X[xj]
                dy,uy = Y[yi],Y[yj]
                num = 0
                for x,y in p:
                    if lx<=x and x<=rx and dy<=y and y<=uy:
                        num += 1
                if K==num:
                    ans = min(abs(rx-lx)*abs(uy-dy),ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = [] 

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
print(len(ans))



Fixed submission:
n = int(input())
ans = set() 

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = []

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.append(a)
print(len(ans))


Fixed submission:
n = int(input())
ans = set() 

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
ans = []

for i in range(n):
    a.append(int(input()))
    if a[i] in ans:
        ans.remove(a[i])
    else:
        ans.append(a[i])
print(len(ans))

Fixed submission:
n = int(input())
ans = set() 

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
ans = []

for i in range(n):
    if a[i] in ans:
        ans.remove(a[i])
    else:
        ans.append(a[i])
print(len(ans))


Fixed submission:
n = int(input())
ans = set() 

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def dfs(neigh,K):
    q = deque()
    q.append(K)
    visited = [False]*N
    d = [0]*N
    visited[K] = True
    while len(q)>0:
        p = q.pop()
        for i in range(len(neigh[p])):
            if neigh[p][i]==0 or visited[i]:
                continue
            d[i] = d[p]+neigh[p][i]
            visited[i] = True
            q.append(i)
    return d

N = int(input())
neigh = [[0 for i in range(N)] for i in range(N)]
for i in range(N-1):
    a,b,c = map(int,input().split())
    neigh[a-1][b-1] = c
    neigh[b-1][a-1] = c
Q,K = map(int,input().split())
d = dfs(neigh,K-1)
for i in range(Q):
    x,y = map(int,input().split())
    print(d[x-1]+d[y-1])


Fixed submission:
from collections import deque
def dfs(neigh,K):
    q = deque([K])
    d = [0]*N
    visited = [0]*N
    visited[K] = True
    while q:
        p = q.pop()
        for di,cost in neigh[p]:
            if visited[di]:
                continue
            d[di] = d[p]+cost
            visited[di] = True
            q.append(di)
    return d

N = int(input())
neigh = [[] for i in range(N)]
for i in range(N-1):
    a,b,c = map(int,input().split())
    neigh[a-1].append((b-1,c))
    neigh[b-1].append((a-1,c))

Q,K = map(int,input().split())
d = dfs(neigh,K-1)
for i in range(Q):
    x,y = map(int,input().split())
    print(d[x-1]+d[y-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = (int(i) for i in input().split())
a,b = [0 for i in range(m)],[0 for i in range(m)]
g = [[0 for i in range(m)] for j in range(m)]
OK = False 
for i in range(m):
    a[i],b[i] = map(int, input().split())
    a[i]-=1
    b[i]-=1

for i in range(m):
    if a[i]==0:
        v = b[i]
        for j in range(m):
            if a[j]==v and b[j]==n-1:
                OK = True
print('POSSIBLE' if OK else 'IMPOSSIBLE')


Fixed submission:
n, m = (int(i) for i in input().split())
a,b = [0 for i in range(m)],[0 for i in range(m)]
g = [[] for i in range(n)]
OK = False 
for i in range(m):
    a[i],b[i] = map(int, input().split())
    a[i]-=1
    b[i]-=1
    g[a[i]].append(b[i])
    g[b[i]].append(a[i])
for i in range(m):
    if a[i]==0 and n-1 in g[b[i]]:
        OK = True
print('POSSIBLE' if OK else 'IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
def search(ans, s, ar, si = 0, ari = 0):
    if si+ari == n:
        if not(ari == 0) and not(si == 0):
            ans.append(abs(sum(s)-sum(ar)))
        return

    s.append(a[si+ari])
    search(ans,s,ar,si+1,ari)
    s.pop()

    ar.append(a[si+ari])
    search(ans,s,ar,si,ari+1)
    ar.pop()

n = int(input())
a = list(map(int,input().split()))
ans = []
s = []
ar = []
search(ans,s,ar)
print(min(ans))


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
ans = float("inf")
x = 0

for i in range(n-1):
    x += a[i]
    ans = min(ans,abs(s-2*x))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(n):
    b.append(a[i])
    b = b[::-1]
print(' '.join(map(str,b)))


Fixed submission:
from collections import deque

n = int(input())
a = list(map(int,input().split()))
b = deque([a[0]])

for i in range(1,n):
    if i%2==(n-1)%2:
        b.appendleft(a[i])
    else:
        b.append(a[i])
    
print(' '.join(map(str,b)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(n):
    b.append(a[i])
    b = b[::-1]
for i in range(n-1):
    print('{0} '.format(b[i]), end='')
print(b[-1])


Fixed submission:
from collections import deque

n = int(input())
a = list(map(int,input().split()))
b = deque([a[0]])

for i in range(1,n):
    if i%2==(n-1)%2:
        b.appendleft(a[i])
    else:
        b.append(a[i])
    
print(' '.join(map(str,b)))
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
key = []
value = []
a, b = map(int, input().split())
key.append(a)
value.append(b)
s = 0
for i in range(n-1):
    last = True    
    a, b = map(int, input().split())
    for j in range(len(key)):
        if a <= key[j]:
            key.insert(j,a)
            value.insert(j,b)
            last = False
            break
    if last:
        key.append(a)
        value.append(b)
for i in range(n):
    s += value[i]
    if k <= s:
        print(key[i])
        break


Fixed submission:
n,k = map(int,input().split())
arr = [0 for i in range(1,10**5+2)]
s = 0
for i in range(n):
    a,b = map(int, input().split())
    arr[a] += b
for i in range(1,10**5+1):
    s += arr[i]
    if k <= s:
        print(i)
        break

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
array = []
for i in range(n):
    a, b = map(int, input().split())
    for j in range(b):
        array.append(a)
array.sort()
print(array[k-1])


Fixed submission:
n,k = map(int,input().split())
arr = [0 for i in range(1,10**5+2)]
s = 0
for i in range(n):
    a,b = map(int, input().split())
    arr[a] += b
for i in range(1,10**5+1):
    s += arr[i]
    if k <= s:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
INF = float('inf')
N,M = map(int,input().split())
edge = []
d = [INF]*N
d[0] = 0
negative = [False for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    edge.append([a-1,b-1,-c])

for i in range(N):
    for j in range(M):
        if d[edge[j][0]]==INF:
            continue
        d[edge[j][1]] = min(d[edge[j][1]],d[edge[j][0]]+edge[j][2])

ans = d[N-1]

for i in range(N):
    for j in range(M):
        if d[j]==INF:
            continue
        if d[edge[j][1]]>d[edge[j][0]]+edge[j][2]:
            d[edge[j][1]]=d[edge[j][0]]+edge[j][2]
            negative[edge[j][1]] = True
        if negative[edge[j][0]]:
            negative[edge[j][1]] = True
print('inf' if negative[N-1] else -ans)


Fixed submission:
INF = float('inf')
N,M = map(int,input().split())
edge = []
d = [INF]*N
d[0] = 0
negative = [False for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    edge.append([a-1,b-1,-c])

for i in range(N):
    for j in range(M):
        if d[edge[j][0]]==INF:
            continue
        d[edge[j][1]] = min(d[edge[j][1]],d[edge[j][0]]+edge[j][2])

ans = d[N-1]

for i in range(N):
    for j in range(M):
        if d[edge[j][0]]==INF:
            continue
        if d[edge[j][1]]>d[edge[j][0]]+edge[j][2]:
            d[edge[j][1]]=d[edge[j][0]]+edge[j][2]
            negative[edge[j][1]] = True
        if negative[edge[j][0]]:
            negative[edge[j][1]] = True
print('inf' if negative[N-1] else -ans)
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w_in, v = map(int,input().split())
table = [[] for i in range(4)]
table[0].append(v)
for i in range(N-1):
    w, v = map(int,input().split())
    table[w-w_in].append(v)
for i in range(N):
    table[i].sort(reverse=True)
    for j in range(len(table[i])-1):
            table[i][j+1] += table[i][j]
    table[i].insert(0,0)
ans = 0
for i in range(len(table[0])):
    for j in range(len(table[1])):
        for k in range(len(table[2])):
            for l in range(len(table[3])):
                if w_in*i+(w_in+1)*j+(w_in+2)*k+(w_in+3)*l <= W:
                    ans = max(ans, table[0][i]+table[1][j]+table[2][k]+table[3][l])
print(ans)


Fixed submission:
N,W = map(int,input().split())
w_in, v = map(int,input().split())
table = [[] for i in range(4)]
table[0].append(v)
for i in range(N-1):
    w, v = map(int,input().split())
    table[w-w_in].append(v)
for i in range(4):
    table[i].sort(reverse=True)
    for j in range(len(table[i])-1):
            table[i][j+1] += table[i][j]
    table[i].insert(0,0)
ans = 0
for i in range(len(table[0])):
    for j in range(len(table[1])):
        for k in range(len(table[2])):
            for l in range(len(table[3])):
                if w_in*i+(w_in+1)*j+(w_in+2)*k+(w_in+3)*l <= W:
                    ans = max(ans, table[0][i]+table[1][j]+table[2][k]+table[3][l])
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]
ans = ''
for i in range(97,97+26):
    count=float("inf")
    for j in range(n):
        count=min(count,a[j].count(chr(i)))
    ans += chr(i)*count

print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
ans = ''
for i in range(97,97+26):
    count=float("inf")
    for j in range(n):
        count=min(count,s[j].count(chr(i)))
    ans += chr(i)*count

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
dv = []
dved = []
for i in range(1,n//2):
    if n%i==0 and not(i in dved):
        dv.append(i)
        dved.append(n//i) 
    if i in dved:
        break
print(len(str(dved[-1]))if len(dv)>0 else 1)


Fixed submission:
import math
n = int(input())
dv = []
dved = []
for i in range(1,int(math.sqrt(n)+1)):
    if n%i==0 and not(i in dved):
        dv.append(i)
        dved.append(n//i) 
    if i in dved:
        break
print(len(str(dved[-1]))if len(dv)>0 else 1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
dv = []
dved = []
for i in range(1,n):
    if n%i==0 and not(i in dved):
        dv.append(i)
        dved.append(n//i) 
    if i in dved:
        break
print(len(str(dved[-1])))


Fixed submission:
import math
n = int(input())
dv = []
dved = []
for i in range(1,int(math.sqrt(n)+1)):
    if n%i==0 and not(i in dved):
        dv.append(i)
        dved.append(n//i) 
    if i in dved:
        break
print(len(str(dved[-1]))if len(dv)>0 else 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
for i in range(1,n+1):
    ans *= i
print(ans%(10**9+7))


Fixed submission:
n = int(input())
ans = 1
for i in range(1,n+1):
    ans = ans*i % (10**9+7)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
i,j = 0,0
start = []
while i<=n-m:
    if b[0] in a[i]:
        start.append(a[i].index(b[0]))
        j += 1
        for k in range(1,m):
            if b[k] in a[i+j]:
                start.append(a[i+j].index(b[k]))
                j += 1
                if not start[0] == start[j-1]:
                    start.clear()
                    j = 0
                break
            else:
                start.clear()
                j = 0
                break
    if len(start)==m:
        break
    i += 1
print('Yes' if len(start)>0 else 'No')


Fixed submission:
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
res = True
for i in range(len(b)):
    if b[i] not in a[i]:
        res = False
        break

print('Yes' if res else 'No')

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
i,j = 0,0
start = []
while i<=n-m:
    if b[0] in a[i]:
        start.append(a[i].index(b[0]))
        j += 1
        for k in range(1,m):
            if b[k] in a[i+j]:
                start.append(a[i+j].index(b[k]))
                j += 1
            else:
                start.clear()
                j = 0
                break
            if not start[0] == start[j-1]:
                start.clear()
                j = 0
                break
    if len(start)==m:
        break
    i += 1
print('Yes' if len(start)>0 else 'No')


Fixed submission:
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
res = True
for i in range(len(b)):
    if b[i] not in a[i]:
        res = False
        break

print('Yes' if res else 'No')

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
i,j = 0,0
start = []
while i<n-m:
    if b[0] in a[i]:
        start.append(a[i].index(b[0]))
        j += 1
        for k in range(1,m):
            if b[k] in a[i+j]:
                start.append(a[i+j].index(b[k]))
                j += 1
            else:
                start.clear()
                j = 0
                break
            if (not start[0] == start[j-1]):
                start.clear()
                j = 0
                break
    i += 1
print('Yes' if len(start)>0 else 'No')

Fixed submission:
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
res = True
for i in range(len(b)):
    if b[i] not in a[i]:
        res = False
        break

print('Yes' if res else 'No')