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 in C (Clang 3.8.0) (judge verdict: Accepted)

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) > *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static size_t countDivisors(const size_t n)
{
	size_t count = 1;

	for (size_t i = 2; i <= n; i++) {
		if (n%i == 0) {
			count++;
		}
	}

	return count;
}

static size_t rowCount[100];
static size_t colCount[100];

int main(void) {
	size_t H, W;
	char aReal[100][101];
	char *a[100];

	for (size_t idx = 0; idx < 100; idx++) {
		a[idx] = aReal[idx];
	}

	scanf("%zu %zu\n", &H, &W);
	for (size_t idx = 0; idx < H; idx++) {
		rowCount[idx] = 0;
	}
	for (size_t idx = 0; idx < W; idx++) {
		colCount[idx] = 0;
	}
	for (size_t idx = 0; idx < H; idx++) {
		scanf("%s", a[idx]);
		if (idx < H - 1) {
			scanf("\n");
		}

		for (size_t col = 0; col < W; col++) {
			if (a[idx][col] == '.') {
				rowCount[idx]++;
				colCount[col]++;
			}
		}
	}

	size_t h = H;
	size_t w = W;
	
	for (size_t count = 0; count < 2 * MIN(H, W); count++) {
		if (count % 2 == 0) {
			for (size_t row = 0; row < h; row++) {
				if (rowCount[row] == w) {
					for (size_t mvIdx = row; mvIdx < h - 1; mvIdx++) {
						a[mvIdx] = a[mvIdx + 1];
						rowCount[mvIdx] = rowCount[mvIdx + 1];
					}
					for (size_t colIdx = 0; colIdx < w; colIdx++) {
						colCount[colIdx]--;
					}
					h--;
				}
			}
		}
		else {
			for (size_t col = 0; col < w; col++) {
				if (colCount[col] == h) {
					for (size_t rowIdx = 0; rowIdx < h; rowIdx++) {
						for (size_t mvIdx = col; mvIdx < w; mvIdx++) {
							a[rowIdx][mvIdx] = a[rowIdx][mvIdx + 1];
							if (rowIdx == 0 && mvIdx < w - 1) {
								colCount[mvIdx] = colCount[mvIdx + 1];
							}
						}
						rowCount[rowIdx]--;
					}
					w--;
				}
			}

		}
	}

	for (size_t idx = 0; idx < h; idx++) {
		puts(a[idx]);
	}

	return 0;
}