eolymp
bolt
Try our new interface for solving problems
Problems

Bread Sorting

Bread Sorting

\includegraphics{https://static.e-olymp.com/content/57/57a29041e6561c1c45cbcaf150c9f4c261696d0a.jpg} Michael works in a bakery. At the end of his shift, his boss wants the breads sorted in a certain order. She can't seem to decide on which order, though – every day there seems to be a new one – to Michael’s despair. Michael has worked there for a while now and has learned a neat trick with his wooden bakery paddle. He can take three breads next to each other on his paddle and throw them up in the air such that when they land, the right-most has moved to the left-most position, and the two other breads have moved one place to the right. In other words, he can rotate to the right a subsequence of breads of length three. Before the end of the shift, his coworkers place the breads in a long line. Michael would like to sort the line of breads using his paddle trick. He can take any three consecutive breads along the line on his paddle, rotate them, and then put them back. Sometimes though, it does not matter how many times he uses his paddle – the line of bread just doesn’t seem to be possible to sort the way the boss wants... \InputFile The first line contains a positive integer $n~(3 \le n \le 10^5)$. Then two lines follow: on the first line, a permutation of the integers $1$ through $n$ describing the order in which the breads are lined up. On the second line, a permutation of the integers $1$ through $n$ describing how Michael’s boss wants the breads sorted. \OutputFile Print "\textbf{Possible}" if Michael can sort the breads with his paddle in the order prescribed by his boss. Otherwise print "\textbf{Impossible}".
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
1 3 4 2
4 3 2 1
Output example #1
Possible
Input example #2
6
1 2 3 4 5 6
6 5 4 3 2 1
Output example #2
Impossible
Source 2012 Nordic Collegiate Programming Contest, October 6, Problem B