Oh no! Bill just realized that the sudoku puzzle he had spent the last ten minutes trying to solve essentially was last week's puzzle, only rotated counterclockwise. How cheap! Couldn't the magazine afford to make a new one every week? Of course, he had no way of knowing about this before he started to solve it, as the holes to fill with digits were other than last week. Nevertheless, realizing that this week's puzzle was a simple derivative of last week's certainly took the fun out of solving the rest of it.
The sudoku board consists of 9×9 cells. These can be grouped into 3×3 regions of 3×3 cells each. Some of the cells are filled with a digit 1 through 9 while the rest of them are left empty. The aim of the game is to fill each empty cell with a digit 1 ... 9 so that every row, every column and every region contains each of the numbers 1 ... 9 exactly once. A proper sudoku puzzle always has exactly one solution.
Help Bill avoid unpleasant surprises by creating a program that checks whether an unsolved sudoku puzzle is in fact derived from an earlier puzzle by simple operations.
The allowed operations are:
- Rotating the entire puzzle clockwise or counterclockwise.
- Swapping two columns within a 3 × 9 column segment.
- Swapping two rows within a 9 × 3 row segment.
- Swapping entire row or column segments.
- Applying a permutation f of the digits 1 ... 9 to every cell (i.e. replace x by f(x) in every cell).
An operation is considered being performed on the sudoku solution (rather than on the unsolved puzzle) and always guarantees that if the board before the transformation was a solution to a sudoku puzzle, it still is afterwards.