Problem p03155 (python)

Fixed submission:
n = int(input())
h = int(input())
w = int(input())


ans = (n - h+1)*(n-w+1)

print(ans)

Buggy submission (verdict: Runtime Error):
h, w = list(map(int, input().split()))
field = []
for i in range(h):
    si = input()
    field.append( [c for c in si] )

def visalizer():
    global field
    print("=========================")
    for i in range(h):
        for j in range(w):
            print(field[i][j], end=' ')
        print('\n')
    print("=========================")

def maeke_last(c):
    if c == "#":
        return "."
    else:
        return "#"

pair_list = []
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
def dfs( last, s_row=0, s_colmun=0, row=0, column=0,):
    global field
    global dict
    if not((0 <= row and row <=h-1) and (0 <=column and column <= w-1)):
        return
    if field[row][column] == '@':
        return

    here = field[row][column]

    if here == last:
        return
    else:
        if not ((s_row, s_colmun) ,(row, column)) in pair_list:
            if here == '.':
                pair_list.append(((s_row, s_colmun) ,(row, column)))


    here_was = field[row][column]
    field[row][column] = '@'
    # visalizer()
    for i in range(len(dx)):
        n_row = row + dx[i]
        n_column = column + dy[i]
        dfs(last = here, s_row = s_row, s_colmun=s_colmun, row=n_row, column=n_column)
    field[row][column] = here_was

# for s_row in range(h):
#     for s_column in range(w):
#         dfs(last = field[s_row][s_column],  s_row=s_row, s_colmun=s_column, row=s_row, column=s_column)

for s_row in range(h):
    for s_column in range(w):
        if field[s_row][s_column] == "#":
            dfs(last = maeke_last(field[s_row][s_column]),  s_row=s_row, s_colmun=s_column, row=s_row, column=s_column)

for ele in pair_list:
    if ele[0]==ele[1] :
        pair_list.remove(ele)
    # pair_list.remove((ele[1], ele[0]))

pair_list2 = []
# for ele in pair_list:
#     if (not (ele[1], ele[0]) in pair_list2) :
#         pair_list2.append(ele)

# for ele in pair_list2:
#     print(ele)
print(len(pair_list))


# visalizer()

Buggy submission (verdict: Runtime Error):
h, w = list(map(int, input().split()))
field = []
for i in range(h):
    si = input()
    field.append( [c for c in si] )

def visalizer():
    global field
    print("=========================")
    for i in range(h):
        for j in range(w):
            print(field[i][j], end=' ')
        print('\n')
    print("=========================")

def maeke_last(c):
    if c == "#":
        return "."
    else:
        return "#"

pair_list = []
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
def dfs( last, s_row=0, s_colmun=0, row=0, column=0,):
    global field
    global dict
    if not((0 <= row and row <=h-1) and (0 <=column and column <= w-1)):
        return
    if field[row][column] == '@':
        return

    here = field[row][column]

    if here == last:
        return
    else:
        if not ((s_row, s_colmun) ,(row, column)) in pair_list:
            if here == '.':
                pair_list.append(((s_row, s_colmun) ,(row, column)))


    here_was = field[row][column]
    field[row][column] = '@'
    # visalizer()
    for i in range(len(dx)):
        n_row = row + dx[i]
        n_column = column + dy[i]
        dfs(last = here, s_row = s_row, s_colmun=s_colmun, row=n_row, column=n_column)
    field[row][column] = here_was

# for s_row in range(h):
#     for s_column in range(w):
#         dfs(last = field[s_row][s_column],  s_row=s_row, s_colmun=s_column, row=s_row, column=s_column)

for s_row in range(h):
    for s_column in range(w):
        if field[s_row][s_column] == "#":
            dfs(last = maeke_last(field[s_row][s_column]),  s_row=s_row, s_colmun=s_column, row=s_row, column=s_column)

for ele in pair_list:
    if ele[0]==ele[1] :
        pair_list.remove(ele)
    # pair_list.remove((ele[1], ele[0]))

pair_list2 = []
# for ele in pair_list:
#     if (not (ele[1], ele[0]) in pair_list2) :
#         pair_list2.append(ele)

# for ele in pair_list2:
#     print(ele)
print(len(pair_list))


# visalizer()