GentleBots

Simulate a fixed three-dimensional two-robot controller: for each robot, print the straight or detour route around the other robot's position, exactly following the stated rules.

Medium7SimulationImplementationGeometryBrute forceNo attempts yetTime limit1sMemory limit512 MB

Problem

Rainforest Inc. is opening a large automated warehouse in the north of the UK, in a place called Walthamstow.

The worker robots inside move in three dimensions. In one time step a robot either stays where it is or walks one metre along one of the six axis directions, so a robot that travels from (x1,y1,z1)(x_1, y_1, z_1) to (x2,y2,z2)(x_2, y_2, z_2) with nothing in its way needs x2x1+y2y1+z2z1|x_2 - x_1| + |y_2 - y_1| + |z_2 - z_1| steps.

The robots are impeccably polite. When two of them meet head on, they settle it without a word and one steps aside so the other can pass.

A robot always stands on integer coordinates. Two robots must never stand on the same coordinates, and two robots must never exchange positions in one time step. All moves of a time step happen at the same instant.

The test run of the warehouse has two robots installed. The controller plans them with one fixed procedure, written out in the output section, and your program has to reproduce that plan exactly.

Input

The first line has six space separated integers x0 y0 z0 x1 y1 z1x_0\ y_0\ z_0\ x_1\ y_1\ z_1. The first three are the start position (x0,y0,z0)(x_0, y_0, z_0) of robot 1 and the last three are its end position (x1,y1,z1)(x_1, y_1, z_1). The second line gives the six values of robot 2 in the same format. Every coordinate satisfies 1000x,y,z1000-1000 \le x, y, z \le 1000.

The two robots start at different positions and end at different positions. One robot may start and end at the same position.

Output

Print the plan of the controller. Counting from 0, line TT has six space separated integers: the position of robot 1 at time TT followed by the position of robot 2 at time TT. The first line holds the two start positions, the last line holds the two end positions, and between two consecutive lines a robot moves at most one metre.

The controller walks one robot at a time and leaves the other standing. Two definitions come first.

The straight route from pp to qq is the list of positions that begins at pp, changes the x coordinate one step at a time until it matches the x coordinate of qq, then changes the y coordinate the same way, then the z coordinate, and so ends at qq.

The safe route from pp to qq around a blocked position mm, where mm equals neither pp nor qq, is fixed like this. If the straight route from pp to qq does not contain mm, that route is the safe route. If it does contain mm, check the six offsets (1,0,0)(1, 0, 0), (1,0,0)(-1, 0, 0), (0,1,0)(0, 1, 0), (0,1,0)(0, -1, 0), (0,0,1)(0, 0, 1), (0,0,1)(0, 0, -1) in this order and take the first offset ss for which the straight route from p+sp + s to q+sq + s does not contain mm. Such an offset always exists. The safe route is then pp, every position of the straight route from p+sp + s to q+sq + s, and qq, in that order.

Write a0a_0 and a1a_1 for the start and the end of robot 1, and b0b_0 and b1b_1 for those of robot 2. The controller applies the first rule whose condition holds.

  1. If a1b0a_1 \ne b_0, robot 1 walks the safe route from a0a_0 to a1a_1 around b0b_0, then robot 2 walks the safe route from b0b_0 to b1b_1 around a1a_1.
  2. Otherwise, if b1a0b_1 \ne a_0, robot 2 walks the safe route from b0b_0 to b1b_1 around a0a_0, then robot 1 walks the safe route from a0a_0 to a1a_1 around b1b_1.
  3. Otherwise robot 2 first steps aside to c=b0+sc = b_0 + s, where ss is the first offset in the list above with b0+sa0b_0 + s \ne a_0. Then robot 1 walks the safe route from a0a_0 to a1a_1 around cc, and finally robot 2 walks the safe route from cc to b1b_1 around a1a_1.

While a robot walks a route, print one line for every position of the route except the first one, and the robot that is not walking repeats its position on those lines. A route of a single position prints no line.