Dominoes#542

Dominoes

1 second
256 megabytes

A horizontal row of dominoes is on the table. When implementing your solution in C++, add the directive #define lll long long and use lll for 64-bit integers. When implementing your solution in Python, add the line lll = int at the beginning of the program and convert every value you read to a number with the call lll(...). Its left end shows , and its right end shows .

Andrii has two dominoes: and . Taras has one domino: . Each pair gives the numbers on the two halves of the corresponding domino.

A domino can be attached to an end of the row if the touching halves show equal numbers. A domino may be reversed before it is attached. Dominoes already in the row cannot be moved or reversed.

First, Andrii must attach both his dominoes: one on the left and the other on the right. He chooses which domino to attach on each side and its orientation. Each domino must be used exactly once.

Then Taras tries to attach his domino to either end of the row. He may also reverse it.

Find an arrangement of Andrii's dominoes that leaves Taras unable to move, or report that no such arrangement exists.

Example for l = 1, r = 2, (a, b) = (1, 3), (c, d) = (2, 4), and (e, f) = (1, 2)

Input

The first line contains two integers and (0 \le l, r \le 6) — the numbers at the left and right ends of the existing row, respectively.

The second line contains two integers and (0 \le a, b \le 6) — the numbers on Andrii's first domino.

The third line contains two integers and (0 \le c, d \le 6) — the numbers on Andrii's second domino.

The fourth line contains two integers and (0 \le e, f \le 6) — the numbers on Taras's domino.

Different dominoes may have identical pairs of numbers. Andrii's two dominoes are separate pieces even if they show the same numbers; both pieces must be used.

Output

If no suitable arrangement exists, print .

Otherwise, on the first line, print two numbers and — the numbers on the domino Andrii attaches on the left. On the second line, print two numbers and — the numbers on the domino he attaches on the right. On both lines, write the numbers in left-to-right order. Thus, y=l, z=r, and the new ends of the row are and .

Use both of Andrii's dominoes, each exactly once, with reversal allowed. Afterwards, Taras must have no legal move. If several arrangements are possible, print any of them.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading

Note

The first example is shown in the picture above. Andrii attaches on the left in the order , and on the right in the order . The new ends of the row are and . Taras has , so he cannot make a move.

In the second example, can only be attached on the left. Therefore, must be attached on the right. The new ends are and . Taras can attach his domino to the end showing , so no suitable arrangement exists.

Example for l = 1, r = 2, (a, b) = (1, 3), (c, d) = (2, 1), and (e, f) = (1, 4)

In the third example, Andrii attaches on the left in the order , and on the right in the order . The new ends are and . Neither matches the numbers and on Taras's domino, so he cannot make a move.

Editorial