Painters
A painting company has received an order to paint a long fence, which requires the work of multiple painters. The company manager assigned each painter to paint a section of the fence, from board number X to board number Y (inclusive), using color Z. Each painter starts their task after the previous one has finished. However, due to some errors in task assignments, certain boards may have been painted more than once, while others might not have been painted at all. The company director has collected all the records of the painters' work and needs to determine which color would be the easiest to repaint the entire fence.
Your task is to calculate how many boards are painted in each color on the fence.
Input
The first line contains a single natural number N — the number of painters involved, where N ≤ 10^5. The following N lines each contain three integers, X_i, Y_i, Z_i, separated by spaces. Here, 0 ≤ X_i, Y_i ≤ 10^9, and 1 ≤ Z_i ≤ 10^5. These represent the starting board number, the ending board number, and the color used, respectively.
Output
Let M be the number of distinct colors used on the boards. Output M lines, each containing 2 natural numbers separated by a space: the color number and the count of boards painted in that color. The output should be sorted in ascending order by the color number.