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):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 pf(s): return print(s, flush=True)


def main():
    H, W = LI()
    A = []
    [A.append(S()) for i in range(H)]

    
    rm_idx = []
    for idx, a in enumerate(A):
        if '
            rm_idx.append(idx)

    count = 0
    for idx, i in enumerate(rm_idx):
        del A[i-count]
        count += 1

    
    rm_idx = []
    for w in range(W):
        if all(a[w] == '.' for a in A):
            rm_idx.append(w)

    count = 0
    for idx, i in enumerate(rm_idx):
        A = [a[:i-count] + a[i-count+1:] for a in A]
        count += 1

    for a in A:
        print(''.join(a))


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    H, W = li_input()
    S = [input() for _ in range(H)]

    i = 0
    while i < len(S):
        if S[i].count("
            S = S[:i] + S[i+1:]
        else:
            i += 1

    i = 0
    while i < len(S[0]):
        is_blank = True
        for j in range(len(S)):
            if S[j][i] == "
                is_blank = False
                break
        
        if is_blank:
            for j in range(len(S)):
                S[j] = S[j][:i] + S[j][i+1:]
        else:
            i += 1

    for s in S:
        print(s)


main()

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

mas = []

for i in range(H):
    a = input()
    if a == '.'*W:
        continue
    mas.append(a)

delFlg = False
delcache = []
for i in range(W):
    delFlg = True
    for x in mas:
        if x[i] != '.':
            delFlg = False
            break
    if delFlg:
        delcache.append(i)
delcache.sort(reverse=True)

for i in delcache:
    for j,x in enumerate(mas):
        mas[j] = x[0:i] + x[i+1:]

for x in mas:
    print(x)

Solution (Python):


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

    a = [ai for ai in a if any(ais == '

    i = 0
    while i < len(a[0]):
        if all(ai[i] == '.' for ai in a):
            for ai in a:
                del ai[i]
        else:
            i += 1
            continue

    for ai in a:
        print(''.join(ai))


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

H,W = map(int, input().split())
res = []
for i in range(H):
    res.append(list(map(list,input().split())))

initial_map = []
for i in res:
    row = [f for f in i]
    initial_map.append(row[0])

remove_list = []
for i in range(H):
    if '
        remove_list.append(i)

count = 0
for i in remove_list:
    initial_map.pop(i-count)
    count += 1

remove_list = []

initial_map_t = np.array(initial_map).T.tolist()

for i in range(W):
    if '
        remove_list.append(i)

count = 0
for i in remove_list:
    initial_map_t.pop(i-count)
    count += 1

res = np.array(initial_map_t).T.tolist()

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

Solution (Python):
def main() -> None:
    h, w = map(int, input().split())
    a = []
    for _ in range(h):
        a.append(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()


if __name__ == '__main__':
    main()

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

A = []
for i in range(h):
    a = list(input())
    if '
        A.append(a)
        
for j in range(w - 1, -1, -1):
    for i in range(len(A)):
        if A[i][j] == '
            break
    else:
        for k in range(len(A)):
            del A[k][j]
            
for i in range(len(A)):
    print(''.join(A[i]))

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

e = [""] * h
for i in range(h):
    e[i] = input()
    

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



for i in range(h):
    for j in range(w):
        if e[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(e[i][j], end = '')
		print()

Solution (Python):
int_h, int_w = map(int, input().split())

masu = list()

for i in range(int_h):
    masu.append(list(input()))

conv = list()
for x in list(map(list, zip(*masu))):
    if "
        conv.append(x)

result = list()

for y in list(map(list, zip(*conv))):
    if "
        result.append(y)

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

Solution (Python):
def main():
 h, w = map(int, input().split())
 a = [input() for _ in range(h)]
 na = []
 l = [0] * (w + 1)
 for i in range(h):
  if not("
   pass
  else:
   na += [a[i]]
   for j in range(w):
    if a[i][j] == "
     l[j] += 1
 for i in na:
  for j in range(w):
   if l[j] != 0:
    print(i[j], end="")
  print("")
main()

Solution (Python):
def func(A,H,W):
    H_del=[]
    W_del=[]
    for h in range(H):
        if A[h][0]=='.':
            g=1
            for w in range(1,W):
                if A[h][w]!='.':
                    g=0
                    break
            if g==1:
                H_del.append(h)
    for w in range(W):
        if A[0][w]=='.':
            g=1
            for h in range(1,H):
                if A[h][w]!='.':
                    g=0
                    break
            if g==1:
                W_del.append(w)
    return H_del,W_del

def show(A,H_del,W_del,H,W):
    for h in range(H):
        if h in H_del:
            continue
        for w in range(W):
            if w in W_del:
                continue
            print(A[h][w],end='')
        print('')
H,W=map(int,input().split())
A=[]
H_del=[]
W_del=[]
for i in range(H):
    A.append(list(input()))
H_del,W_del=func(A,H,W)
show(A,H_del,W_del,H,W)

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):
    char=''
    if row[i]:
        for j in range(w):
            if col[j]:
                char+=a[i][j]
            else:
                continue
    else:
        continue
    print(char)

Solution (Python):
H, W = map(int, input().split())
A = [[0 if x == "." else 1 for x in input()] for _ in range(H)]
A = [a for a in A if sum(a) != 0]
W_cut = [w for w in range(W) if sum([a[w] for a in A]) == 0]
for a in A:
    line = ""
    for w in range(W):
        if w in W_cut:
            continue
        line += "." if a[w] == 0 else "
    print(line)

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


for i in range(H):
    for j in range(W):
        if a[i][j] == '.':
            a[i][j] = 1
        elif a[i][j] == '
            a[i][j] = 0
        else:
            pass
a = np.array(a)
v = []
h = []
for i in range(H):
    if np.sum(a[i,:]) == W:
        h.append(i)
for j in range(W):
    if np.sum(a[:,j]) == H:
        v.append(j)

a_del = np.delete(np.delete(a, v, 1), h, 0)
a_del = list(a_del)

for i in range(len(a_del)):
    for j in range(len(a_del[i])):
        if a_del[i][j] == 1:
            print('.', end='')
        elif a_del[i][j] == 0:
            print('
    print('')

Solution (Python):
h,w = map(int,input().split())
mx = []
for i in range(h):
    mx.append(list(map(str, input().split())))
for i in range(h-1,-1,-1):
    if not '
        del mx[i]
l = []
for i in range(w):
    for j in range(len(mx)):
        if mx[j][0][i]=='
            break
        if j==len(mx)-1:
            l.append(i)
if l:
    for i in range(1,len(l)+1):
        for j in range(len(mx)):
            if l[-i]==len(mx[j][0])-1:
                mx[j][0]=mx[j][0][:l[-i]]
            else:
                mx[j][0]=mx[j][0][:l[-i]]+mx[j][0][l[-i]+1:]
for m in mx:
    print(m[0])

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

l = []

for i in range(H):
    l.append(input())

y = [False] * H
x = [False] * W

for i in range(H):
    flg = True
    for j in range(W):
        if l[i][j] != '.':
            flg = False
            break
    if flg:
        y[i] = True

for i in range(W):
    flg = True
    for j in range(H):
        if l[j][i] != '.':
            flg = False
            break
    if flg:
        x[i] = True

for i in range(H):
    if y[i]:
        continue
    for j in range(W):
        if x[j]:
            continue
        print(l[i][j], end='')
    print()

Solution (Python):
import sys

def main():
  input = sys.stdin.readline
  H, W = map(int, input().split())
  A = [str(input().strip()) for _ in range(H)]
  B = []
  for i in range(len(A)):
    if A[i] != '.'*W:
      B.append([str(c) for c in A[i]])

  C = [[0 for _ in range(len(B))] for _ in range(len(B[0]))]
  for i in range(len(B)):
    for j in range(len(B[0])):
      C[j][i] = B[i][j]
  
  D = []
  for i in range(len(C)):
    if ''.join(C[i]) != '.' * len(C[0]):
      D.append([str(c) for c in C[i]])
  
  E = [[0 for _ in range(len(D))] for _ in range(len(D[0]))]
  for i in range(len(D)):
    for j in range(len(D[0])):
      E[j][i] = D[i][j]

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


if __name__ == '__main__':
  main()

Solution (Python):

H, W = map(int, input().split())
a = []
for _ in range(H):
    i = list(input())
    if '
        a.append(i)
ans = zip(*[i for i in zip(*a) if '
for s in ans:
    print(*s, sep='')

Solution (Python):
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
for i in range(h):
    if set(a[h-i-1]) == {'.'}:
        del(a[h-i-1])
for i in range(w):
    if set([j[w-i-1] for j in a]) == {"."}:
        for j in a:
            del(j[w-i-1])
for i in a:
    print(''.join(i))

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

Solution (Python):
h,w=[int(i) for i in input().split()]
a=[]
row=[]
col=[]
for i in range(h):
    a.append(input())
for i in range(h):
    row.append(False)
for i in range(w):
    col.append(False)

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("\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 = [input() for _ in range(h)]
a = [x for x in a if not all([i == '.' for i in x])]
b = [[x[i] for x in a] for i in range(w)]
b = ["".join(x) for x in b]
b = [x for x in b if not all([i == '.' for i in x])]
c = [[x[i] for x in b] for i in range(len(b[0]))]
c = ["".join(x) for x in c]
print(*c, sep="\n")

Solution (Python):
import sys
def こたえ():
    H,W = [int(_) for _ in input().split()]
    aM = [_.rstrip() for _ in sys.stdin.readlines()]
    aH = [True]*H
    aW = [True]*W
    for i in range(H):
        bH = True
        for j in range(W):
            bW = True if aM[i][j] == "." else False
            if bH and not bW:
                bH = False
            if aW[j] and  not bW :
                aW[j]=False
        aH[i] = bH
    for i in range(H):
        if not aH[i]:
            for j in range(W):
                if not aW[j]:
                    sys.stdout.write(aM[i][j])
            sys.stdout.write("\n")
こたえ()

Solution (Python):

h,w = list(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())
HW = [input() for _ in range(H)]
HW = [''.join(hw) for hw in zip(*HW) if hw.count('
HW = [''.join(hw) for hw in zip(*HW) if hw.count('
print('\n'.join(HW))

Solution (Python):
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B=[]
C=[]
for i in range(h):
    if (set(A[i]))!={'.'}:
        B.append(A[i])
B=list(map(list, zip(*B)))
h_=len(B)
for i in range(h_):
    if set(B[i])!={'.'}:
        C.append(B[i])
C=list(map(list, zip(*C)))
h__=len(C)
for i in range(h__):
    print(''.join(map(str,C[i])))

Solution (Python):
class Solver(object):
    def __init__(self):
        self.h, self.w = list(map(int, input().split(" ")))
        self.grid = [[] for _ in range(self.h)]  
        for row in range(self.h):
            for value in input():
                self.grid[row].append(value)

    def solve(self):
        for row in range(self.h):
            for column in range(self.w):
                if self.grid[row][column] == ".":
                    self.check_and_delete(row, column)
        self.print_grid()

    def check_and_delete(self, row, column):
        
        delete = True
        for c in range(self.w):
            if self.grid[row][c] is not None:
                if self.grid[row][c] == "
                    delete = False
        if delete:
            for c in range(self.w):
                self.grid[row][c] = None

        
        delete = True
        for r in range(self.h):
            if self.grid[r][column] is not None:
                if self.grid[r][column] == "
                    delete = False
        if delete:
            for r in range(self.h):
                self.grid[r][column] = None
    
    def print_grid(self):
        for row in self.grid:
            printed = False
            for column in row:
                if column is not None:
                    printed = True
                    print(column, end="")
            if printed:
                print()


if __name__ == "__main__":
    s = Solver()
    s.solve()

Solution (Python):
def del_row(lines):
    if not lines:
        return
    erasable = []
    for idx, line in enumerate(lines):
        if all([c == '.' for c in line]):
            erasable.append(idx)
    for idx in erasable[::-1]:
        del lines[idx]


def del_col(lines):
    if not lines:
        return
    erasable = []
    for idx in range(len(lines[0])):
        col = [lines[i][idx] for i in range(len(lines))]
        if all([c == '.' for c in col]):
            erasable.append(idx)
    for idx in erasable[::-1]:
        for i in range(len(lines)):
            del lines[i][idx]


lines = []
H, W = [int(x) for x in input().split()]
for i in range(H):
    lines.append(list(input()))

del_row(lines)
del_col(lines)
for line in lines:
    print(''.join(line))

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

cells = []
for h in range(H):
    s = input()
    if s != '.' * W:
        cells.append(s)

new_cells = [''] * len(cells)
for w in range(W):
    delete = True
    for c in cells:
        if c[w] == '
            delete = False
    if not delete:
        for h, c in enumerate(cells):
            new_cells[h] += cells[h][w]

for c in new_cells:
    print(c)

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

A = []
for i in range(h):
    s = list(input())
    if '
        A.append(s)

h2 = len(A)
for j in range(w - 1, -1, -1):
    for i in range(h2):
        if A[i][j] == '
            break
        elif i == h2 - 1:
            for k in range(h2):
                del A[k][j]
            
for a in A:
    print(''.join(a))

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

A = []
for i in range(h):
    s = list(input())
    if '
        A.append(s)
        
B = [[0] * w for i in range(len(A))]
for i in range(len(A)):
    for j in range(w):
        if A[i][j] == '
            B[i][j] += 1
            
C = [0] * w
for i in range(len(A)):
    for j in range(w):
        C[j] += B[i][j]
        
D = [[] for i in range(len(A))]
for i in range(len(A)):
    for j in range(w):
        if C[j] != 0:
            D[i].append(A[i][j])
            
for i in range(len(A)):
    print(''.join(D[i]))

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

aa = [input() for _ in range(h)]
aa_rm=[]
target_row=[]
for row,a in enumerate(aa):
    if a.count('.') < w:
        target_row.append(row)

target_col=[]
for iw in range(w):
    col=[]
    for ih in range(h):
        col.append(aa[ih][iw])
    
    if col.count('.') < h:
        target_col.append(iw)

ans =[]
for row in target_row:
    s=""
    for col in target_col:
        s+=aa[row][col]
    ans.append(s)
for a in ans:
    print(a)

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

r = set()
for i in range(h):
    ok = True
    for j in range(w):
        if a[i][j] == '
            ok = False
            break
    else:
        if ok:
            r.add(i)
c = set()
for j in range(w):
    ok = True
    for i in range(h):
        if a[i][j] == '
            ok = False
            break
    else:
        if ok:
            c.add(j)
for i in range(h):
    tmp = ''
    if i in r:
        continue
    for j in range(w):
        if j in c:
            continue
        tmp += a[i][j]
    print(tmp)

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

b = []
for i in range(h):
    cnt = 0
    for j in range(w):
        if a[i][j] == '.':
            cnt += 1
            
    if cnt != w:
        b.append(a[i])

c = ['']*len(b) 
for i in range(len(b[0])):
    cnt = 0
    for j in range(len(b)):
        if b[j][i] == '.':
            cnt += 1
    
    if cnt != len(b):
        for j in range(len(b)):
            c[j] += b[j][i]

for i in range(len(c)):
    print(c[i])

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

arr_all = []
arr_del = []
for i in range(h):
    arr_w = input()
    if list(set(arr_w)) == ["."]:
        continue
    else:
        arr_all.append(arr_w)
        arr_del.append([])


d = []

for i in range(w):
    for j in range(len(arr_all)):
        if arr_all[j][i] == ".":
            if j == w - 1:
                break
            else:
                continue
        else:
            d.append(i)
            break

for j in range(len(arr_all)):
    for i in d:
        arr_del[j] += arr_all[j][i]


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

Solution (Python):
h,w = (int(i) for i in 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):
import numpy as np
import copy

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

array = np.zeros((h,w))
for n, i in enumerate(lst):
    for m, j in enumerate(i):
        array[n][m] = 1if j == '

while True:
    origin = copy.deepcopy(array)
    array = array[:, array.sum(axis=0) > 0]
    array = array[array.sum(axis=1)>0, :]
    if array.shape == origin.shape:
        break

for i in array:
    string = ''
    for j in i:
        string += '
    print(string)

Solution (Python):
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
a_h = [False]*H
a_w = [False]*W

for i in range(H):
  for j in range(W):
    if a[i][j] == '
      a_h[i] = True
      a_w[j] = True

for i in range(H):
  if a_h[i] == True:
    for j in range(W):
      if a_w[j] == True:
        print(a[i][j],end='')
    print()

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

tmp = []
for a in zip(*A):
  if(a.count("
    tmp.append("".join(a))
tmp2 = []
for t in zip(*tmp):
  if(t.count("
    tmp2.append("".join(t))
print("\n".join(tmp2))

Solution (Python):

def solve(h, w, a):
    rs = []
    for r in range(h):
        ok = True
        for c in range(w):
            if a[r][c] == "
                ok = False
                break
        if not ok:
            rs.append(r)
    cs = []
    for c in range(w):
        ok = True
        for r in range(h):
            if a[r][c] == "
                ok = False
                break
        if not ok:
            cs.append(c)
    res = "\n".join(map(lambda r: "".join(map(lambda c: a[r][c], cs)), rs))
    return res


h, w = map(int, raw_input().split())
a = []
for r in range(h):
    a.append(raw_input())




print solve(h, w, a)

Solution (Python):
h,w=map(int, input().split())
a=[""]*h
for i in range(h):
  a[i]=input()
row=[False]*h
column=[False]*w
for i in range(h):
  for j in range(w):
    if a[i][j]=="
      row[i]=True
      column[j]=True
for i in range(h):
  if row[i]:
    for j in range(w):
      if column[j]:
        print(a[i][j], end = "")
    print()

Solution (Python):
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
l = ["."]*w
while l in a:
  a.remove(l)
  
for j in range(w):
    s = 0
    for m in a:
        if m[j]=="
            s = 1
            break
    if s == 0:
        for m in a:
            m[j]=""
for i in a:
    print("".join(i))

Solution (Python):
H,W = map(int,input().split())
ahw = [strlist for strlist in [[s for s in input()] for i in range(H)] if "
tenti = []
for h in range(W):
   m =  [ah[h] for ah in ahw]
   if "
       tenti.append(m)
for ahwnum in range(len(ahw)):
    print("".join([num[ahwnum] for num in tenti]))

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

for i in range(h)[::-1]:
    if "
        del a[i]
        h -= 1

n = []
for j in range(w):
    m = ["".join(t[j] for t in a)]
    if "
        n += m

for k in range(h):
    print("".join(u[k] for u in n))

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


HW = ["".join(hw) for hw in zip(*HW) if hw.count("

HW = ["".join(hw) for hw in zip(*HW) if hw.count("
print("\n".join(HW))

Solution (Python):
H,W=map(int,input().split())
matrix=[list(map(str,input().split())) for i in range(H)]
count_delete_H=0
count_delete_W=0

for i in range(H):
  matrix[i-count_delete_H]=list(*matrix[i-count_delete_H])
  if(matrix[i-count_delete_H].count('
    del matrix[i-count_delete_H]
    count_delete_H+=1
    
matrix_t = [list(x) for x in zip(*matrix)]
for i in range(W):
  if(matrix_t[i-count_delete_W].count('
    del matrix_t[i-count_delete_W]
    count_delete_W+=1
    
matrix_tt = [list(x) for x in zip(*matrix_t)]
for i in range(H-count_delete_H):
  for j in range(W-count_delete_W):
    print(matrix_tt[i][j],end='')
  print('')

Solution (Python):
H,W=map(int,input().split())
matrix=[list(map(str,input().split())) for i in range(H)]
count_delete_H=0 
count_delete_W=0 

for i in range(H):
  matrix[i-count_delete_H]=list(*matrix[i-count_delete_H])
  
  if(matrix[i-count_delete_H].count('
    del matrix[i-count_delete_H]
    count_delete_H+=1
    
matrix_t = [list(x) for x in zip(*matrix)]
for i in range(W):
  
  if(matrix_t[i-count_delete_W].count('
    del matrix_t[i-count_delete_W]
    count_delete_W+=1
    
matrix_tt = [list(x) for x in zip(*matrix_t)]

for i in range(H-count_delete_H):
  for j in range(W-count_delete_W):
    print(matrix_tt[i][j],end='')
  print('')

Solution (Python):
H, W = map(int,input().split())
HW = [input() for _ in range(H)]
HW = ["".join(hw) for hw in zip(*HW) if hw.count("
HW = ["".join(hw) for hw in zip(*HW) if hw.count("
print("\n".join(HW))

Solution (Python):
""" AtCoder """

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

a = [input() for _ in range(H)]

ans = []
ans = []
ans_len = 0

for i in range(H):
    if a[i].count('
        ans.append(a[i])
        ans_len += 1

for t in range(W):
    for i in range(W):
        check = True
        for j in range(ans_len):
            if ans[j][i] == '
                check = False
                break
        if check:
            tmp = ans
            ans = []
            for j in range(ans_len):
                ans.append(tmp[j][:i] + tmp[j][i+1:])
            W -= 1
            break

for i in range(ans_len):
    print(ans[i])

Solution (Python):


def main():
    h, w = map(int, input().split())
    rows = [input() for i in range(h)]
    rows = filter(rows)
    cols = transpose(rows)
    cols = filter(cols)
    rows = transpose(cols)
    for r in rows:
        print("".join(r))

def transpose(rows):
    h = len(rows)
    w = len(rows[0])
    cols = [[rows[i][j] for i in range(h)] for j in range(w)]
    return cols

def filter(rows):
    rows = [r for r in rows if "
    return rows

main()

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


count = 0
for i in range(h-1,-1,-1):
  if "
    del a[i]
    count +=1
h -=count

tenti_a = list(map(list, zip(*a)))
count = 0
for i in range(w-1,-1,-1):
  if "
    del tenti_a[i]
    count +=1
w -=count

tenti_tenti_a = list(map(list, zip(*tenti_a)))
for i in range(h):
  print(str(tenti_tenti_a[i]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))

Solution (Python):

import sys
H, W = map(int, input().split(' '));

board = []
flags = [ True for x in range(W)]
for i in range(H):
    line = list(input())
    if ( '
        board.append(line)
        flags = [ f and s == '.' for s,f in zip(line, flags) ]

j = 0
for b in board:
    for l,flag in zip(b,flags):
        if not flag:
            sys.stdout.write(l)
    print()

Solution (Python):
h,w=map(int,input().split())
s=[]
for _ in range(h):
    a = input() 
    if "
        s.append(a)
d = []
for i in zip(*s):
    if "
        d.append(i)
for j in zip(*d):
    print(*j,sep="")

Solution (Python):
import numpy as np
h,w=map(int,input().split())
s=[]
for _ in range(h):
    a = input() 
    if "
        s.append(a)
d = []
for i in zip(*s):
    if "
        d.append(i)
for j in zip(*d):
    print(*j,sep="")