Obstacle Course Run

Given vertical wall segments, find the shortest eastbound route from a start point to a finish line and list the y coordinates of all distinct endpoints of shortest routes.

Medium6GeometryGraphShortest pathSortingNo attempts yetTime limit2sMemory limit512 MB

Problem

Coordinates are a convenient way to name a point in the plane. In Figure 1 the red point lies at distance 4 to the right of the reference point (called the origin) and distance 3 above it, so its coordinates are (4,3)(4, 3). In the same way, the point at distance xx to the right of the origin and distance yy above it has coordinates (x,y)(x, y), and the origin itself is (0,0)(0, 0).

Figure 1

A running race is held on a wide field with obstacles on it. Fence shaped obstacles stand here and there across the field, each one running in the vertical direction (north to south). The runner starts at the starting point and runs east. On meeting an obstacle the runner must run south or north to get around it. Once the runner reaches an end of the obstacle, the runner can only run east again.

The goal of the race is to reach the finish line, an infinitely long vertical line, over the shortest distance. Every obstacle is described to the runner before the race starts. The runner knows the size and the position of each obstacle and has to reach the finish line by the shortest run that avoids them.

The starting point and the two ends of each obstacle are written as (x,y)(x, y) coordinates. Every coordinate value is an integer, and the xx coordinate of the starting point is 00. An obstacle is a vertical segment, so its two ends share one xx coordinate and a single obstacle is described by three values [x,yl,yh][x, y_l, y_h] (yl<yhy_l < y_h). These three values are the xx coordinate where the obstacle stands and the yy coordinates of its two ends.

No two obstacles with the same xx coordinate overlap or meet at a point.

A runner heading east who meets an end point of an obstacle keeps running east.

Look at the example in Figure 2. The starting point is (0,43)(0, 43), the xx coordinate of the finish line is 7070, and the four obstacles are [20,30,50][20, 30, 50], [30,10,38][30, 10, 38], [45,35,55][45, 35, 55] and [55,50,70][55, 50, 70]. The shortest route, drawn as a dotted line, is

(0,43)(20,43)(20,50)(45,50)(45,55)(55,55)(55,50)(70,50)(0, 43) \to (20, 43) \to (20, 50) \to (45, 50) \to (45, 55) \to (55, 55) \to (55, 50) \to (70, 50)

Its total length is 8787, and the yy coordinate of the arrival point is 5050.

Figure 2

The example in Figure 3 has four different shortest routes.

  1. (0,40)(20,40)(20,50)(35,50)(35,60)(70,60)(0, 40) \to (20, 40) \to (20, 50) \to (35, 50) \to (35, 60) \to (70, 60)
  2. (0,40)(20,40)(20,50)(35,50)(35,40)(70,40)(0, 40) \to (20, 40) \to (20, 50) \to (35, 50) \to (35, 40) \to (70, 40)
  3. (0,40)(20,40)(20,30)(50,30)(50,40)(70,40)(0, 40) \to (20, 40) \to (20, 30) \to (50, 30) \to (50, 40) \to (70, 40)
  4. (0,40)(20,40)(20,30)(50,30)(50,20)(70,20)(0, 40) \to (20, 40) \to (20, 30) \to (50, 30) \to (50, 20) \to (70, 20)

Figure 3

The second route and the third route run along different paths, yet they arrive at the same point.

Given the yy coordinate of the starting point, the xx coordinate of the finish line and the description of NN obstacles, find every shortest route that follows the movement rules, then print the yy coordinates of the distinct arrival points in ascending order.

Input

Standard input carries the following. The first line has one integer NN, the number of obstacles (1N100,0001 \le N \le 100{,}000). The second line has two integers, the yy coordinate of the starting point and the xx coordinate of the finish line, in that order. Each of the next NN lines has three integers xx, yly_l and yhy_h (yl<yhy_l < y_h) describing one obstacle, in that order. Every coordinate (x,y)(x, y) used in the problem satisfies 0x1,000,0000 \le x \le 1{,}000{,}000 and 0y2,000,0000 \le y \le 2{,}000{,}000. The xx coordinate of every obstacle is greater than 00 and smaller than the xx coordinate of the finish line.

Output

On the first line of standard output print the length of a shortest route. On the second line print kk, the number of distinct arrival points of the shortest routes, followed by the yy coordinates of those kk arrival points in ascending order.