Codeforces Round 332 (Div. 2)
B
Spongebob and Joke
Codeforces
1500
原题
← AC →
翻译中…

While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence $*a*_{1}, *a*_{2}, ..., *a*_{*m*}$ of length $*m*$, consisting of integers from $1$ to $*n*$, not necessarily distinct. Then he picked some sequence $*f*_{1}, *f*_{2}, ..., *f*_{*n*}$ of length $*n*$ and for each number $*a*_{*i*}$ got number $*b*_{*i*} = *f*_{*a*_{*i*}}$. To finish the prank he erased the initial sequence $*a*_{*i*}$.

翻译中…

It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 100 000$) — the lengths of sequences $*f*_{*i*}$ and $*b*_{*i*}$ respectively.

翻译中…

The second line contains $*n*$ integers, determining sequence $*f*_{1}, *f*_{2}, ..., *f*_{*n*}$ ($1 ≤ *f*_{*i*} ≤ *n*$).

翻译中…

The last line contains $*m*$ integers, determining sequence $*b*_{1}, *b*_{2}, ..., *b*_{*m*}$ $(1 ≤ *b*_{*i*} ≤ *n*)$.

翻译中…

Output

翻译中…

Print "Possible" if there is exactly one sequence $*a*_{*i*}$, such that $*b*_{*i*} = *f*_{*a*_{*i*}}$ for all $*i*$ from $1$ to $*m*$. Then print $*m*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*m*}$.

翻译中…

If there are multiple suitable sequences $*a*_{*i*}$, print "Ambiguity".

翻译中…

If Spongebob has made a mistake in his calculations and no suitable sequence $*a*_{*i*}$ exists, print "Impossible".

翻译中…

Note

翻译中…

In the first sample $3$ is replaced by $1$ and vice versa, while $2$ never changes. The answer exists and is unique.

翻译中…

In the second sample all numbers are replaced by $1$, so it is impossible to unambiguously restore the original sequence.

翻译中…

In the third sample $*f*_{*i*} ≠ 3$ for all $*i*$, so no sequence $*a*_{*i*}$ transforms into such $*b*_{*i*}$ and we can say for sure that Spongebob has made a mistake.

翻译中…

样例

Input #1
3 3
3 2 1
1 2 3
Output #1
Possible
3 2 1
InputCopy OutputCopy
Input #2
3 3
1 1 1
1 1 1
Output #2
Ambiguity
InputCopy OutputCopy
Input #3
3 3
1 2 1
3 3 3
Output #3
Impossible
InputCopy OutputCopy
题目信息
题号
599B
时间限制
2 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。