Snake Cube
The snake cube is a mechanical puzzle made up of (n^3) cubes, each measuring (1 1 1), connected by an elastic cord. Each pair of adjacent cubes on the cord touches at one face and can rotate freely around an axis perpendicular to that face. Every three consecutive cubes form either a straight line or a (90) degree angle. You cannot bend a straight segment of the snake into an angle or straighten an angle into a straight segment; you can only decide, through rotations, which of the four directions the snake turns at each angle. The objective is to assemble a larger cube of size (n n n) using this snake. An example of a snake is shown in the figure.
Not every snake can be assembled into a cube; at a minimum, all straight sections of the snake must consist of no more than (n) cubes.
We define the snake by the sequence of lengths of its straight segments, specifically by the sequence of distances between the centers of the first and last cubes in each straight segment. For example, the snake shown in the figure is defined from left to right as follows: (2 1 1 2 1 2 1 1 2 2 1 1 1 2 2 2 2).
In this task, you are asked to solve a generalized version of this puzzle. A snake with (l w h) cells is given. Fit it into a rectangular parallelepiped of size (l w h) cells or determine that it is impossible.
Input
The first line of the input file contains four integers separated by spaces - (l), (w), (h), and (m) ((1 l, w, h 4); (0 m < lwh)); here (l), (w), and (h) are the length, width, and height of the parallelepiped, respectively, and (m) is the number of segments in the snake. The second line contains (m) positive integers separated by spaces - the sequence of lengths of the straight segments of the snake. It is guaranteed that the given snake contains exactly (l w h) cubes.
Output
If it is impossible to fit the given snake into the parallelepiped, output "Bit" on the first line of the output file. Otherwise, output "Baba" on the first line of the output file, and in the next (l w h) lines - the coordinates of the snake's cubes, three numbers per line. The snake should be output from the same end it starts in the input file. The numbers (x_i), (y_i), and (z_i) in the ((i+1))-th line must satisfy the inequalities (0 x_i < l), (0 y_i < w), and (0 z_i < h). Additionally, all cubes of the parallelepiped (l w h) must appear in the output file exactly once, adjacent lines must contain adjacent cubes, and the turns must exactly match the turns of the snake. The snake can start and end in any cube of the parallelepiped. If there are multiple solutions, any one of them may be output.