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 (GCC 9.2.1) (judge verdict: Accepted)

/*	ex7_3
	suzuto	*/

  #include <stdio.h>
  #include <stdlib.h>

  int main(void){
    char **grid_ptr, ins; /*変数の宣言*/
    int *height_ptr, *width_ptr, height, width, i, j;

    scanf("%d %d", &height, &width); /*縦横の長さを入力*/
    height_ptr = (int*)calloc(height, sizeof(int)); /*圧縮後に残る行を記憶*/
    if(height_ptr == NULL){ /*エラー出力*/
      fprintf(stderr, "Memory allocation error.\n");
      return 1;
    }
    for(i = 0; i < height; i++){
      height_ptr[i] = 0; /*height_ptrを初期化*/
    }
    width_ptr = (int*)calloc(width, sizeof(int)); /*圧縮後に残る列を記憶*/
    if(width_ptr == NULL){ /*エラー出力*/
      fprintf(stderr, "Memory allocation error.\n");
      return 1;
    }
    for(i = 0; i < width; i++){
      width_ptr[i] = 0; /*width_ptrを初期化*/
    }
    grid_ptr = (char**)calloc(height, sizeof(char*)); /*char*型配列を確保*/
    if(grid_ptr == NULL){ /*エラー出力*/
      fprintf(stderr, "Memory allocation error.\n");
      return 1;
    }
    for(i = 0; i < height; i++){
      grid_ptr[i] = (char*)calloc(width, sizeof(char)); /*char型配列を確保し入力を記憶する二次元配列が完成*/
      if(grid_ptr[i] == NULL){ /*エラー出力*/
        fprintf(stderr, "Memory allocation error.\n");
        return 1;
      }
    }
    for(i = 0; i < height; i++){
      for(j = 0; j < width; j++){
        scanf(" %c", &ins); /*入力insに一時的に記憶*/
        grid_ptr[i][j] = ins; /*入力を記憶用の配列に反映*/
        if(ins == '#'){ /*黒のある行、および列は圧縮により消えない*/
          height_ptr[i] = 1;
          width_ptr[j] = 1;
        }
      }
    }
    for(i = 0; i < height; i++){
      if(height_ptr[i] == 1){ /*height_ptrが初期値でないときその行は残る*/
        for(j = 0; j < width; j++){
          if(width_ptr[j] == 1){ /*width_ptrが初期値でないときその列は残る*/
            printf("%c", grid_ptr[i][j]); /*この点は残っているので出力*/
          }
        }
        printf("\n");
      }
    }

    /*各々の使用済みの動的確保した破裂を解放*/
    free(height_ptr);
    free(width_ptr);
    for(i = 0; i < height; i++){
      free(grid_ptr[i]);
    }
    free(grid_ptr);
    return 0;
  }