Bread Sorting
InterviewTime limit1sMemory limit128 MB
Decide whether one permutation of 1..n can be turned into another using only the operation that rotates any three adjacent elements right by one.
Problem
Sanggeun works at a bakery. His last task before leaving for the day is to arrange the loaves of bread in the order his boss wants.
Sanggeun can use a special trick to toss three adjacent loaves at once with a spatula. When the loaves land again, the rightmost of the three moves to the leftmost spot, while the other two each shift one position to the right. In other words, applying the trick to three loaves turns them into . For example, if the order is and the trick is applied to at positions , the order becomes .
Given the current order of the loaves and the order the boss wants, write a program that decides whether the desired order can be reached using only this trick.
Input
The first line contains the number of loaves . The second line gives the current order of the loaves, and the third line gives the order the boss wants, each separated by spaces. The loaves are labeled with distinct integers from to ; no two loaves share a label.
Output
Print Possible if the boss's desired order can be produced using only the trick, or Impossible otherwise.