P6265 [COCI 2014/2015 #3] SILUETA

Background

One day, the painter Vincent found himself in a big city full of skyscrapers, so he immediately sat down to paint, enjoying this wonderful view. For some reasons that ordinary programmers cannot understand, Vincent decided to draw only the outline of the skyscrapers in front of him. Unfortunately, one week after he finished this masterpiece, the painting was burned. To rebuild the painting, Vincent has asked for help in all directions, and now it is your turn.

Description

From your point of view, Vincent’s skyscrapers are rectangles whose sides are parallel to the coordinate axes, with one side lying on the $x$-axis. In the picture, the $x$-axis should be drawn using the character `*`, the outline of the skyscrapers using `#`, and everything else using `.`. The left edge of the picture must start with a skyscraper, and the right edge of the picture must end with a skyscraper. Also, to verify the result obtained by mathematicians, output the perimeter of the given outline, instead of counting the side that lies on the $x$-axis.

Input Format

The first line contains an integer $n$, the number of skyscrapers. Each of the next $n$ lines contains three integers $l_i, r_i$ and $h_i$, describing the position of the $i$-th skyscraper. In the Cartesian coordinate system, the skyscraper is treated as a rectangle with the bottom-left corner at $(l_i, 0)$ and the top-right corner at $(r_i, h_i)$.

Output Format

Output an integer on the first line, the perimeter of the skyscraper outline. In the next $h + 1$ lines, where $h + 1$ is the height of the tallest skyscraper, output Vincent’s drawing as described above.

Explanation/Hint

#### Explanation of Sample Input/Output 1 In the figure below, blue shows the skyscraper outline (character `#`), and yellow is the part of the $x$-axis in Vincent’s painting (character `*`). ![](https://cdn.luogu.com.cn/upload/image_hosting/ynl2n5os.png) #### Constraints - For $50\%$ of the testdata, $1 \le n \le 100$, and $1 \le l_i, r_i, h_i \le 100$. - For $100\%$ of the testdata, $1 \le n \le 10^4$, $1 \le l_i, r_i, h_i \le 10^3$, and $3 \leq r_i - l_i \leq 10^3$. Translated by ChatGPT 5