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 = input().split()
h = int(h)
w = int(w)
lines = list()
c = [0]*w
for _ in range(h):
    line = input()
    if line=="."*w:
        continue
    lines.append(line)
    for i in range(w):
        if line[i]==".":
            c[i] += 1
h = len(lines)
ans = list()
for j in range(h):
    line = ""
    for i in range(w):
        if c[i] != h:
            line += lines[j][i]
    ans.append(line)
print("\n".join(ans))

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

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


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



for i in range(H):
	str=""
	for j in range(W):
		if A[i][j]!=0:
			str+=A[i][j]
	if len(str)!=0:
		print str

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

a = []

for i in range(h):
    s = input()
    f = 1
    for j in range(w):
        if s[j]=='
            f = 0
            break
    if f==0:    
        a.append(s)

out = []
for i in range(w):
    f =1
    for j in range(len(a)):
        if a[j][i] == '
            f = 0
            break
    if f == 1:
        out.insert(0, i)
        
        
for i in out:
    for j in range(len(a)):
        a[j] = a[j][:i]+a[j][i+1:]
            
for i in range(len(a)):
    print(a[i])

Solution (Python):
H,W = map(int,input().split())
ma = [input() for i in range(H)]
ol = []
for i in range(len(ma)):
    if '
        ol.append(ma[i])
f = True
deli = []
for i in range(len(ma[0])):
    f = True
    for i2 in range(len(ma)):
        if ma[i2][i] == '
           f = False
           break
    if f:
        deli.append(i)

for o in ol:
    s = ""
    for i in range(len(o)):
        if not i in deli:
            s += o[i]
    print(s)

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

b = []
for i in range(h):
    if a[i]!="."*w:
        b.append(a[i])

c = ["" for i in range(len(b))]

for i in range(w):
    for j in range(len(b)):
        if b[j][i] != ".":
            for k in range(len(b)):
                c[k] += b[k][i]
            break


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

Solution (Python):
h, w = [int(x) for x in input().split()]
m = []
for i in range(h):
    m.append(input())
n = []
for i, row in enumerate(m):
    if '
        n.append(row)
flgs = []
for j in range(w):
    js = ''.join([row[j] for row in m])
    flgs.append('
n = [''.join([item for i, item in enumerate(s) if flgs[i]]) for s in n]
for item in n:
    print(item)

Solution (Python):
H, W = list(map(int, input().split()))
X = []
h = 0
for i in range(H):
	a = input()
	if a == "." * W:
		pass
	else:
		X.append(list(a))
		h += 1

Y = []
w = 0
for i in range(W):
	x = ""
	for j in range(h):
		x += X[j][i]
	if x == "." * h:
		pass
	else:
		Y.append(list(x))
		w += 1

for i in range(h):
	n = ""
	for j in range(w):
		n += Y[j][i]

	print(n)

Solution (Python):

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

for i in range(h):
    ww = ["." for _ in range(w)]
    st = list(str(input()))
    if st != ww:
        hako.append(list(st))


hako2 = []
for i in range(w):
    one = []
    for onelist in hako:
        one.append(onelist[i])
    hako2.append(one)
    
hako3 = []
for _ in hako2:
    check = ["." for pp in range(len(_))]
    if _ != check:
        hako3.append(_)
        
hako4 = []

for i in range(len(hako3[0])):
    one = []
    for onelist in hako3:
        one.append(onelist[i])
    hako4.append(one)
    
for _ in hako4:
    strs = ""
    for char in _:
        strs += char
    print(strs)

Solution (Python):


def main():
    h, w = map(int, input().split())
    lines = [l for l in [input() for _ in range(h)] if l != '.' * w]
    lines2 = [''] * len(lines)
    for i in range(w):
        f = False
        for l in lines:
            if l[i] != '.':
                f = True
                break
        if f:
            for j, l in enumerate(lines):
                lines2[j] = lines2[j] + l[i]

    for l in lines2:
        print(l)


if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
a = [input() for i in range(H)]
b = []
for i in range(H):
    if '
        b.append(a[i])
c = [i for i in zip(*b)]

d =[]
for i in range(len(c)):
    if '
        d.append(c[i])
e = [i for i in zip(*d)]

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

Solution (Python):
H, W = map(int, input().split())
grid = []
for i in range(H):
    a = input()
    assert len(a) == W
    grid.append(a)

whiterow = [all(c == '.' for c in row) for row in grid]
whitecol = [all(row[i] == '.' for row in grid) for i in range(W)]

for r, row in enumerate(grid):
    if whiterow[r]: continue
    comp = [c for i, c in enumerate(row) if not whitecol[i]]
    print(''.join(comp))

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

m = []
l = [False for i in range(w)]

for i in range(h):
    s = input()
    flg = False
    if '
        m.append(s)
    for j in range(w):
        if l[j]==False and s[j] == '
            l[j] = True
for i in m:
    for j in range(w):
        if l[j]:
            print(i[j],end='')
    print()

Solution (Python):
h, w = map(int, input().split())
array = [input() for x in range(h)]
res_array = []
for row in array:
    if len(row) != row.count("."):
        res_array.append(row)

array2 = [x for x in zip(*res_array)]
res_array2 = []
for row in array2:
    if len(row) != row.count("."):
        res_array2.append(row)

for i in [x for x in zip(*res_array2)]:
    print("".join(i))

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

ans = []

for i in range(H):
    S = input()
    if(S.find(Black) == -1):
        H -= 1
    else:
        ans.append(list(S))


i = 0
del_row = []
while(i < W):
    tmp = ""
    for j in range(H):
        tmp += ans[j][i]
    if(tmp.find(Black) == -1):
        del_row.append(i)

    i += 1

for i in reversed(del_row):
    for j in range(H):
        ans[j].pop(i)

for i in range(H):
    print("".join(ans[i]))

Solution (Python):
h, w = map(int, input().split())
a = []
for _ in range(h):
    aa = list(input())
    a.append(aa)
b = []
for i in range(h):
    if "
       b.append(a[i])
tra = list(map(list, zip(*b)))
ans = []
for i in range(len(tra)):
    if "
       ans.append(tra[i])
ans = list(map(list, zip(*ans)))
for j in ans:
    print("".join(j))

Solution (Python):
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
delJ = []
for j in range(W):
    judge = True
    for i in range(H):
        if A[i][j] == "
            judge = False
            break
    if judge:
        delJ.append(j)

output = []
for i in range(H):
    if "
        B = ""
        for j in range(W):
            if j not in delJ:
                B += str(A[i][j])
        output.append(B)

for i in output:
    print(i)

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



for i in range(h):
  l = input()
  if '
    a.append(l)
    
z = [False] * w

for i in range(w):
  for l in a:
    if l[i] == '
      z[i] = True
      break
    


for j, _ in enumerate(a):
  for i in range(w) :
    if z[i]:
      print(_[i], end='')
  if j == len(a) -1:
    break
  print('')

Solution (Python):


import numpy as np

h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]
buf = []
for i in range(h):
    for j in range(w):
        if A[i][j] == '
            buf.append(A[i])
            break
ret = []
for j in range(len(buf[0])):
    for i in range(len(buf)):
        if buf[i][j] == '
            ret.append([buf[k][j] for k in range(len(buf))])
            break
ans = np.array(ret).T
for line in ans:
    print(''.join(line))

Solution (Python):
H, W = map(int, input().split())
m = []
for i in range(H):
    r = list(input())
    if r == ['.'] * W:continue
    m.append(r)

k = []
for i in range(W):
    if [m[j][i] for j in range(len(m))] == ['.'] * len(m):
        k.append(i)

ans = []    
for r in m:
    t = []
    for i,l in enumerate(r):
        if  not i in k:
            t.append(l)
    ans.append(t)
for l in ans:
    print(''.join(l))

Solution (Python):
H, W = map(int, input().split())
A = [input() for _ in range(H)]
A = list(filter(lambda a: any(x == '
A = list(filter(lambda a: any(x == '
for a in zip(*A):
    print(''.join(a))

Solution (Python):
from sys import stdin, stdout

input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    H, W = map(int, input().split())
    A = stdin.read().splitlines()

    def func(a):
        ret = []
        for s in a:
            if s.count('
                ret.append(s)
        return ret

    ans = func(list(zip(*A)))
    ans = func(list(zip(*ans)))
    for s in ans:
        print(*s, sep='')

main()

Solution (Python):

import sys
input = sys.stdin.readline

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


bk = '

for i in range(h):
    flg = True
    for j in range(w):
        if M[i][j] == bk:
            flg = False
            break
    if flg:
        for j in range(w):
            M[i][j] = ''

for j in range(w):
    flg = True
    for i in range(h):
        if M[i][j] == bk:
            flg = False
            break
    if flg:
        for i in range(h):
            M[i][j] = ''     

for i in range(h):
    res = ''
    for j in range(w):
        if M[i][j] != '':
            res += M[i][j]
    if res != '':
        print(res)

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

M = []

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

M2 = []

for i in range(H):
    if '
        M2.append(M[i])

idx = []
for i in range(W):
    flag = True
    for j in range(len(M2)):
        if M2[j][i] == '
            flag = False

    if flag == False:
        idx.append(i)

M3 = []
for i in range(len(M2)):
    s = ''
    for j in range(W):
        if j in idx:
            s += M2[i][j]
    M3.append(s)

print '\n'.join(M3)

Solution (Python):
h,w=map(int,input().split())
l=[list(input()) for _ in range(h)]
l=[i for i in l if i!=["."]*w]
h=len(l)
m=[]
for (i,j) in enumerate(zip(*l)):
  if j==tuple("." for _ in range(h)):
    m.extend([i])
for i in range(h):
  for j in range(w):
    if not j in m:
      print(l[i][j],end="")
  print()

Solution (Python):
h,w=map(int,input().split())
a=[]
b=[]
for i in range(h):
   n=input()
   if n.count(".")<w:a+=[n]
for i in range(w):
   if [I[i] for I in a].count(".")==len(a):
      b+=[i]
for i in range(len(a)):
   print("".join([a[i][I] for I in range(w) if I not in b]))

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

S = []
for w in range(W):
    for l in range(len(L)):
        if L[l][w] == "
            break
    else:
        S.append(w)
    
for l in range(len(L)):
    s = ""
    for w in range(W):
        if not w in S:
            s += L[l][w]
    print(s)

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

for _ in range(H):
    a = input()
    A.append(a)

result = []
temp = []

for a in A:
    flag = True
    for s in a:
        if s != '.':
            flag = False
            break
    if not flag:
        temp.append(a)

idx = []

for i in range(W):
    flag = True
    for s in temp:
        if s[i] != '.':
            flag = False
            break
    if not flag:
        idx.append(i)

for s in temp:
    t = ''
    for i in idx:
        t += s[i]
    result.append(t)

print(*result, sep='\n')

Solution (Python):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

H, W =getMN()
all = []
for i in range(H):
    a = input()
    if "
        all.append(a)

length = len(all[0])
raw = [0 for i in range(length)]

for r in all:
    for i in range(length):
        if r[i] == "
            raw[i] = 1

for r in all:
    for i in range(length):
        if raw[i] == 1:
            print(r[i],end="")
    print("")

Solution (Python):
h,w=map(int, input().split())
a=[]
w=[False for _ in range(w)]
for _ in range(h):
    line=input()
    for i, ai in enumerate(line):
        if ai=='
            w[i]=True
    if '
        a.append(line)

for ai in a:
    line=''
    for i, wi in enumerate(w):
        if wi:
            line+=ai[i]
    print(line)

Solution (Python):
import numpy as np


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

A = []

for h in range(H):
    a = list(input())
    if '
        A.append(a)

A = np.rot90(np.array(A)).tolist()
B = []

for w in range(len(A)):
    if '
        B.append(A[w])


B = np.rot90(np.array(B), 3).tolist()

for b in B:
    print(str.join('', b))

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



H=[0 for i in range(h)]
W=[0 for i in range(w)]

for i in range(h):
    if A[i]=="."*w :
        H[i]=1
for i in range(w):
    co=0
    for j in range(h):
        if A[j][i]=="." :
            co+=1
    if co==h :
        W[i]=1


B=[]

for i in range(h):
    st=""
    if H[i]==0 :
        for j in range(w):
            if W[j]==0:
                st+=A[i][j]
        print(st)

Solution (Python):
h,w = list(map(int,input().split()))
h_ch = [0]*h
w_ch = [0]*w
inp = []
for i in range(h):
  inp.append(input())
  for j in range(w):
    h_ch[i] += 1 if inp[-1][j]=="
    w_ch[j] += 1 if inp[-1][j]=="
    
for i in range(h):
  if h_ch[i] > 0:
    out = ""
    for j in range(w):
      if w_ch[j] > 0:
        out += inp[i][j]
    print(out)

Solution (Python):
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 == '
    mtx = [x for x in zip(*mtx)]
    mtx = [x for x in mtx if len([y for y in x if y == '
    mtx = [x for x in zip(*mtx)]
    for x in mtx:
        print(''.join(x))


if __name__ == '__main__':
    main()

Solution (Python):
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()

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
import numpy as np

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

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

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

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

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

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

Solution (Python):
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()

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

MAP=[None]*H

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


ANSH=[]
for i in range(H):
    if "
        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()

Solution (Python):
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)

Solution (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

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 = [''] * 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()