| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 5000 |
| 문제명 | 빵 정렬 |
| 레벨 | 플래티넘 3 |
| 분류 |
불변성 |
| 시간복잡도 | O(n) |
| 인풋사이즈 | n<=100000 |
| 사용한 언어 | Python 3.13 |
| 제출기록 | 47088KB / 112ms |
| 최고기록 | 108ms |
| 해결날짜 | 2025/11/13 |
"""Solution code for "BOJ 5000. 빵 정렬".
- Problem link: https://www.acmicpc.net/problem/5000
- Solution link: http://www.teferi.net/ps/problems/boj/5000
"""
from teflib import permcycle
def main():
_n = int(input())
cur_order = [int(x) - 1 for x in input().split()]
target_order = [int(x) - 1 for x in input().split()]
cur_parity = permcycle.sign_of_permutation(cur_order)
target_parity = permcycle.sign_of_permutation(target_order)
print('Possible' if cur_parity == target_parity else 'Impossible')
if __name__ == '__main__':
main()