Under construction

Still being built. Things may change

Towers

Time limit2sMemory limit1024 MB

Summary
Given a grid of towers, print the smallest connected, row- and column-convex set of cells that contains all of them.
Level

Medium6 of 10

Topics
Geometry, Implementation
Solved
No attempts yet

Problem

Richmond Valentine built cell towers through which he plans to send signals to the SIM cards of his company. Now he wants to find the area covered by his towers.

The map of the Earth is a grid of nn rows and mm columns. Each tower occupies exactly one cell. A set of cells is called connected if every cell in it can be reached from every other cell by moving across cell borders while staying inside the set. A connected set is called cell-convex if every vertical and horizontal line intersects it in at most one contiguous segment. Valentine considers the towers to cover the minimal connected cell-convex figure that contains all the towers he built. Find this area.

Input

The first line contains integers nn and mm (1≤n,m≤5001 \le n, m \le 500), the dimensions of the Earth. The next nn lines each contain mm characters describing the map. If cell (i,j)(i, j) holds a tower, the jj-th character of the ii-th line is *, otherwise it is ..

Output

Print nn lines of mm characters each. If cell (i,j)(i, j) lies in the covered area, the jj-th character of the ii-th line must be *, otherwise it must be .. If there are multiple answers, print any of them.

Examples1

  1. Example 1

    Input
    3 3
    ***
    *.*
    *.*
    
    Expected output
    ***
    ***
    ***