Problem:


Score : 200 points

Problem Statement

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.

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

There is at least one black square in the whole grid.

Input

Input is given from Standard Input in the following format:

H W
a_{1, 1}...a_{1, W}
:
a_{H, 1}...a_{H, W}

Output

Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

Sample Input 1

4 4
##.#
....
##.#
.#.#

Sample Output 1

###
###
.##

The second row and the third column in the original grid will be removed.

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

As there is no row or column that consists only of white squares, no operation will be performed.

Sample Input 3

4 5
.....
.....
..#..
.....

Sample Output 3

#

Sample Input 4

7 6
......
....#.
.#....
..#...
..#...
......
.#..#.

Sample Output 4

..#
#..
.#.
.#.
#.#



Sample input:
4 4
##.#
....
##.#
.#.#


Sample output:
###
###
.##

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    H, W = [int(x) for x in stdin.readline().rstrip().split()]
    mtx = [list(stdin.readline().rstrip()) for _ in range(H)]
    mtx = [x for x in mtx if len([y for y in x if y == '#']) != 0]
    mtx = [x for x in zip(*mtx)]
    mtx = [x for x in mtx if len([y for y in x if y == '#']) != 0]
    mtx = [x for x in zip(*mtx)]
    for x in mtx:
        print(''.join(x))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W = [int(i) for i in input().split()]
A = [input() for j in range(H)]

DH = []

for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            break
    else:
        DH.append(h)

DW = []

for w in range(W):
    for h in range(H):
        if A[h][w] == '#':
            break
    else:
        DW.append(w)

for h in range(H):
    for w in range(W):
        if h in DH:
            break
        elif w in DW:
            continue
        print(A[h][w], end='')
    else:
        print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split(" "))
a = [input() for _ in range(h)]

h_remove_count = 0
while "."*w in a:
	a.remove("."*w)
	h_remove_count += 1

a = ["".join(h_line) for h_line in zip(*a)]
while "."*(h-h_remove_count) in a:
	a.remove("."*(h-h_remove_count))

for line in zip(*a):
	print("".join(line))

Submission status: Accepted

Solution code:
import numpy as np

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

def tra(a):
    b = []
    for ax in a:
        if ax == '#':
            b.append(1)
        else:
            b.append(0)
    b = np.array(b)
    return b

aa = []
for i in range(h):
    a = input()
    aa.append(tra(a))

aa_ori = np.vstack(aa)

while True:
    ind = np.sum(aa_ori,axis=0) > 0
    if np.sum(ind) == len(ind):
        break
    aa_ori = aa_ori[:,ind]

    ind = np.sum(aa_ori,axis=1) > 0
    if np.sum(ind) == len(ind):
        break
    aa_ori = aa_ori[ind,:]

for a in aa_ori:
    s = ''
    for b in a:
        if b == 1:
            s += '#'
        else:
            s += '.'
    print(s)

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]

b = []
for i in range(H):
    if '#' in a[i]:
        b.append(a[i])
b = np.array(b)

c = []
for i in range(W):
    if '#' not in b[:, i]:
        c.append(i)

b = np.delete(b, c, axis=1)

for i in range(len(b)):
    print(*b[i], sep='')

Submission status: Accepted

Solution code:
h,w=[int(x) for x in input().split()]
a=[]
for _ in [0]*h:
    ai=list(input())
    if "#" in ai:
        a.append(ai)
tenchi=[]
for wi in zip(*a):
    if "#" in wi:
        tenchi.append(wi)
for ansi in zip(*tenchi):
    print("".join(ansi))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())

ls = [input() for _ in range(h)]
drops_h = []
drops_w = []

for i in range(h):
    if all([ls[i][j] == '.' for j in range(w)]):
        drops_h.append(i)

for i in range(w):
    if all([ls[j][i] == '.' for j in range(h)]):
        drops_w.append(i)

for i in range(h):
    if i in drops_h:
        continue
    else:
        for j in range(w):
            if j in drops_w:
                continue
            else:
                print(ls[i][j], end='')
        print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())

MAP=[None]*H

for i in range(H):
    MAP[i]=input()


ANSH=[]
for i in range(H):
    if "#" in MAP[i]:
        ANSH.append(i)

ANSW=[]
for i in range(W):
    check=0
    for j in range(H):
        if MAP[j][i]=="#":
            check=1

    if check==1:
        ANSW.append(i)


for i in ANSH:
    for j in ANSW:
        print(MAP[i][j],end="")

    print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
src = [input() for i in range(H)]
cols = list(zip(*src))
for row in src:
    if all([c=='.' for c in row]): continue
    out = ''
    for i,c in enumerate(row):
        if all([c=='.' for c in cols[i]]): continue
        out += c
    print(out)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

H, W = map(int, raw_input().split())

A = []

for i in range(H):
    A.append(raw_input())

H_flag = [0] * H
W_flag = [0] * W

for i in range(H):
    for j in range(W):
        if A[i][j] == '.':
            W_flag[j] += 1
            H_flag[i] += 1

for i in range(H):
    if H_flag[i] != W:
        S = ''
        for j in range(W):
            if W_flag[j] != H:
                S += A[i][j]
        print S

Submission status: Runtime Error

Solution code:
h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, w)]
list_tmp = []
for i in range(0, w):
    for j in range(0, h):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, h):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
A=[list(input()) for i in range(w)]
answ=[]
ansh=[]
for i in range(w):
  if not all([a=="." for a in A[i]]):
    answ.append(i)
for j in range(h):
  if not all([A[i][j]=="." for i in range(w)]):
    ansh.append(j)
for i in answ:
  for j in ansh:
    print(A[i][j],end="")
  print("\n")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
lis=[list(input()) for i in range(h)]

fin=[]
ans=[]

for l in lis:
  if l.count(".") != w:
    fin.append(l)
  else:  
    h=h-1

tr = []
for i in range(w):
    tr_row = []
    for vector in fin:
        tr_row.append(vector[i])
    tr.append(tr_row)
    
for t in tr:
  if t.count(".") != h:
    ans.append(t)
  else:  
    w=w-1
    
for i in range(w):
    tr_row = []
    for vector in ans:
        tr_row.append(vector[i])
    print(*tr_row)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
lis=[list(input()) for i in range(h)]

fin=[]

for l in lis:
  if l.count(".") != w:
    fin.append(l)
  else:  
    h=h-1

num=[]
for i in range(w):
  cnt=0
  for f in fin:
    if f[i] == ".":
      cnt+=1
  if cnt == h:
    num.append(i)
      
for i in num:
  for f in fin:
    f.pop(i)
    
for i in fin:
  print(*i)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
mass = [list(input()) for _ in range(H)]

for i in range(H):
  if "#" not in mass[i]:
    mass.pop(i)
  
H = len(mass)

new_mass = [[] for _ in range(W)]

for j in mass:
  for i, k in enumerate(j):
    new_mass[i].append(k)
    
for l in range(W):
  if "#" not in new_mass[l]:
    new_mass.pop(l)
    
mass = [[] for _ in range(H)]

for n in new_mass:
  for i, m in enumerate(n):
    mass[i].append(m)
    
print(mass)

Submission status: Runtime Error

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]

h,w = map(int, input().split())
a = [input() for _ in range(h)]

y = [False] * h
x = [False] * w

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            y[i] = True
            x[j] = True

for i in range(h):
    if y[i]:
        for j in range(w):
            if y[j]:
                print(a[i][j],end="")
        print("")

Submission status: Runtime Error

Solution code:
#わからないのでギブアップコピペ
h,w=map(int,input().split())

a=[] #入力データのリスト化
for i in range(h):
  x=input().split()
  a.append(x)

h1=[]
for i in range(h):
  if a[i]==['.']*w:
    h1.append(i)

w1=[]
for i in range(w):
  flag=0
  for j in range(h):
    if a[j][i]=='#':
      flag=1
      break
  if flag==0:
    w1.append(i)

ans=[]
for i in range(h):
  if i not in h1:
    r=[]
    for j in range(w):
      r.append(a[i][j])
    ans.append(r)

for i in range(lens(ans)):
  print(''.join(ans[i]))

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())

a=[] #入力データのリスト化
for i in range(h):
  x=input().split()
  a.append(x)

h1=[]
for i in range(h):
  if a[i]==['.']*w:
    h1.append(i)

w1=[]
for i in range(w):
  flag=0
  for j in range(h):
    if a[j][i]=='#':
      flag=1
      break
  if flag==0:
    w.append(i)

ans=[]
for i in range(h):
  if i not in h1:
    r=[]
    for j in range(w):
      r.append(a[i][j])
    ans.append(r)

for i in range(lens(ans)):
  print(''.join(ans[i]))

Submission status: Runtime Error

Solution code:
#わからないのでギブアップコピペ
h,w=map(int,input().split())

a=[] #入力データのリスト化
for i in range(h):
  x=input().split()
  a.append(x)

h1=[]
for i in range(H):
  if a[i]==['.']*w:
    h1.append(i)

w1=[]
for i in range(w):
  flag=0
  for j in range(h):
    if a[j][i]=='#':
      flag=1
      break
  if flag==0:
    w.append(i)

ans=[]
for i in range(h):
  if i not in h1:
    r=[]
    for j in range(w):
      r.append(a[i][j])
    ans.append(r)

for i in range(lens(ans)):
  print(''.join(ans[i]))

Submission status: Runtime Error

Solution code:
#わからないのでギブアップコピペ
h,w=map(int,input().split())

a=[] #入力データのリスト化
for i in range(h):
  x=input().split()
  a.append(x)

h1=[]
for i in range(H):
  if a[i]==['.']*w
    h1.append(i)

w1=[]
for i in range(w):
  flag=0
  for j in range(h):
    if a[j][i]=='#':
      flag=1
      break
  if flag==0:
    w.append(i)

ans=[]
for i in range(h):
  if i not in h1:
    r=[]
    for j in range(w):
      r.append(a[i][j])
    ans.append(r)

for i in range(lens(ans)):
  print(''.join(ans[i]))

Submission status: Runtime Error

Solution code:
#わからないのでギブアップ・コピペ

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

a=[] #入力データのリスト化
for i in range(h):
  x=input().split()
  a.append(x)

h1=[]
for i in range(h):
  if a[i]==['.']:
    h1.append(i)

w1=[]
for i in range(w):
  flag=0
  for j in range(h):
    if a[j][i]=='#':
      flag=1
      break
  if flag==0:
    w.append(i)

ans=[]
for i in range(h):
  if i not in h1:
    r=[]
    for j in range(w):
      r.append(a[i][j])
    ans.append(r)

for i in range(lens(ans)):
  print(''.join(ans[i]))

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
a = [''] * h

for i in range(w):
    a[i] = input()
    
row = [False] * h
cal = [False] * w

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            row[i] = True
            cal[j] = True
            
for i in range(h):
    if row[i]:
        for j in range(w):
            if cal[j]:
                print(a[i][j], end='')
        print()

Submission status: Runtime Error

Solution code:
# abc107_b.py
# https://atcoder.jp/contests/abc107/tasks/abc107_b

# B - Grid Compression /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 縦 H行、横 W 列のマス目があります。 上から i 行目、左から j 列目のマスを (i,j) と表します。 
# 各マスは白または黒です。 マス目の配色は、H 行 W 列の行列 (ai,j) によって与えられます。 
# ai,j が . ならばマス (i,j) は白であり、ai,j が # ならばマス (i,j)は黒です。
# すぬけ君はこのマス目を圧縮しようとしています。 そのために、白いマスのみからなる行または列が存在する間、次の操作を繰り返し行います。

#     操作: 白いマスのみからなる行または列をひとつ任意に選び、その行または列を取り除いて空白を詰める。

# 各操作でどの行または列を選ぶかによらず、最終的なマス目は一意に定まることが示せます。 最終的なマス目を求めてください。

# 制約
#     1≤H,W≤100
#     ai,jは . または # である。
#     マス目全体で少なくともひとつは黒いマスが存在する。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# H W
# a1,1...a1,W
# :
# aH,1...aH,W

# 出力
# 最終的なマス目を、入力と同様のフォーマットで出力せよ。 ただし、行数および列数は省くこと。 詳しくはサンプルを参照せよ。

# 入力例 1
# 4 4
# ##.#
# ....
# ##.#
# .#.#

# 出力例 1
# ###
# ###
# .##

# 元のマス目における第 2行および第 3列がそれぞれ取り除かれます。

# 入力例 2
# 3 3
# #..
# .#.
# ..#

# 出力例 2
# #..
# .#.
# ..#

# 白いマスのみからなる行または列が存在しないので、操作は行われません。

# 入力例 3
# 4 5
# .....
# .....
# ..#..
# .....

# 出力例 3
# #

# 入力例 4
# 7 6
# ......
# ....#.
# .#....
# ..#...
# ..#...
# ......
# .#..#.

# 出力例 4
# ..#
# #..
# .#.
# .#.
# #.#


def calculation(lines):
    N, W = list(map(int, lines[0].split()))
    masus = list()
    for i in range(N):
        line = lines[i+1]
        if line != '.'*W:
            masus.append(line)
    for w in range(W):
        flag = True
        for masu in masus:
            if masu[w] == '#':
                flag = False
        if flag:
            for i in range(len(masus)):
                masus[i] = masus[i][:w] + ' ' + masus[i][w+1:]
    for i in range(len(masus)):
        masus[i] = masus[i].replace(' ', '')
    return masus


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4 4', '##.#', '....', '##.#', '.#.#']
        lines_export = ['###', '###', '.##']
    if pattern == 2:
        lines_input = ['3 3', '#..', '.#.', '..#']
        lines_export = ['#..', '.#.', '..#']
    if pattern == 3:
        lines_input = ['4 5', '.....', '.....', '..#..', '.....']
        lines_export = ['#']
    if pattern == 4:
        lines_input = ['7 6', '......', '....#.', '.#....', '..#...', '..#...', '......', '.#..#.']
        lines_export = ['..#', '#..', '.#.', '.#.', '#.#']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
MM = input().split()
A = int(MM[0])
B = int(MM[1])
list1 =[]
for i in range(A):
  aa = input()
  if '.'*B == aa:
    pass
  else:
    list1.append(list(aa))


for i in range(B):
  count = 0
  for j in range(len(list1)):
    if list1[j][i] == '#':
      count +=1
  if count == 0:
    for j in range(len(list1)):
     
      list1[j][i] = 'a'

for i in list1:
  i.remove('a')

for i in list1:
  for j in i:
    print(j,end='')
  print()

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
data = []
for _ in range(h):
    data.append( list(input()) )

next_data = []
# 横列処理
for d in data:
    if "#" in d:
        next_data.append( d )

next_next_data = []
origin_v_data = []
# 縦列処理
for i in range( len(next_data[0]) ):
    # 縦配列生成
    v_data = []
    for j in range( len(next_data) ):
        v_data.append( next_data[j][i] )

    # 配列チェック
    if "#" in v_data:
        origin_v_data.append( v_data )

ans_data = []
for i in range( len(origin_v_data[0]) ):
    join_data = []
    for j in range( len(origin_v_data) ):
        join_data.append( origin_v_data[i][j] )
    ans_data.append( join_data )

# 標準出力
for a in ans_data:
    print("".join(a))

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())

grid = [list(str(input())) for _ in range(H)]

def elim(grid):
    grid_after = []
    for i in range(H):
        gset = list(set(grid[i]))
        #print(gset)
        #print(grid[i])
        if gset[0] != '.':
            grid_after.append(grid[i])
    return grid_after
    
def transpose(grid_after):
    
    H1 = len(grid_after)
    W1 = len(grid_after[0][:])
    gridT = [['']*H1 for _ in range(W1)]
    for i in range(W1):
        for j in range(H1):
            gridT[i][j] = grid_after[j][i]
            
            
    return gridT

grid_after = elim(grid)

gridT1 = transpose(grid_after)
#print(gridT1)
grid_after2 = elim(gridT1)
# print(grid_after2)
gridT2 = transpose(grid_after2)
#print(gridT2)
for i in gridT2:
    print(*i,sep='')

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

h, w = rm()
li = np.array([np.array(rl()) for _ in range(h)])
li2 = np.array([])
li3 = np.array([])
for i in li:
  if '#' not in i:
    li2.append(i)
li2 = li2.T
for i in li2:
  if '#' not in i:
    li3.append(i)
for i in li3.T:
  print(''.join(i))

Submission status: Runtime Error

Solution code:
import numpy as np
h,w=map(int,input().split())
"""
入力はスペースなしだった
文字列としてリストの行にぶち込む必要あり
icon=list()
for i in range(h):
    icon.append(list(input().split()))

"""
icon=[''] * h
for i in range(h):
    a[i]=input()


row=[False]*h
col=[False]*w

for i in range(h):
    for j in range(w):
        if icon[i][j]=='#':
            row[i]=True
            col[j]=True

for  i in range(h):
    if row[i]==True:
        for j in range(w):
            if col[j]==True:
                print(icon[i][j],end='')
        print()

Submission status: Runtime Error

Solution code:
import numpy as np
h,w=map(int,input().split())
icon=list()
for i in range(h):
    icon.append(list(input().split()))

row=[False]*h
col=[False]*w

for i in range(h):
    for j in range(w):
        if icon[i][j]=='#':
            row[i]=True
            col[j]=True

for  i in range(h):
    if row[i]==True:
        for j in range(w):
            if col[j]==True:
                print(icon[i][j],end='')
        print()

Submission status: Runtime Error

Solution code:
import numpy as np
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

a = np.array(a).reshape(h, w)
for i, v in enumerate(a):
    if "#" not in v:
        a = np.delete(a, i, 0)

a = np.rot90(a)
for i, v in enumerate(a):
    if "#" not in v:
        a = np.delete(a, i, 0)

a = np.rot90(a, 3)
for i in a:
    print(*i)

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())

a = [list(input()) for i in range(h)]
cnt = 0
i = 0

while i < len(a):
  for j in range(w):
    if a[i][j] not in "#":
      cnt += 1
  if cnt == w:
    a.remove(a[i])
    i += -1
    h += -1
  cnt = 0
  i += 1
i = 0
cnt = 1
while o < w:
  if a[0][i] == ".":
    for j in range(1,h):
      if a[i][j] == ".":
        cnt += 1
    if cnt == h:
      for j in range(h):
        a[j].pop(i)
      w += -1
      i += -1
  cnt = 1
  i+= 1
[print("".join(a[i])) for i in range(h)]

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[input() for i in range(h)]

ans=[]
for i in range(h):
  if s[i]!='.'*w:
    ans.append(s[i])

n=len(ans)
a=['' for i in range(n)]

for i in range(w):
  sm=''
  cnt=0
  for j in range(n):
    sm+=ans[j][i]
    if ans[j][i]!='.':
      cnt+=1
  if cnt!=0:
    for k in range(n):
      a[k]+=ans[k][i]
m=len(a[0])
for i in range(m):
  print(a[i])

Submission status: Runtime Error

Solution code:
 numpy as np

H, W = map(int, input().split())
a = np.zeros(shape=(H, W), dtype=bool)
for i in range(H):
  a[i] = [s == "." for s in input()]

y = [True] * H
for i in range(H):
  if all(a[i,:]):
    y[i] = False

x = [True] * W
for i in range(W):
  if all(a[:,i]):
    x[i] = False

ans = []
for i in range(H):
  if not y[i]:
    continue
  s = ""
  for j in range(W):
    if not x[j]:
      continue
    s = "".join([s, "." if a[i,j] else "#"])
  ans.append(s)

print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
 numpy as np

H, W = map(int, input().split())
a = np.zeros(shape=(H, W), dtype=bool)
for i in range(H):
  a[i] = [s == "." for s in input().split()]

y = [True] * H
for i in range(H):
  if all(a[i,:]):
    y[i] = False

x = [True] * W
for i in range(W):
  if all(a[:,i]):
    x[i] = False

ans = []
for i in range(H):
  if not y[i]:
    continue
  s = ""
  for j in range(W):
    if not x[j]:
      continue
    s = "".join([s, "." if a[i,j] else "#"])
  ans.append(s)

print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
import numpy as np

H, W = map(int, input().split())
a = np.array(shape=(H, W), dtype=bool)
for i in range(H):
  a[i] = [s == "." for s in input().split()]

y = [True] * H
 i in range(H):
  if all(a[i,:]):
    y[i] = False

x = [True] * W
for i in range(W):
  if all(a[:,i]):
    x[i] = False

ans = []
for i in range(H):
  if not y[i]:
    continue
  s = ""
  for j in range(W):
    if not x[j]:
      continue
    s = "".join([s, "." if a[i,j] else "#"])
  ans.append(s)

print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
/*  ex5_3
    Graku   */
#include<stdio.h>

int main(void) {
    int height, width;
    scanf("%d %d", &height, &width);
    char matrix[height][width];
    for (int row = 0; row < height; ++row) {
        for (int col = 0; col < width; ++col) {
            scanf(" %c", &matrix[row][col]); //don't read "\n"
        }
    }

    int blank_rows[height], blank_cols[width]; //blank -> 0, not blank -> 1
    for (int row = 0; row < height; ++row) { //find blank rows
        int flag = 0;
        for (int col = 0; col < width; ++col) {
            if ('#' == matrix[row][col]) { //not blank
                flag = 1;
                break;
            }
        }
        blank_rows[row] = flag;
    }
    for (int col = 0; col < width; ++col) { //find blank columns
        int flag = 0;
        for (int row = 0; row < height; ++row) {
            if ('#' == matrix[row][col]) { //not blank
                flag = 1;
                break;
            }
        }
        blank_cols[col] = flag;
    }

    for (int row = 0; row < height; row++) {
        if (blank_rows[row]) { //if row is not blank
            for (int col = 0; col < width; ++col) {
                if (blank_cols[col]) { //if column is not blank
                    printf("%c", matrix[row][col]);
                }
            }
            printf("\n");
        }
    }

    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

H, W = map(int, input().split())
aHW = [list(input()) for _ in range(H)]
naHW = np.array(aHW)
# naHW = np.array(input(), object)
# print(naHW)

res = []
for h in aHW:
    if '#' in h:
        res.append(h)

res = list(zip(*res))
res2 = []
for h in res:
    if '#' in h:
        res2.append(h)

res2 = list(zip(*res2))

for h in res2:
    print(''.join(h))

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
mat = []
for i in range(h):
  g = list(input().split())
  if g.count(".") != w:
    mat.append(g)

for i in range(w-1, -1, -1):
  count = 0
  for j in range(len(mat)):
    if mat[j][i] == ".":
      count += 1
  if count == len(mat):
    for j in range(len(mat)):
      mat[j].pop(i)

for h in range(len(mat)):
  print(" ".join(mat[h]))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
const ll INF = 1LL << 60;
//cout << fixed << setprecision(10);
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
    ll h, w;
    cin>>h>>w;
    vector<string> grid(h);
    set<ll> ver, hor;
    rep(i,h){
        string s;
        cin>>s;
        grid[i] = s;
        rep(j,w){
            if(s[j] == '#'){
                ver.insert(i);
                hor.insert(j);
            }
        }
    }
    rep(i,h){
        rep(j,w){
            bool t = false;
            if(ver.count(i) && hor.count(j)){
                cout<<grid[i][j];
                t = true;
            }
            if(t && j == *rbegin(ver)) cout<<endl;
        }
    }
}

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

H,W = inputIL()
data = []
for _ in range(H):
  s = inputS()
  if s != "."*W:
    data.append(s)

memo = []
for i in range(W):
  flag = 1
  for j in range(len(data)):
    if data[i][j] == "#":
      flag = 0
  if flag == 0:
    memo.append(i)
    
ans = [[data[j][i] for i in memo] for j in range(len(data))]

for i in range(len(ans)):
  print(*ans[i],sep="")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
a = [input() for _ in range(H)]

row = [False]*H
col = [Flase]*W

for i in range(H):
  for j in range(w):
    if a[i][j] == "#":
      row[i] = True
      col[j] = True

for i in range(h):
  if row[i]:
    for j in range(w):
      if col[j]:
        print(a[i][j],end = '')
  print()

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
a_list = [input() for nesya in range(h)]

gyo = [False]*h
retsu = [False]*w
for i in range(h):
  for j in range(w):
    if a_list[i][j] == '#':
      gyo[i] = True
      retsu[j] = True
for k range(h):
  if gyo[k]:
    for l in range(w):
      if retsu[l]:
        print(a_list[k][l], end='')
    print()

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
memo_yoko = [False]*w
memo_tate = [False]*h
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            memo_yoko[i] = True
            memo_tate[j] = True

for i in range(h):
    if memo_yoko[i]:
        for j in range(w):
            if memo_tate[j]:
                print(a[i][j], end="")
        print()