Problem p03591 (python)

Fixed submission:
# -*- coding: utf-8 -*-

s = input()
l = s.split("I")
if(l[0] == "YAK" and len(s) > 3):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

inlist = input().split()
n = int(inlist[0])
m = int(inlist[1])
k = int(inlist[2])
mat = [[1 for i in range(n)] for j in range(m)]

def initialize(i, j, matrix):
    for k in range(i):
        for l in range(j):
            matrix[k][l] = 1
    return matrix

def sum_mat(i, j, matrix):
    sum = 0
    for k in range(i):
        for l in range(j):
            sum = sum + matrix[k][l]
    return sum

escape = False

for l in range(n + 1): #l = 0 -> n
    mat = initialize(n, m, mat)
    for i in range(l):
        for j in range(m):
            mat[i][j] = -mat[i][j]
    mat_save = mat
    for p in range(m + 1): # p = 0 -> m
        mat = mat_save
        for j in range(p):
            for i in range(n):
                mat[i][j] = -mat[i][j]
        sum = sum_mat(n, m, mat)
        if(sum == n * m - 2 * k):
            print("Yes")
            escape = True
            break;
        elif(l == n and p == m):
            print("No")
    if(escape):
        break;

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

inlist = input().split()
n = int(inlist[0])
m = int(inlist[1])
k = int(inlist[2])
mat = [[1 for i in range(n)] for j in range(m)]

def initialize(i, j, matrix):
    for k in range(i):
        for l in range(j):
            matrix[k][l] = 1
    return matrix

def sum_mat(i, j, matrix):
    sum = 0
    for k in range(i):
        for l in range(j):
            sum = sum + matrix[k][l]
    return sum

escape = False

for l in range(n + 1): #l = 0 -> n
    mat = initialize(n, m, mat)
    for i in range(l):
        for j in range(m):
            mat[i][j] = -mat[i][j]
    mat_save = mat
    for p in range(m + 1): # p = 0 -> m
        mat = mat_save
        for j in range(p):
            for i in range(n):
                mat[i][j] = -mat[i][j]
        sum = sum_mat(n, m, mat)
        if(sum == n * m - 2 * k):
            print("Yes")
            escape = True
            break;
        elif(l == n and p == m):
            print("No")
    if(escape):
        break;

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

inlist = input().split()
n = int(inlist[0])
m = int(inlist[1])
k = int(inlist[2])
mat = [[1 for i in range(n)] for j in range(m)]

def initialize(i, j, matrix):
    for k in range(i):
        for l in range(j):
            matrix[k][l] = 1
    return matrix

def sum_mat(i, j, matrix):
    sum = 0
    for k in range(i):
        for l in range(j):
            sum = sum + matrix[k][l]
    return sum

for l in range(n + 1): #l = 0 -> n
    print(mat)
    mat = initialize(n, m, mat)
    for i in range(l):
        for j in range(m):
            mat[i][j] = -mat[i][j]
    mat_save = mat
    for p in range(m + 1): # p = 0 -> m
        mat = mat_save
        for j in range(p):
            for i in range(n):
                mat[i][j] = -mat[i][j]
        sum = sum_mat(n, m, mat)
        if(sum == n * m - 2 * k):
            print("Yes")
        elif(l == n and p == m):
            print("No")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

inlist = input().split()
n = int(inlist[0])
m = int(inlist[1])
k = int(inlist[2])
mat = [[1 for i in range(n)] for j in range(m)]

def initialize(i, j, matrix):
    for k in range(i):
        for l in range(j):
            matrix[k][l] = 1
    return matrix

def sum_mat(i, j, matrix):
    sum = 0
    for k in range(i):
        for l in range(j):
            sum = sum + matrix[k][l]
    return sum

for l in range(n + 1): #l = 0 -> n
    print(mat)
    mat = initialize(n, m, mat)
    for i in range(l):
        for j in range(m):
            mat[i][j] = -mat[i][j]
    mat_save = mat
    for p in range(m + 1): # p = 0 -> m
        mat = mat_save
        for j in range(p):
            for i in range(n):
                mat[i][j] = -mat[i][j]
        sum = sum_mat(n, m, mat)
        if(sum == n * m - 2 * k):
            print("Yes")
        elif(l == n and p == m):
            print("No")