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 ..#
#..
.#.
.#.
#.#

Solution (Python):
H, W = map(int, input().split())
S, U = [], []
for _ in range(H):
    s = list(input())
    if "
T = list(zip(*S))
for i in range(W):
    if "
res = []
for t in zip(*U):
    res.append("".join(t))
print("\n".join(res))

Solution (Python):
def main():
    h, w = list(map(int, input().split()))
    board = []
    safe_h = set()
    safe_w = set()
    for i in range(h):
        board.append(list(input()))
    for i in range(h):
        for j in range(w):
            if board[i][j] == '
                safe_h.add(i)
                safe_w.add(j)
    for i in safe_h:
        for j in safe_w:
            print(board[i][j], end='')
        print()


if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
a = [x for x in a if '
aT = list(zip(*a))
aT = [x for x in aT if '
a = list(zip(*aT))
for i in a:
    print(''.join(i))

Solution (Python):
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
delrow = []
delline = []
for i in range(w):
  whiteline = 0
  for j in range(h):
    if a[j][i] == ".":
      whiteline += 1
    if whiteline == h:
      delline.append(i)
for i in range(h):
  whiterow = 0
  for j in range(w):
    if a[i][j] == ".":
      whiterow += 1
    if whiterow == w:
      delrow.append(i)
for i in range(h):
  if i in delrow:
    continue
  else:
    ans = ""
    for j in range(w):
      if j in delline:
        continue
      else:
        ans += a[i][j]
  print(ans)

Solution (Python):
from typing import List


def answer(h: int, w: int, a: List[str]) -> List[str]:
    for i in range(2):
        white_line = '.' * w
        loop = a.count(white_line)
        for _ in range(loop):
            a.remove(white_line)
        a = [''.join(line) for line in (zip(*a))]
        if i == 0:
            w = h - loop

    return a


def main():
    h, w = map(int, input().split())
    a = [input() for _ in range(h)]
    for i in answer(h, w, a):
        print(i)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

def main():

    H,W = map(int,input().split())
    A = [[0 if s == "." else 1 for s in list(input())] for _ in range(H)]

    for i in reversed(range(H)):
        if sum(A[i]) == 0:
            A.pop(i)

    A = np.array(A).T.tolist()
    for i in reversed(range(W)):
        if sum(A[i]) == 0:
            A.pop(i)
    A = np.array(A).T.tolist()

    for i in range(len(A)):
        print("".join(["." if i == 0 else "

main()

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
h,w = ma()
t="."*w
ls=[]
for i in range(h):
    s=input()
    if s!=t:
        ls.append(s)

l = len(ls)
t="."*l
ans = [[] for i in range(l)]
for i in range(w):
    f=False
    for j in range(l):
        if ls[j][i]=="
            f=True
    if f:
        for j in range(l):
            ans[j].append(ls[j][i])
for a in ans:
    print("".join(a))

Solution (Python):
h, w = map(int, input().split())
tizu = [input() for _ in range(h)]
h_s = [False for _ in range(h)]
w_s = [False for _ in range(w)]
for i in range(h):
  for j in range(w):
    if tizu[i][j] == "
      h_s[i] = True
      w_s[j] = True

for i in range(h):
  if not h_s[i]:
    continue
  row = ""
  for j in range(w):
    if w_s[j]:
      row += tizu[i][j]
  print(row)

Solution (Python):
h,w = map(int,input().split())
a = []
hh = 0
for _ in range(h):
  x = [xx for xx in input()]
  if x.count("
    a.append(x)
    hh += 1
b = []

count = 0
if hh > 1:
  wlist = []
  for i in range(w):
    for j in range(hh):
      b.append(a[j][i])
    if b.count("
      wlist.append(i)
    b = []
  for k in wlist:
    for l in range(hh):
      a[l].pop(k-count)
    count += 1
  for m in range(len(a)):
    print("".join(a[m]))
else:
  a = list(*a)
  ans = [aa for aa in a if aa == "
  print("".join(ans))

Solution (Python):
H, W = map(int, input().split())
A = []
for i in range(H):
  S = input()
  f = 0
  for j in range(W):
    if S[j] == "
      f = 1
      break
  if f == 1:
    A.append(S)
H = len(A)
ANS = ["" for i in range(H)]
for j in range(W):
  f = 0
  for i in range(H):
    if A[i][j] == "
      f = 1
      break
  if f == 1:
    for i in range(H):
      ANS[i] += A[i][j]
for i in range(H):
  print(ANS[i])

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

L, side, ver = [], [], []

for i in range(H):
    a = list(input())
    L.append(a)

def check(n, inlist, outlist):
    """[summary]
    全て白マスの行を削除する
    転置行列を返すので列の判定にも対応可能
    Args:
        n ([type]): 配列サイズ
        inlist ([type]): 入力する二次元配列
        outlist ([type]): 出力する二次元配列

    Returns:
        [list]: 不要な要素を削除して転置して返す
    """    
    for i in range(n):
        if ('
            outlist.append(inlist[i])
    return list(map(list, zip(*outlist)))

side = check(H, L, side)
ver = check(len(side), side, ver)

for i in range(len(ver)):
    print(''.join(ver[i]))

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

L, side, ver = [], [], []

for i in range(H):
    a = list(input())
    L.append(a)

for i in range(H):
    if ('
        side.append(L[i])

side = list(map(list, zip(*side)))

for i in range(len(side)):
    if ('
        ver.append(side[i])

ver = list(map(list, zip(*ver)))

for i in range(len(ver)):
    print(''.join(ver[i]))

Solution (Python):
import copy
h,w = map(int,input().split())
a = [input() for  i in range(h)]
index = 1
ans = copy.copy(a)
for i in range(h):
    bool = True
    for j in range(w):
        if a[i][j] == '
            bool = False
    if bool:
        index -= 1
        del ans[index + i]
ans_1 = copy.copy(ans)
key = 1
for i in range(w):
    bool = True
    for j in range(h - (1 - index)):
        if ans[j][i] == '
            bool = False
    if bool:
        key -= 1
        for k in range(h - (1 - index)):
            ans_1[k] = ans_1[k][:(i + key)] + ans_1[k][(i + key + 1):]
for i in range(len(ans_1)):
    print(ans_1[i])

Solution (Python):
h, w = map(int, input().split())
a = [''] * 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 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()

Solution (Python):
h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, h)]
list_tmp = []
for i in range(0, h):
    for j in range(0, w):
        if list_a[i][j] == '
            list_tmp.append(list(list_a[i]))
            break

list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, len(list_tmp_t)):
    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

list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))

Solution (Python):
import numpy as np

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

for i in range(h):
    if np.count_nonzero(a[i] == '
        a[i] = 'x'
for i in range(w):
    if np.count_nonzero(a[:, i] == '
        a[:, i] = 'x'

for i in range(h):
    if res := ''.join(filter(lambda x: x != 'x', a[i])):
        print(res)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

h, w = map(int, input().split())
graph = []
for _ in range(h):
    r = input().strip()
    if set(r) == {'.'}:
        continue
    graph.append(r)

transpose_graph = [[0] * len(graph) for _ in range(w)]
for i in range(len(graph)):
    for j in range(w):
        transpose_graph[j][i] = graph[i][j]

graph = []
for i in range(w):
    if set(transpose_graph[i]) == {'.'}:
        continue
    graph.append(transpose_graph[i])

transpose_graph = [[0] * len(graph) for _ in range(len(graph[0]))]
for i in range(len(graph)):
    for j in range(len(graph[0])):
        transpose_graph[j][i] = graph[i][j]

for r in transpose_graph:
    print(''.join(r))

Solution (Python):
h,w=map(int,input().split())
a=[input() for i in range(h)]
row=[False]*h
col=[False]*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):
  for j in range(w):
    if row[i]==True and col[j]==True:
      print(a[i][j],end="")
  if row[i]:
    print()

Solution (Python):
H, W = map(int, input().split())
a_list = [list(input()) for _ in range(H)]
dot_cnt = [sum([a == '.' for a in a_col]) for a_col in a_list]
exist_idx = [i for i, num in enumerate(dot_cnt) if num != W]
st = set(range(W))
for i in exist_idx:
    dot_idx = [i for i, a in enumerate(a_list[i]) if a == '.']
    st = st & set(dot_idx)
for i in exist_idx:
    print(''.join([a for i, a in enumerate(a_list[i]) if i not in st]))

Solution (Python):


import collections
import itertools

def main():
    h, w = input_list()
    maze = [list(input()) for _ in range(h)]
    ans = []
    blacks = [False] * w
    for m in maze:
        for i, v in enumerate(m):
            if v == "
                blacks[i] = True
    for m in maze:
        f = True
        new_row = []
        for i, b in enumerate(blacks):
            if b:
                new_row.append(m[i])
        for i, v in enumerate(new_row):
            if v == "
                f = False
                break
        if f:
            continue
        ans.append(new_row)
    for a in ans:
        print("".join(a))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    H, W = LI()
    a = []
    excrow = set()
    exccol = set()
    for _ in range(H):
        a.append(S())
    for row in range(H):
        all_white = True
        for c in a[row]:
            if c == '
                all_white = False
                break
        if all_white:
            excrow.add(row)

    for col in range(W):
        all_white = True
        for r in range(H):
            if a[r][col] == '
                all_white = False
                break
        if all_white:
            exccol.add(col)

    newA = []
    for row in range(H):
        if row in excrow:
            continue
        newA.append(a[row])

    newnewA = []
    for row in range(len(newA)):
        string = ''
        for col in range(W):
            if col in exccol:
                continue
            string += newA[row][col]
        newnewA.append(string)
    print('\n'.join(newnewA))


main()

Solution (Python):
import sys

input = sys.stdin.readline
H, W = map(int, input().split())
grid = []
for _ in range(H):
    grid.append(list(input().strip()))

h_set = set()
for i in range(H):
    flag = True
    for j in range(W):
        if grid[i][j] == "
            flag = False
            break
    if flag:
        h_set.add(i)

w_set = set()
for j in range(W):
    flag = True
    for i in range(H):
        if grid[i][j] == "
            flag = False
            break
    if flag:
        w_set.add(j)

for i in range(H):
    if i in h_set:
        continue
    for j in range(W):
        if j in w_set:
            continue
        print(grid[i][j], end="")
    print("")

Solution (Python):
h, w = map(int, input().split())
a = []
for i in range(h):
  s = input()
  if s.count('
    a.append(s)

b = [0 for i in range(w)]
for gl in a:
  for i in range(w):
    if gl[i] == '
      b[i] += 1
for gl in a:
  v = ''
  for i in range(w):
    if b[i] > 0:
      v += gl[i]
  print (v)

Solution (Python):
import numpy as np

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

maze = []
for i in range(h):
    row = list(input())
    if "
        maze.append(row)
        
maze = np.array(maze)
maze = np.rot90(maze)

ans = []
for row in maze:
    if "
        ans.append(row)
        
ans = np.rot90(ans, -1)

for r in ans:
    print("".join(r))

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

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

Solution (Python):
h, w = map(int, input().split())
a = [''] * 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 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()

Solution (Python):
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
a = [x for x in a if '
aT = list(zip(*a))
aT = [x for x in aT if '
a = list(zip(*aT))
for i in a:
    print(''.join(i))

Solution (Python):
import numpy as np
H, W = map(int, input().split())
mat = []
for _ in range(H):
    a = list(input())
    ca = [0 if i == '.' else 1 for i in a]
    mat.append(ca)
amat = np.array(mat)

mask1 = []
for i in range(H):
    if np.sum(amat[i]) != 0:
        mask1.append(i)
amat1 = amat[mask1]

mask2 = []
for i in range(W):
    if np.sum(amat1[:,i]) != 0:
        mask2.append(i)
amat2 = amat1[:,mask2]

ans = []
for i in range(amat2.shape[0]):
    temp = ''
    for s in amat2[i]:
        if s == 1:
            temp += '
        else:
            temp += '.'
    ans.append(temp)
print(*ans, sep='\n')

Solution (Python):
H,W=map(int,input().split())
delh=[]
delw=[]

sq=[list(input()) for i in range(H)]

for j in range(H):
    temp=0
    for k in range(W):
        if sq[j][k]==".":
            temp+=1
    if temp==W:
        delh.append(j)

for l in range(W):
    temp=0
    for m in range(H):
        if sq[m][l]==".":
            temp+=1
    if temp==H:
        delw.append(l)

for n in range(len(delh)):
    del sq[delh[n]]
    for q in range(len(delh)):
        delh[q]-=1
H-=len(delh)

for o in range(len(delw)):
    for p in range(H):
        del sq[p][delw[o]]
    for r in range(len(delw)):
        delw[r]-=1
        
for s in range(H):
    print("".join(sq[s]))

Solution (Python):
h,w=map(int, input().split())
alist=['']*h
for i in range(h):
  alist[i]=input()
hlist=[]
wlist=[]
for i in range(h):
  flag=False
  for j in range(w):
    if alist[i][j]=='
      flag=True
  if flag:
    hlist.append(i)
for i in range(w):
  flag=False
  for j in range(h):
    if alist[j][i]=='
      flag=True
  if flag:
    wlist.append(i)
for i in hlist:
  ans=[]
  for j in wlist:
    ans.append(alist[i][j])
  print(''.join(ans))

Solution (Python):
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]
b=[]
for i in range(H):
    if '
        b.append(a[i])
c=[[] for _ in range(len(b))]
for j in range(W):
    flag=False
    for i in range(len(b)):
        if b[i][j]=='
            flag=True
    if flag:
        for i in range(len(b)):
            c[i].append(b[i][j])
for i in range(len(c)):
    for j in range(len(c[i])):
        print(c[i][j],end='')
    print()

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    h,w = i_map()
    l = []
    for i in range(h):
        a = input()
        if "
            l.append(a)
    l = [list(i) for i in zip(*l)]
    ans = []

    for i in l:
        if "
            ans.append(i)

    ans = [i for i in zip(*ans)]
    for i in ans:
        print("".join(i))





if __name__=="__main__":
    main()

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

for i in range(h):
    r = list(input())
    if '
        a.append(r)

box = [0] * w

for colum in range(w):
    if all(row[colum] == '.' for row in a) :
        box[colum] = 1

for j in range(w):
    if box[j] == 1:
        for row in a:
            row[j] = ''

for row in a:
    print(''.join(map(str, row)))

Solution (Python):
import sys
import copy
import math
import itertools
import numpy as np

H,W = [int(c) for c in input().split()]
a = np.array([list(input()) for c in range(H)])
b = copy.deepcopy(a)
Hc=[]
Wc=[]
for i in range(H):
    if np.count_nonzero(a[i,:] == ".") == W:
        Hc.append(i)

for i in range(W):
    if np.count_nonzero(a[:,i] == ".") == H:
        Wc.append(i)

a = np.delete(a,Hc,0)
a = np.delete(a,Wc,1)

for i in range(len(a)):
    s = ""
    for j in range(len(a[i])):
        s+=a[i][j]
    print(s)

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

g = []
same = ['.'] * w
for _ in range(h):
    a = list(input())
    if a == same:
        continue
    else:
        g.append(a)

l = []
for j in range(w):
    for row in g:
        if row[j] == '
            break
    else:
        l.append(j)

for i in range(len(g)):
    g[i] = [g[i][j] for j in range(w) if j not in l]

for i in g:
    print(''.join(i))

Solution (Python):
import numpy as np
H, W = map(int, input().split())
x = [list(map(str, list(input()))) for l in range(H)]

y = []
for i in range(H):
    if set(x[i]) != {"."}:
        y.append(x[i])

z = np.array(y)
zz = np.rot90(z)
zzz = zz.tolist()

ans = []
for i in range(W):
    if set(zzz[i]) != {"."}:
        ans.append(zzz[i])

a = np.array(ans)
b = np.rot90(a, -1)
c = b.tolist()

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

Solution (Python):
h, w = map(int, input().split())
aa = [list(input()) for i in range(h)]
bb = list(zip(*aa))

cc =  [b for b in bb if any(x == '
dd =list(zip(*cc))
ee = [d for d in dd if any(x == '


for i in range(len(ee)):
    print(''.join(ee[i]))

Solution (Python):
H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if "
        a.append(s)

d = [i for i in range(W)]

for i in range(W):
    f = 0
    for j in a:
        if j[i] == "
            f = 1
            break
    if f == 0:
        d.remove(i)

ans = [""] * H
for i in range(len(a)):
    for j in d:
        ans[i] += a[i][j]
    print(ans[i])

Solution (Python):
H, W = [int(x) for x in input().split()]
A = [input().strip() for _ in range(H)]

B = []
for i in range(H):
    if "
        B.append(A[i])

ans = []
for j in range(W):
    for i in range(len(B)):
        if "
            ans.append(j)
            break

for i in range(len(B)):
    for j in ans:
        print(B[i][j], end="")
    print()

Solution (Python):
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
resH = [True] * H
resW = [True] * W

for h in range(H):
    judge = False
    for w in range(W):
        if a[h][w] == "
            judge = True
    resH[h] = judge

for w in range(W):
    judge = False
    for h in range(H):
        if a[h][w] == "
            judge = True
    resW[w] = judge

for h, row in enumerate(a):
    tmp = []
    for w, element in enumerate(row):
        if resH[h] and resW[w]:
            tmp.append(element)
    if tmp:
        print(*tmp, sep="")

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

B = []
for row in A:
    if all(a=='.' for a in row): continue
    B.append(row)

C = ['' for _ in range(len(B))]
for col in zip(*B):
    if all(a=='.' for a in col): continue
    for i,a in enumerate(col):
        C[i] += a
for row in C:
    print(row)

Solution (Python):
H,W=list(map(int, input().split()))
A=[list(input()) for _ in range(H)]
S={i for i in range(H)}
T={j for j in range(W)}
for i in range(H):
  if set(A[i])=={'.'}:
    S-={i}
for j in range(W):
  for i in range(H):
    if A[i][j]=='
      break
  else:
    T-={j}
S=sorted(list(S))
T=sorted(list(T))
for i in S:
  ans=[]
  for j in T:
    ans.append(A[i][j])
  print(''.join(ans))

Solution (Python):
import numpy as np
H, W = map(int, input().split())
a = ['']*H
for i in range(H):
  a[i] = input()

h_flag = [0]*H
w_flag = [0]*W
for iHeight in range(H):
  for jWidth in range(W):
    if a[iHeight][jWidth] == '
      h_flag[iHeight] = 1
      w_flag[jWidth] = 1

for iHeight in range(H):
  if h_flag[iHeight] == 1:
    for jWidth in range(W):
      if w_flag[jWidth] == 1:
        print(a[iHeight][jWidth], end='')
    print()

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

H,W = mint()
A = [input() for _ in range(H)]
I = []
J = []

for i in range(H):
    for j in range(W):
        if A[i][j]=='
            I.append(i)
            break

for j in range(W):
    for i in range(H):
        if A[i][j]=='
            J.append(j)
            break

            
S = [[0]*len(J) for _ in range(len(I))]

for i in range(len(I)):
    for j in range(len(J)):
        print(A[I[i]][J[j]],end='')
    print('')

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

fin=[]
num=[0]*w

for l in lis:
  if l.count(".") != w:
    fin.append(l)
  for i in range(w):
    if l[i]==".":
      num[i]+=1

for f in fin:
  ans=[]
  for i in range(len(num)):
    if num[i]!=h:
      ans.append(f[i])
  print(*ans,sep='')

Solution (Python):
import sys
h,w = map(int,input().split())
square = [input() for i in range(h)]
y = "." * w
ans = []
index = []
for s in square:
  if s != y:
    ans.append(s)
h = len(ans)
for i in range(w):
  dot = 0
  for a in ans:
    if a[i] == ".":
      dot += 1
  if dot == h:
    index.append(i)

if len(index) == 0:
  for a in ans:
    print(a)
else:
  for a in ans:
    f = []
    for i,l in enumerate(a):
      if i not in index:
        f.append(l)
    print("".join(f))

Solution (Python):
h,w=map(int,input().split())
a=[]
data=[0]*w
for i in range(h):
  a_=input()
  if a_!='.'*w:
    a.append(a_)
    for j in range(w):
      if a_[j]=='.':
        data[j]+=1
n=len(a)
for i in range(n):
  ans=[]
  for j in range(w):
    if data[j]!=n:
      ans.append(a[i][j])
  print(*ans,sep='')

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

for i in range(H):
    for j in range(W):
        if A[i][j] == "
            break
    
    else:
        for l in range(W):
            A[i][l] = "x"


for i in range(W):
    for j in range(H):
        if A[j][i] == "
            break
    else:
        for l in range(H):
            A[l][i] = "x"
for i in range(H):
    x_cnt = 0
    for j in range(W):
        if A[i][j] != "x":
            print(A[i][j], end="")
        else:
            x_cnt += 1

    if x_cnt < W:
        print()
    else:
        pass

Solution (Python):
H,W = map(int,input().split())
masu = [list(input())for i in range(H)]
excludeC = []
excludeR = []
for i in range(H):
    if masu[i].count('.') == W:
        excludeR.append(i)

for i in range(W):
    isExclude = True
    for j in range(H):
      if masu[j][i] == '
            isExclude = False
            break
    if isExclude:
        excludeC.append(i)

for i in range(H):
    if i in excludeR:
        continue
    for j in range(W):
        if j in excludeC:
            continue
        print(masu[i][j],end='')
    print('')

Solution (Python):
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
x = list()
y = list()
for i in range(h):
    if "
        x.append(i)
for j in range(w):
    cnt = 0
    for k in range(h):
        if a[k][j] == "
            y.append(j)
            break
for p in x:
    z = ""
    for q in y:
        z += a[p][q]
    print(z)

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

h_set = set()
w_set = set()
B = [input() for i in range(H)]
for i in range(H):
  for j in range(W):
    if B[i][j] == '
      w_set.add(j)
      h_set.add(i)
      
for i in range(H):
  if i in h_set:
    t = ""
    for j in range(W):
      if j in w_set:
        t += B[i][j]
    print(t)

Solution (Python):
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
x = list()
y = list()
for i in range(h):
    if "
        x.append(i)
for j in range(w):
    cnt = 0
    for k in range(h):
        if a[k][j] == "
            y.append(j)
            break
for p in x:
    z = ""
    for q in y:
        z += a[p][q]
    print(z)

Solution (Python):
h,w = map(int, input().split())
a = [str(input()) for _ in range(h)]
b = []
for i in range(h):
    if a[i] != '.'*w:
        b.append(a[i])
c = []
for h in range(w):
    num = 0
    for j in b:
        if j[h] == '.':
            num += 1
    if num == len(b):
        c.append(h)
for k in b:
    word = ""
    for l in range(w):
        if l not in c:
            word += k[l]
    print(word)

Solution (Python):

import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    H, W = map(int, input().split())
    a = []
    white = '.' * W
    for i in range(H):
        s = input()
        if s == white:
            pass
        else:
            a.append(s)

    black = []
    for w in range(W):
        for h in range(len(a)):
            if a[h][w] == '
                black.append(w)

    black = sorted(list(set(black)))
    for h in range(len(a)):
        t = ''
        for b in black:
            t += a[h][b]
        print(t)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
H, W = map(int, input().split())
A = []
for _ in range(H):
    a = list(input())
    if a.count("
        A.append(a)

H = len(A)
if H == 1:
    A = list(itertools.chain.from_iterable(A))
    cnt = []
    for ans in A:
        if ans == "
            cnt.append(ans)
    print("".join(cnt))
else:
    L = []
    for w in range(W):
        l = []
        for h in range(H):
            if A[h][w] == "
                l = []
                break
            l.append(w)
        if len(l) != 0:
            L.append(l[0])

    dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
    for ans in A:
        ans = dellist(ans, L)
        print("".join(ans))

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

ignore = "".join(["." for _ in range(W)])

A = list(filter(lambda x : x != ignore, [input() for _ in range(H)]))
H = len(A)
B = [[] for _ in range(H)]

for w in range(W):
    if list(filter(lambda x: x[w] == "
        for i in range(H):
            B[i].append(A[i][w])

for h in range(H):
    print("".join(B[h]))

Solution (Python):
h, w = map(int, input().split())
a = [input() for i in range(h)]
vdel = []
sdel = []

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

for i in range(w):
    cnt = 0
    for j in range(h):
        if a[j][i] == '.':
            cnt += 1
    if cnt == h:
        vdel.append(i)
i = 0
lens = len(sdel)-1
h -= lens+1
while i <= lens:
    del a[sdel[lens]]
    lens -= 1

for i in range(h):
    tmp = ''
    for j in range(w):
        if j not in vdel:
            tmp += a[i][j]
    print(tmp)

Solution (Python):
h, w = map(int, input().split())
A = [input() for i in range(h)]
row = [False] * h
col = [False] * 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()

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

a2=[]
a3=[]
for i in range(h):
  if "
    a2.append(a[i])
a2=np.array(a2)
a2=a2.T

for i in range(len(a2)):
  if "
    a3.append(a2[i])
a3=np.array(a3)
a3=a3.T
for i in range(len(a3)):
  print("".join(a3[i]))

Solution (Python):
h, w = map(int, input().split())
grid = [input() for _ in range(h)]

def check_row(grid):
    for i in range(len(grid)):
        if "
            return i
    return -1

def check_col(grid):
    grid_inv = []
    for i in range(len(grid[0])):
        grid_inv.append("".join(row[i] for row in grid))
    return check_row(grid_inv)

while True:
    if check_row(grid) != -1:
        del grid[check_row(grid)]
        continue
    elif check_col(grid) != -1:
        d = check_col(grid)
        for i in range(len(grid)):
            grid[i] = grid[i][:d] + grid[i][d+1:]
    else:
        break

for g in grid:
    print(g)