Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
h, w = map(int, input().split())

l = []
ll = [[True for i in range(w)] for j in range(h)]
for _ in range(h):
    s = input()
    cells = list(s)
    # print(cells)
    l.append(cells)
    
# print(l)

for h_i in range(h):
    flag = True
    for w_i in range(w):
        # print(l[h_i][w_i])
        if l[h_i][w_i] == "#":
            flag = False
            break
    if flag:
        for w_i in range(w):
            ll[h_i][w_i] = False

for w_i in range(w):
    flag = True
    for h_i in range(h):
        # print(l[h_i][w_i])
        if l[h_i][w_i] == "#":
            flag = False
            break
    if flag:
        for h_i in range(h):
            ll[h_i][w_i] = False
            
# print(ll)

for i in range(h):
    lll = []a
    for j in range(w):
        # print(l[i][j])
        if ll[i][j]:
            lll.append(l[i][j])
    if len(lll) > 0:
        print(''.join(lll))

h, w = map(int, input().split())

l = []
ll = [[True for i in range(w)] for j in range(h)]
for _ in range(h):
    s = input()
    cells = list(s)
    # print(cells)
    l.append(cells)
    
# print(l)

for h_i in range(h):
    flag = True
    for w_i in range(w):
        # print(l[h_i][w_i])
        if l[h_i][w_i] == "#":
            flag = False
            break
    if flag:
        for w_i in range(w):
            ll[h_i][w_i] = False

for w_i in range(w):
    flag = True
    for h_i in range(h):
        # print(l[h_i][w_i])
        if l[h_i][w_i] == "#":
            flag = False
            break
    if flag:
        for h_i in range(h):
            ll[h_i][w_i] = False
            
# print(ll)

for i in range(h):
    lll = []a
    for j in range(w):
        # print(l[i][j])
        if ll[i][j]:
            lll.append(l[i][j])
    if len(lll) > 0:
        print(''.join(lll))

h, w = map(int, input().split())

l = []
ll = [[True for i in range(w)] for j in range(h)]
for _ in range(h):
    s = input()
    cells = list(s)
    # print(cells)
    l.append(cells)
    
# print(l)

for h_i in range(h):
    flag = True
    for w_i in range(w):
        # print(l[h_i][w_i])
        if l[h_i][w_i] == "#":
            flag = False
            break
    if flag:
        for w_i in range(w):
            ll[h_i][w_i] = False

for w_i in range(w):
    flag = True
    for h_i in range(h):
        # print(l[h_i][w_i])
        if l[h_i][w_i] == "#":
            flag = False
            break
    if flag:
        for h_i in range(h):
            ll[h_i][w_i] = False
            
# print(ll)

for i in range(h):
    lll = []
    for j in range(w):
        # print(l[i][j])
        if ll[i][j]:
            lll.append(l[i][j])
    if len(lll) > 0:
        print(''.join(lll))

Verdicts: Runtime Error

Runtime Error

Accepted