#Q25. 「一本通 1.3 练习 2」平板涂色
「一本通 1.3 练习 2」平板涂色
Description
Original Problem from: ICPC Tehran 1999
CE Digital Company has developed a product called the Automatic Painting Machine (APM). It can paint a flat panel composed of non-overlapping rectangles of different sizes with predetermined colors.

To perform the painting, APM requires a set of brushes. Each brush is dipped in a color . The APM picks up a brush dipped in color and paints all rectangles that are colored . Note that there is an order requirement for painting: to prevent color mixing due to pigment leakage, a rectangle can only be painted after all rectangles immediately above it have been painted. For example, in the figure, rectangle must be painted after and have been painted. Note that each rectangle must be fully painted at once; partial painting is not allowed.
Write a program to find a painting sequence that minimizes the number of times the APM picks up a brush. Note that if a brush is picked up more than once, each instance must be counted in the total.
Input Format
The first line contains the number of rectangles .
The following lines describe the rectangles. Each rectangle is described by 5 integers: the and coordinates of the top-left corner, the and coordinates of the bottom-right corner, and the predetermined color.
Output Format
A single integer representing the minimum number of times the brushes are picked up.
Sample 1
7
0 0 2 2 1
0 2 1 6 2
2 0 4 2 1
1 2 4 4 2
1 4 3 6 1
4 0 6 4 1
3 4 6 6 2
3
Constraints & Hints
For all data, , and the color codes are integers from to . It is guaranteed that the top-left corner of the panel is always , and the coordinate range is from to .