Skyscraper Silhouette

No attempts yetTime limit1sMemory limit32 MB

Problem

The painter Vincent travelled through a city of skyscrapers and finished a painting of nothing but their silhouette. A week after he finished it, the painting burned. The architects gave him the exact dimensions of the skyscrapers again, so the painting can be reconstructed.

There are NN skyscrapers. The ii-th one is a rectangle with sides parallel to the coordinate axes, with its lower left corner at (Li,0)(L_i, 0) and its upper right corner at (Ri,Hi)(R_i, H_i). The silhouette is the union of these NN rectangles.

Let L=minLiL = \min L_i, R=maxRiR = \max R_i and H=maxHiH = \max H_i. The picture is RLR - L cells wide, so its left edge is the left side of the leftmost skyscraper and its right edge is the right side of the rightmost skyscraper. The picture has HH rows for the skyscrapers plus one row for the xx axis, H+1H + 1 rows in total. The jj-th cell from the left covers the interval [L+j1,L+j][L + j - 1, L + j] on the xx axis, and the kk-th row from the top covers the interval [Hk,Hk+1][H - k, H - k + 1] on the yy axis. The last row is the xx axis and is filled with * across the whole width.

Every coordinate is an integer, so each cell above the xx axis either lies completely inside the silhouette or shares no interior point with it. Call a cell that lies completely inside the silhouette a building cell. If at least one of the eight cells that share a side or a corner with a building cell is not a building cell, write # in that building cell. Write . in every other cell. A cell outside the horizontal range of the picture is not a building cell. Inside that range, the cells on the xx axis row and below it count as building cells. What is left is the outline of the silhouette.

The value the mathematicians computed has to be checked, so report the perimeter of the silhouette as well. Sides that lie on the xx axis do not count towards the perimeter.

Input

The first line contains the number of skyscrapers NN (1N100001 \le N \le 10\,000).

Each of the next NN lines contains three integers LiL_i, RiR_i and HiH_i describing the ii-th skyscraper (1Li,Ri,Hi10001 \le L_i, R_i, H_i \le 1\,000, 3RiLi10003 \le R_i - L_i \le 1\,000).

Output

On the first line, print the perimeter of the silhouette. Sides lying on the xx axis are not counted.

On the next H+1H + 1 lines, print the picture, where HH is the height of the tallest skyscraper.