Hiking in the Hills
Helen is hiking with her friends in a highland. Their plan is to hike from their camp A to a beautiful showplace B.
Unfortunately, Helen started feeling dizzy due to altitude sickness. Help her group find a route such that the topmost height on that route is as small as possible.
Input
Contains full information about the landscape of a square region 10^6
* 10^6
in the following format. The first line contains integer n - the number of triangles in the landscape (2 ≤ n ≤ 2000). Each of following n lines contains nine integers x[i1]
, y[i1]
, z[i1]
, x[i2]
, y[i2]
, z[i2]
, x[i3]
, y[i3]
, z[i3]
- coordinates of a triangle. All coordinates belong to the closed interval [0, 10^6
]. The two last lines contain three integers each: x[A]
, y[A]
, z[A]
and x[B]
, y[B]
, z[B]
- coordinates of the camp A and the showplace B.
The given triangles are guaranteed to describe a consistent continuous landscape. Projections of triangles onto XY plane are non-degenerate and fill the square without overlapping. A vertex of one triangle never lays inside an edge of another triangle. Points A and B belong to the landscape surface and are different.
Output
Output a polyline route from A to B with the smallest possible topmost height. The first line should contain m, the number of vertices in this polyline. Each of following m lines should contain three integer coordinates of a polyline vertex: x[i]
, y[i]
and z[i]
. Vertices must be listed along the polyline, from A to B (including these two endpoints).
All coordinates of polyline vertices should be integer. Each polyline edge must belong to some trianglefrom the input (possibly, to its edge). The number of vertices in the polyline must not exceed 5n.