问题4111--Bread Sorting

4111: Bread Sorting

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 128 MB

题目描述

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…

输入

The first line of input contains a positive integer n, 3 <= n <= 100000 . Then two lines follow: On the first line, a permutation of the integers 1through ndescribing 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.

输出

Output “Possible” if Michael can sort the breads with his paddle in the order prescribed by his boss, otherwise “Impossible”.

样例输入 Copy

4
1 3 4 2
4 3 2 1
6
1 2 3 4 5 6
6 5 4 3 2 1

样例输出 Copy

Possible
Impossible

来源/分类

NCPC 2012