Crazy Bits#6914

Crazy Bits

1 second
64 megabytes
Very hard

Olandicans have invented a strange computer; it has only -bit registers to store numbers. And the only command that this computer accepts is SWAP. The Swap function is called with parameters , , and . A call of swap(i, j, d) swaps the -th bit of the -th register with its neighboring bit in direction (: up, : right, : down, : left). For example, swap(2, 3, 1) swaps the -rd and the -th bits of the -nd register and Swap(6, 4, 2) swaps the -th bits of the -th and the -th registers.

Olandicans know the initial values of the registers and they want to change them to some other numbers. They asked you to help them find the minimum number of swap calls.

Input

The input consists of multiple test cases. The first line of each test case is (1 \le n \le 16), the number of registers. The next line contains integers, where the -th number is the initial value of the -th register. The next line contains integers, where the -th number is the desired value of the -th register. The input is terminated by a line containing a zero.

Output

For each test case, you should write a single line containing the minimum number of swaps needed for that test case. If it is not possible, write "Impossible".

Examples

Example 1

Loading
Loading