A solar-tracking array is built from an n × n grid of independently tilting panels. Each panel is either raised into sunlight (marked 1) or lying flat (marked 0). When technicians remount the entire frame after maintenance, the mounting bolts only let them bolt it back at 0°, 90°, 180°, or 270° clockwise rotation from its original orientation — the frame can never be flipped over.
You are given the panel configuration recorded just before the remount and the configuration a maintenance log claims was observed afterward. Determine whether the observed configuration could really be the same physical array, simply bolted back on at one of the four allowed rotation angles.
Line 1: a single integer n, the grid's side length.
Next n lines: n integers each (0 or 1), the "before" grid, given row by row, top to bottom.
Next n lines: n integers each (0 or 1), the "after" grid, given the same way.
Print exactly one line containing YES if some rotation (by 0°, 90°, 180°, or 270°) of the before grid is identical to the after grid, and NO otherwise.
Example 1
Input
2 0 1 1 1 1 1 0 1
Expected
YES
Explanation
The before grid is [[0,1],[1,1]]. Rotating it 270° clockwise (equivalently 90° counter-clockwise) sends the top-right 1 to the bottom-left and rearranges the rest, producing [[1,1],[0,1]], which exactly matches the after grid, so the answer is YES.
Example 2
Input
2 1 0 0 1 1 1 0 1
Expected
NO
Explanation
The before grid has exactly two raised panels while the after grid has three. Rotating a grid never changes how many panels are raised, so no rotation of before can ever equal after, and the answer is NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →