Problem p03804 (python)

Fixed submission:
# ABC 054: B – Template Matching
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

isIncluding = False

for a_row in range(n):
    for a_column in range(n):

        if a[a_row][a_column] == b[0][0]:

            isExact = True
            for b_row in range(m):
                for b_column in range(1, m):
                    if a_row + b_row > n - 1 or a_column + b_column > n - 1:
                        isExact = False
                        break

                    if b[b_row][b_column] != a[a_row + b_row][a_column + b_column]:
                        isExact = False
                        break

                if not isExact:
                    isExact = True
                    break
            else:
                isIncluding = True
                break

        if isIncluding:
            break
            
    if isIncluding:
        break

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

Buggy submission (verdict: Runtime Error):
# ABC 054: B – Template Matching
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

isIncluding = False

for a_row in range(n):
    for a_column in range(n):

        if a[a_row][a_column] == b[0][0]:

            isExact = True
            for b_row in range(m):
                for b_column in range(1, m):
                    if b[b_row][b_column] != a[a_row + b_row][a_column + b_column]:
                        isExact = False
                        break
                if not isExact:
                    isExact = True
                    break
            else:
                isIncluding = True
                break
        if isIncluding:
            break
    if isIncluding:
        break

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

Buggy submission (verdict: Runtime Error):
# ABC 054: B – Template Matching
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

isIncluding = 'No'
current = 0

for i in range(n):
    if b[0] in a[i]:
        current = a[i].index(b[0])

        for j in range(1, m):
            if b[j] not in a[i + j] or a[i + j].index(b[j]) != current:
                break
        else:
            isIncluding = 'Yes'
            break

print(isIncluding)

Buggy submission (verdict: Runtime Error):
# ABC 054: B – Template Matching
n, m = [int(s) for s in input().split()]
a = []
b = []

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

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

is_contained = 'No'

for i in range(n - m + 1):
    for j in range(m - i):
        if b[j] in a[j]:
            if a[j].index(b[j]) != a[i].index(b[i]):
                break
    else:
        is_contained = 'Yes'
        break

print(is_contained)

Buggy submission (verdict: Runtime Error):
# ABC 054: B – Template Matching
n, m = [int(s) for s in input().split()]
a = []
b = []

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

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

is_contained = 'No'

for i in range(n - m + 1):
    if b[0] in a[i]:
        for j in range(m - i):
            if a[j].index(b[j]) != a[i].index(b[i]):
                break
        else:
            is_contained = 'Yes'
            break

print(is_contained)