Problem p03804 (python)

Fixed submission:
n, m = [int(x) for x in input().split()]
img_a = []
img_b = []

for i in range(n):
    img_a.append(input())

for i in range(m):
    img_b.append(input())

ans = "No"
for a in range(n - m + 1):
    border = 0
    flag = True
    while flag:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                flag = False
                break

        else: # if not loop broken.
            ans = "Yes"
            break
        

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
img_a = [input() for _ in range(n)]
img_b = [input() for _ in range(m)]

found = False
for a in range(n - m + 1):
    border = 0
    isok = True
    while isok and not flag:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                isok = False
                break

        else: # if not loop broken.
            ans = "Yes"
            found = True
            break
    if found:
        break
else: # if not 'found==True' even after last loop, then it means B is not in A.
    ans = "No"
        
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
img_a = []
img_b = []

for i in range(n):
    img_a.append(input())

for i in range(m):
    img_b.append(input())

ans = "No"
for a in range(n - m + 1):
    dup_a = img_a.copy()
    dup_b = img_b.copy()
    flag = True
    while flag:
        for b in range(m):
            if dup_b[b] in dup_a[b+a]:
                if b == 0:
                    index = dup_a[a].index(dup_b[0])
                current_index = dup_a[b+a].index(dup_b[b])
                if current_index != index:                
                    if current_index > index:
                        for line in dup_a:
                            del line[:current_index]
                        break
                    else:
                        for line in dup_a:
                            del line[:index]
                        break
            else:   # if not substring in string.
                flag = False
                break

        else: # if not for loop broken.
            ans = "Yes"
            break
        

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
img_a = []
img_b = []

for i in range(n):
    img_a.append(input())

for i in range(m):
    img_b.append(input())

ans = "No"
for a in range(n - m + 1):
    dup_a = img_a.copy()
    dup_b = img_b.copy()
    flag = True
    while flag:
        for b in range(m):
            if dup_b[b] in dup_a[b+a]:
                if b == 0:
                    index = dup_a[a].index(dup_b[0])
                current_index = dup_a[b+a].index(dup_b[b])
                if current_index == index:
                    continue
                elif current_index > index:
                    for line in dup_a:
                        del line[:current_index]
                    break
                else:
                    for line in dup_a:
                        del line[:index]
                    break
            else:   # if not substring in string.
                flag = False
                break

        else: # if not loop broken.
            ans = "Yes"
            break
        

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
img_a = []
img_b = []

for i in range(n):
    img_a.append(input())

for i in range(m):
    img_b.append(input())

ans = "No"
for a in range(n - m + 1):
    dup_a = img_a.copy()
    dup_b = img_b.copy()
    while True:
        for b in range(m):
            if dup_b[b] in dup_a[b+a]:
                if b == 0:
                    index = dup_a[a].index(dup_b[0])
                current_index = dup_a[b+a].index(dup_b[b])
                if current_index == index:
                    continue
                elif current_index > index:
                    for line in dup_a:
                        del line[:current_index]
                    break
                else:
                    for line in dup_a:
                        del line[:index]
                    break
            else:   # if not substring in string.
                break
        
        if not dup_b[b] in dup_a[b+a]:
            break

        # if not loop broken.
        ans = "Yes"
        break
        

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
img_a = []
img_b = []

for i in range(n):
    img_a.append(input())

for i in range(m):
    img_b.append(input())

ans = "No"
for a in range(n - m + 1):
    dup_a = img_a.copy()
    dup_b = img_b.copy()
    while True:
        for b in range(m):
            if dup_b[b] in dup_a[b+a]:
                if b == 0:
                    index = dup_a[a].index(dup_b[0])
                current_index = dup_a[b+a].index(dup_b[b])
                
                if current_index > index:
                    for line in dup_a:
                        del line[:current_index]
                        break
                elif current_index < index:
                    for line in dup_a:
                        del line[:index]
                        break
        
            else:   # if not substring in string.
                break
        else: # if not loop broken.
            ans = "Yes"
            break
        if not dup_b[b] in dup_a[b+a]:
            break

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
img_a = []
img_b = []

for i in range(n):
    img_a.append(input())

for i in range(m):
    img_b.append(input())

ans = "No"
for a in range(n - m + 1):
    dup_a = img_a.copy()
    dup_b = img_b.copy()
    while True:
        for b in range(m):
            if dup_b[b] in dup_a[b+a]:
                if b == 0:
                    index = dup_a[a].index(dup_b[0])
                current_index = dup_a[b+a].index(dup_b[b])
                
                if current_index > index:
                    for line in dup_a:
                        del line[:current_index]
                        break
                elif current_index < index:
                    for line in dup_a:
                        del line[:index]
                        break
        
            else:   # if not substring in string.
                break
        else: # if not loop broken.
            ans = "Yes"
            break
        if not dup_b[b] in dup_a:
            break

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
img_a = []
img_b = []

for i in range(n):
    img_a.append(input())

for i in range(m):
    img_b.append(input())

ans = "No"
for a in range(n - m + 1):
    dup_a = img_a.copy()
    dup_b = img_b.copy()
    while True:
        for b in range(m):
            if dup_b[b] in dup_a[b+a]:
                if b == 0:
                    index = dup_a[a].index(dup_b[0])
                current_index = dup_a[b+a].index(dup_b[b])
                
                if current_index > index:
                    for line in dup_a:
                        del line[:current_index]
                        break
                elif current_index < index:
                    for line in dup_a:
                        del line[:index]
                        break
        
            else:   # if not substring in string.
                break
        else: # if not loop broken.
            ans = "Yes"
            break

print(ans)