Reorganizing Bus Routes
InterviewTime limit2sMemory limit1024 MB
Merge overlapping intervals into their union, keeping the cheaper fare, then output the surviving intervals sorted by start.
Problem
Seogang operates bus routes along a straight road. Because routes were added whenever the need arose, many of them overlap or duplicate each other. To help citizens tired of the complicated bus network, the government decided to reorganize the routes.
Each bus route is described by three integers , , and , meaning that it covers the interval with fare . If the intervals of two bus routes share at least one point, the two intervals are replaced by a single new route covering their union. The fare of the new route is the lower of the two fares. The reorganization continues until no two routes have overlapping intervals.

Figure D.1: Bus routes before and after reorganization
Given the information about the bus routes, write a program that outputs the routes after the reorganization finishes.
Input
The first line contains the number of bus routes . ()
The next lines each contain three integers , , and describing one bus route. (, )
Output
Print , the number of bus routes after the reorganization, on the first line.
On the next lines, print , , and for each route after the reorganization, in increasing order of .