eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Crazy Bits

Crazy Bits

Olandicans have invented a strange computer; it has only \textbf{12}-bit registers to store numbers. And the only command that this computer accepts is \textbf{SWAP}. The Swap function is called with \textbf{3} parameters \textbf{i}, \textbf{j}, and \textbf{d}. A call of \textbf{swap(i, j, d) }swaps the \textbf{j}^th bit of the \textbf{i}^th register with its neighboring bit in direction \textbf{d} (\textbf{0}: up, \textbf{1}: right, \textbf{2}: down, \textbf{3}: left). For example, \textbf{swap (2, 3, 1)} swaps the \textbf{3}^rd and the \textbf{4}^th bits of the \textbf{2}^nd register and \textbf{Swap(6, 4, 2)} swaps the \textbf{4}^th bits of the \textbf{6}^th and the\textbf{7}^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. \InputFile The input consists of multiple test cases. The first line of each test case is \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{16}), the number of registers. The next line contains \textbf{n} integers, where the \textbf{i}^th number is the initial value of the \textbf{i}^th register. The next line contains \textbf{n }integers, where the \textbf{i}^th number is the desired value of the \textbf{i}^th register. The input is terminated by a line containing a zero. \OutputFile 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 "\textbf{Impossible}".
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
2 3
6 2
3
1 1 1
2 3 4
4
5 2 6 0
3 2 2 4
0
Вихідні дані #1
3
Impossible
2
Джерело 32nd ACM International Collegiate, 9th Asian Regional Contest in Iran, December 6-7 2007 (Azar 15-16, 1386)