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".


-----Examples-----
Input
3 3
3 2 1
1 2 3

Output
Possible
3 2 1 

Input
3 3
1 1 1
1 1 1

Output
Ambiguity

Input
3 3
1 2 1
3 3 3

Output
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.

Difficulty: MEDIUM
Tags: Implementation

Starter code:

Solutions:
def calc(f, b):
	a = [0 for i in range(1000001)]
	ambiguity = False
	for i in range(len(f)):
		e = f[i]
		if a[e] == 0:
			a[e] = i + 1
		else:
			a[e] = -1
	r = []
	for e in b:
		if a[e] == 0:
			return 'Impossible'
		elif a[e] == -1:
			ambiguity = True
		r.append(a[e])
	if ambiguity:
		return 'Ambiguity'
	return 'Possible\n' + str.join(' ', list((str(e) for e in r)))
(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
b = list(map(int, input().split()))
print(calc(f, b))


(n, m) = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = [-1] * 100001
for i in range(n):
	if a[f[i]] != -1:
		a[f[i]] = -2
	else:
		a[f[i]] = i
for i in b:
	if a[i] == -1:
		print('Impossible')
		exit(0)
for i in b:
	if a[i] == -2:
		print('Ambiguity')
		exit(0)
print('Possible')
for i in b:
	print(a[i] + 1, end=' ')


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(n):
	f[i] = [f[i], i]
for i in range(m):
	b[i] = [b[i], i]
f.sort()
b.sort()
ans = [0] * m
j = 0
i = 0
flag = 0
while i < m and j < n:
	if b[i][0] < f[j][0]:
		flag = 1
		print('Impossible')
		break
	elif b[i][0] == f[j][0]:
		ans[b[i][1]] = f[j][1] + 1
		i += 1
		if j < n - 1 and f[j + 1][0] == f[j][0]:
			flag = 2
	else:
		j += 1
if i < m and flag != 1:
	print('Impossible')
elif flag == 2:
	print('Ambiguity')
elif flag == 0:
	print('Possible')
	print(*ans)


(n, m) = map(int, input().strip().split(' '))
f = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
hm = {}
for i in range(n):
	if hm.__contains__(f[i]):
		hm[f[i]].append(i)
	else:
		hm[f[i]] = []
		hm[f[i]].append(i)
a = [0] * m
fl = True
am = False
for i in range(m):
	if hm.__contains__(b[i]):
		a[i] = hm[b[i]][0]
		if len(hm[b[i]]) > 1:
			am = True
	else:
		fl = False
		break
if fl and am == False:
	print('Possible')
	out = ''
	for j in a:
		out += str(j + 1) + ' '
	print(out)
elif fl and am == True:
	print('Ambiguity')
else:
	print('Impossible')


(n, m) = map(int, input().split())
f = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = [-1] * 100001
for i in range(n):
	if a[f[i]] != -1:
		a[f[i]] = -2
	else:
		a[f[i]] = i
for i in b:
	if a[i] == -1:
		print('Impossible')
		exit(0)
for i in b:
	if a[i] == -2:
		print('Ambiguity')
		exit(0)
output = [a[i] + 1 for i in b]
print('Possible')
print(' '.join([str(x) for x in output]))


(n, m) = map(int, input().split())
domain = list(map(int, input().split()))
occurs = {}
for (pos, x) in enumerate(domain):
	occurs[x] = occurs.setdefault(x, []) + [pos]
range = list(map(int, input().split()))

def exit(message):
	print(message)
	import sys
	sys.exit()
result = []
ambiguous = False
for y in range:
	if y not in occurs:
		exit('Impossible')
	if len(occurs[y]) > 1:
		ambiguous = True
	result.append(occurs[y][0] + 1)
if ambiguous:
	exit('Ambiguity')
print('Possible')
print(' '.join(map(str, result)))


from collections import Counter
(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
b = list(map(int, input().split()))
(ctf, ctb) = (Counter(f), Counter(b))
possible = True
ambiguous = False
for (k, v) in list(ctb.items()):
	if k not in ctf:
		possible = False
	if ctf[k] >= 2:
		ambiguous = True
idx = {}
for (i, v) in enumerate(f):
	idx[v] = i + 1
if not possible:
	print('Impossible')
elif ambiguous:
	print('Ambiguity')
else:
	print('Possible')
	a = []
	for v in b:
		a.append(idx[v])
	print(' '.join(map(str, a)))


from collections import Counter
(n, m) = map(int, input().split())
ff = list(map(int, input().split()))
df = {int(v): i for (i, v) in enumerate(ff, 1)}
cnt = Counter(ff)
bb = list(map(int, input().split()))
try:
	ans = ' '.join((str(df[b]) for b in bb))
	if any((cnt[b] > 1 for b in bb)):
		print('Ambiguity')
	else:
		print('Possible')
		print(ans)
except KeyError:
	print('Impossible')


read = lambda : map(int, input().split())
(n, m) = read()
f = list(read())
b = list(read())
c = [list() for i in range(n + 1)]
for i in range(n):
	c[f[i]].append(i + 1)
a = [0] * m
ans = 'Possible'
for i in range(m):
	if len(c[b[i]]) == 0:
		print('Impossible')
		exit()
	if len(c[b[i]]) > 1:
		ans = 'Ambiguity'
	if len(c[b[i]]) == 1:
		a[i] = c[b[i]][0]
print(ans)
if ans != 'Ambiguity':
	print(*a)


(n, m) = [int(x) for x in input().split(' ')]
F = [int(x) for x in input().split(' ')]
B = [int(x) for x in input().split(' ')]

def solve(F, B):
	D = {}
	for (i, e) in enumerate(F):
		if e not in D:
			D[e] = set()
		D[e].add(i)
	A = []
	p = None
	for (i, e) in enumerate(B):
		if e not in D:
			return 'Impossible'
		if len(D[e]) > 1:
			p = 'Ambiguity'
		A.append(str(list(D[e])[0] + 1))
	if p == None:
		return A
	else:
		return p
s = solve(F, B)
if type(s) == str:
	print(s)
else:
	print('Possible')
	print(' '.join(s))


def findSequence(N, arrayF, M, arrayB):
	positions = [-2] * N
	amb = False
	for i in range(N):
		val = arrayF[i]
		if val < 1 or val > N:
			return ('Impossible', [])
		pos = positions[val - 1]
		if pos >= -1:
			positions[val - 1] = -1
		else:
			positions[val - 1] = i + 1
	output = [0] * M
	for j in range(M):
		key = arrayB[j]
		if key < 1 or key > N:
			return ('Impossible', [])
		pos = positions[key - 1]
		if pos == -1:
			amb = True
		elif pos == -2:
			return ('Impossible', [])
		else:
			output[j] = pos
	if amb:
		return ('Ambiguity', [])
	return ('Possible', output)
(n, m) = input().split()
(n, m) = (int(n), int(m))
arrayF = input().split()
arrayF = [int(x) for x in arrayF]
arrayB = input().split()
arrayB = [int(x) for x in arrayB]
(status, output) = findSequence(n, arrayF, m, arrayB)
print(status)
if status == 'Possible':
	print(' '.join([str(x) for x in output]))


R = lambda : map(int, input().split())
(n, m) = R()
(f, b) = (R(), list(R()))
from collections import defaultdict

def solve(f, b):
	df = defaultdict(list)
	for (i, fi) in enumerate(f, 1):
		df[fi].append(i)
	r = []
	for bi in b:
		if bi not in df:
			print('Impossible')
			return
	for bi in b:
		if len(df[bi]) > 1:
			print('Ambiguity')
			return
	for bi in b:
		r.append(df[bi][0])
	print('Possible')
	print(' '.join(map(str, r)))
solve(f, b)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
f_back = dict()
keys = set()
for i in range(n):
	if f[i] in keys:
		f_back[f[i]] = -1
	else:
		f_back[f[i]] = i
		keys.add(f[i])
state = 1
a = [0] * m
for i in range(m):
	if b[i] in keys:
		if state == 1:
			if f_back[b[i]] == -1:
				state = 2
			else:
				a[i] = f_back[b[i]] + 1
	else:
		state = 0
		break
if state == 1:
	print('Possible')
	print(' '.join(map(str, a)))
elif state == 2:
	print('Ambiguity')
else:
	print('Impossible')


from collections import Counter
get = lambda : list(map(int, input().split()))
(n, m) = get()
a = get()
b = get()
Q = Counter(a)
ans = []
A = dict(((j, i) for (i, j) in enumerate(a)))
flag = False
for i in b:
	if Q[i] == 0:
		print('Impossible')
		break
	if Q[i] != 1:
		flag = True
	ans.append(A[i] + 1)
else:
	if flag:
		print('Ambiguity')
	else:
		print('Possible')
		print(' '.join(map(str, ans)))


import sys
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = [0 for i in range(n + 1)]
indx = [-1 for i in range(n + 1)]
for i in range(n):
	cnt[f[i]] += 1
	indx[f[i]] = i + 1
ans = []
for num in b:
	if cnt[num] == 0:
		print('Impossible')
		sys.exit()
for num in b:
	if cnt[num] >= 2:
		print('Ambiguity')
		sys.exit()
	ans.append(indx[num])
print('Possible')
for num in ans:
	print(num, end=' ')


from collections import defaultdict
(n, m) = [int(r) for r in input().split()]
f = [int(r) for r in input().split()]
b = [int(r) for r in input().split()]
count_f = defaultdict(int)
count_b = defaultdict(int)
loc_in_f = {}
i = 1
for z in f:
	count_f[z] += 1
	loc_in_f[z] = i
	i += 1
for z in b:
	count_b[z] += 1
valid = all((count_f[z] >= 1 for z in count_b))
ambiguous = any((count_f[z] > 1 for z in count_b))
if not valid:
	print('Impossible')
elif ambiguous:
	print('Ambiguity')
else:
	print('Possible')
	for z in b:
		print(loc_in_f[z], end=' ')


import sys

def main():
	(n, m) = map(int, input().split())
	f = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	f = [0] + f
	b = [0] + b
	imf = set()
	d = set()
	g = [0] * (n + 1)
	for i in range(1, n + 1):
		if f[i] in imf:
			d.add(f[i])
		else:
			imf.add(f[i])
		g[f[i]] = i
	for i in range(1, m + 1):
		if b[i] not in imf:
			print('Impossible')
			return
	for i in range(1, m + 1):
		if b[i] in d:
			print('Ambiguity')
			return
	print('Possible')
	for i in range(1, m):
		print(g[b[i]], end=' ')
	print(g[b[m]])
main()


(n, m) = map(int, input().split())
(f, b) = ([int(e) for e in input().split()], [int(e) for e in input().split()])
(F, l) = ({}, [])
for (e, u) in enumerate(f):
	if u in F:
		F[u] = 0
	else:
		F[u] = e + 1
for e in b:
	if e in F:
		if F[e] > 0:
			l += [F[e]]
	else:
		print('Impossible')
		break
else:
	if len(l) == m:
		print('Possible')
		print(*l)
	else:
		print('Ambiguity')


import unittest
import sys

class Sponge:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n, self.m] = map(int, uinput().split())
		self.numf = list(map(int, uinput().split()))
		self.numb = list(map(int, uinput().split()))
		self.fd = {}
		self.fdn = {}
		for (i, n) in enumerate(self.numf):
			self.fd[n] = self.fd.setdefault(n, 0) + 1
			self.fdn[n] = i + 1
		self.bd = {}
		for (i, n) in enumerate(self.numb):
			self.bd[n] = self.bd.setdefault(n, 0) + 1

	def calculate(self):
		result = []
		for n in self.numb:
			if n not in self.fd:
				return 'Impossible'
		for n in self.numb:
			if self.fd[n] > 1:
				return 'Ambiguity'
			result.append(self.fdn[n])
		return 'Possible\n' + ' '.join(map(str, result))

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '3 3\n3 2 1\n1 2 3'
		d = Sponge(test)
		self.assertEqual(d.n, 3)
		self.assertEqual(d.m, 3)
		self.assertEqual(d.numf, [3, 2, 1])
		self.assertEqual(d.numb, [1, 2, 3])
		self.assertEqual(Sponge(test).calculate(), 'Possible\n3 2 1')
		test = '3 3\n1 1 3\n1 2'
		self.assertEqual(Sponge(test).calculate(), 'Impossible')
		test = '3 3\n1 1 1\n1 1 1'
		self.assertEqual(Sponge(test).calculate(), 'Ambiguity')
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Sponge(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Sponge().calculate())


import sys
import math
input = sys.stdin.readline
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
c = 0
for i in range(n):
	x = f[i]
	if x in d:
		d[x].append(i)
	else:
		d[x] = [i]
ans = []
for i in range(m):
	x = b[i]
	if x in d:
		if len(d[x]) == 1 and c == 0:
			ans.append(d[x][0] + 1)
		else:
			c = 1
	else:
		c = 2
		break
if c == 2:
	print('Impossible')
	exit()
if c == 1:
	print('Ambiguity')
	exit()
print('Possible')
print(*ans)


(n, m) = map(int, input().split())
f = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
list = [0] * 100001
for i in range(n):
	if list[f[i]] != 0:
		list[f[i]] = -1
	else:
		list[f[i]] = i + 1
for item in b:
	if list[item] == 0:
		print('Impossible')
		return
for item in b:
	if list[item] == -1:
		print('Ambiguity')
		return
output = [list[i] for i in b]
print('Possible')
print(' '.join([str(x) for x in output]))


from collections import defaultdict
try:
	while True:
		(n, m) = list(map(int, input().split()))
		f = list(map(int, input().split()))
		b = list(map(int, input().split()))
		d = [[] for i in range(n + 1)]
		for (i, x) in enumerate(f, 1):
			d[x].append(i)
		a = [None] * m
		ambigious = False
		for i in range(m):
			x = d[b[i]]
			if not x:
				print('Impossible')
				break
			if len(x) != 1:
				ambigious = True
			else:
				a[i] = x[0]
		else:
			if ambigious:
				print('Ambiguity')
			else:
				print('Possible')
				print(' '.join(map(str, a)))
except EOFError:
	pass


def main():
	(n, m) = [int(i) for i in input().split()]
	f = [-1] + [int(i) for i in input().split()]
	b = [-1] + [int(i) for i in input().split()]
	d = [-1] * (n + 1)
	cnt = [0] * (n + 1)
	for i in range(1, n + 1):
		cnt[f[i]] += 1
		d[f[i]] = i
	a = [-1] * (m + 1)
	for i in range(1, m + 1):
		a[i] = d[b[i]]
		if d[b[i]] == -1:
			print('Impossible')
			return
	for i in range(1, m + 1):
		if cnt[b[i]] > 1:
			print('Ambiguity')
			return
	print('Possible')
	print(' '.join((str(i) for i in a[1:])))
main()


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a = [-1] * m
	c = [-1] * (n + 1)
	for (i, item) in enumerate(f):
		if c[item] == -1:
			c[item] = []
		c[item].append([i + 1])
	flag = 1
	for i in range(m):
		if c[b[i]] == -1:
			flag = 0
			break
		elif len(c[b[i]]) > 1:
			flag = 2
		else:
			a[i] = c[b[i]][0][0]
	if flag:
		if flag == 1:
			print('Possible')
			print(*a)
		else:
			print('Ambiguity')
	else:
		print('Impossible')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import itertools
(n, m) = [int(i) for i in input().split()]
inp = [int(i) for i in input().split()]
f = [list() for i in range(n + 2)]
for i in range(len(inp)):
	if 1 <= inp[i] <= n:
		f[inp[i]].append(i)
b = [int(i) for i in input().split()]
for item in b:
	if not f[item]:
		print('Impossible')
		exit(0)
ans = []
for item in b:
	if len(f[item]) <= 1:
		ans.append(str(f[item][0] + 1))
	else:
		print('Ambiguity')
		exit(0)
print('Possible')
print(' '.join(ans))


(n, m) = input().split()
n = int(n)
m = int(m)
temp_f = input().split()
temp_b = input().split()
(f, b, fff) = (dict(), dict(), dict())
amb = False
imp = False
for (t, word) in enumerate(temp_f):
	f[word] = (t + 1, f.get(word, (0, 0))[1] + 1)
	fff[word] = fff.get(word, 0) + 1
for word in temp_b:
	b[word] = b.get(word, 0) + 1
	if word not in fff:
		imp = True
		break
	if fff[word] > 1:
		amb = True
if imp:
	print('Impossible')
elif amb:
	print('Ambiguity')
else:
	print('Possible')
	for word in temp_b:
		print(f[word][0], end=' ')
	print('')


import sys
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
a = list(map(int, input().split()))
dic = {}
for i in range(n):
	if f[i] in dic:
		dic[f[i]] = -1
	else:
		dic[f[i]] = i
ans = []
ambflag = 0
for i in range(m):
	if not a[i] in dic:
		print('Impossible')
		sys.exit()
	if dic[a[i]] == -1:
		ambflag = 1
	ans.append(str(dic[a[i]] + 1))
if ambflag == 1:
	print('Ambiguity')
	sys.exit()
print('Possible')
print(' '.join(ans))


def solve(fs, bs, n, m):
	set_fs = set(fs)
	set_bs = set(bs)
	if not all((b in set_fs for b in set_bs)):
		return ('Impossible',)
	ys = [f for f in fs if f in set_bs]
	if len(ys) != len(set(ys)):
		return ('Ambiguity',)
	d = {f: i for (i, f) in enumerate(fs, 1) if f in set_bs}
	return ('Possible', [d[b] for b in bs])

def main():
	[n, m] = map(int, input().strip().split())
	fs = [int(_c) for _c in input().strip().split()]
	bs = [int(_c) for _c in input().strip().split()]
	assert len(fs) == n
	assert len(bs) == m
	result = solve(fs, bs, n, m)
	if len(result) == 1:
		print(result[0])
	else:
		print(result[0])
		print(*result[1])
main()


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = [list() for i in range(n + 1)]
for i in range(n):
	cnt[f[i]].append(i + 1)
a = [0] * m
res = 'Possible'
for i in range(m):
	if len(cnt[b[i]]) == 0:
		print('Impossible')
		exit()
	if len(cnt[b[i]]) > 1:
		res = 'Ambiguity'
	if len(cnt[b[i]]) == 1:
		a[i] = cnt[b[i]][0]
print(res)
if res == 'Possible':
	print(*a)


from collections import defaultdict
god = defaultdict(int)
(n, m) = [int(i) for i in input().split(' ')]
fuck = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
for i in fuck:
	god[i] += 1
ans = []
f = dict(zip(fuck, range(1, n + 1)))
s = set(fuck)
answ = 'Possible'
for i in b:
	if not i in s:
		answ = 'Impossible'
		break
	elif god[i] > 1:
		answ = 'Ambiguity'
	else:
		ans.append(f[i])
print(answ)
if answ == 'Possible':
	for i in ans:
		print(i, end=' ')


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
c = {}
for i in range(n):
	if c.get(f[i]):
		c[f[i]].append(i + 1)
	else:
		c[f[i]] = [i + 1]
a = []
k = 1
for i in range(m):
	if c.get(b[i]):
		k *= len(c[b[i]])
		a.append(c[b[i]][0])
	else:
		print('Impossible')
		exit()
if k > 1:
	print('Ambiguity')
else:
	print('Possible')
	print(*a)


def __starting_point():
	(n, m) = [int(x) for x in input().split()]
	f = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	fdict = dict()
	for (i, fi) in enumerate(f):
		if fi in fdict:
			fdict[fi].append(i)
		else:
			fdict[fi] = [i]
	a = []
	res = 'Possible'
	for (i, bi) in enumerate(b):
		if bi in fdict:
			a_options = fdict[bi]
			a.append(a_options[0])
			if len(a_options) > 1:
				res = 'Ambiguity'
		else:
			res = 'Impossible'
			break
	print(res)
	if res == 'Possible':
		if len(a) != m:
			print('len(a) != m , len(a) =', len(a))
		print(' '.join([str(x + 1) for x in a]))
	elif res == 'Ambiguity':
		if len(a) != m:
			print('len(a) != m , len(a) =', len(a))
__starting_point()


from collections import Counter

def mp():
	return map(int, input().split())

def lt():
	return list(map(int, input().split()))

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)

def listring(l):
	return ' '.join([str(x) for x in l])

def printlist(l):
	print(' '.join([str(x) for x in l]))
(n, m) = mp()
f = lt()
b = lt()
(cf, cb) = (Counter(f), Counter(b))
possible = True
ambiguity = False
for (c, d) in cb.items():
	if not c in cf:
		possible = False
	if cf[c] >= 2:
		ambiguity = True
r = {}
for (x, y) in enumerate(f, 1):
	r[y] = x
if not possible:
	print('Impossible')
elif ambiguity:
	print('Ambiguity')
else:
	print('Possible')
	a = [r[y] for y in b]
	printlist(a)


__author__ = 'MoonBall'
import sys
T = 1

def process():
	(N, M) = list(map(int, input().split()))
	f = map(int, input().split())
	b = map(int, input().split())
	fc = {}
	for (idx, fv) in enumerate(f):
		fc[fv] = (1, idx) if not fc.get(fv) else (fc[fv][0] + 1, idx)
	a = []
	failed = False
	multi = False
	for bv in b:
		if not fc.get(bv):
			failed = True
			continue
		if fc[bv][0] > 1:
			multi = True
			continue
		a.append(fc[bv][1] + 1)
	if failed:
		print('Impossible')
	elif multi:
		print('Ambiguity')
	else:
		print('Possible')
		print(' '.join(map(str, a)))
for _ in range(T):
	process()


def main():
	(n, m) = map(int, input().split())
	ff = list(map(int, input().split()))
	bb = list(map(int, input().split()))
	(xlat, res) = ([-1] * (n + 1), [0] * m)
	for (i, f) in enumerate(ff, 1):
		x = xlat[f]
		if x == -1:
			xlat[f] = i
		elif x > -1:
			xlat[f] = -2
	s = 'Possible'
	for (i, b) in enumerate(bb):
		x = xlat[b]
		if x >= 0:
			res[i] = x
		else:
			if x == -1:
				print('Impossible')
				return
			s = 'Ambiguity'
	print(s)
	if s == 'Possible':
		print(' '.join(map(str, res)))
main()


ans = []

def func(f, b):
	global ans
	dic = {}
	k = 0
	for i in range(len(f)):
		dic[f[i]] = -1
	for i in range(len(f)):
		if dic[f[i]] != -1:
			dic[f[i]] = -10
		else:
			dic[f[i]] = i + 1
	for i in b:
		if i in dic:
			if dic[i] == -10:
				k = 1
			ans.append(dic[i])
		else:
			return 3
	if k:
		return 2
	return 1
q = list(map(int, input().split()))
(n, m) = (q[0], q[1])
f = list(map(int, input().split()))
b = list(map(int, input().split()))
p = func(f, b)
if p == 1:
	print('Possible')
	for i in ans:
		print(i, end=' ')
elif p == 2:
	print('Ambiguity')
else:
	print('Impossible')


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
a = []
c = [-1] * (n + 1)
for i in range(n):
	if c[f[i]] != -1:
		c[f[i]] = -2
	else:
		c[f[i]] = i + 1
am = False
for i in range(m):
	if c[b[i]] == -2:
		am = True
	if c[b[i]] == -1:
		print('Impossible')
		exit()
	a.append(str(c[b[i]]))
if am:
	print('Ambiguity')
	exit()
print('Possible')
print(' '.join(a))


(n, m) = map(int, input().split())
f = []
b = []
x = []
y = []
f = list(map(int, input().split()))
for i in range(n):
	x.append(0)
	y.append(0)
for i in range(n):
	x[f[i] - 1] = x[f[i] - 1] + 1
	y[f[i] - 1] = i + 1
b = list(map(int, input().split()))
amb = 0
imp = 0
for i in range(m):
	if x[b[i] - 1] > 1:
		amb = 1
	elif x[b[i] - 1] == 0:
		imp = 1
if imp > 0:
	print('Impossible')
elif amb > 0:
	print('Ambiguity')
elif 1 == 1:
	print('Possible')
	for i in range(m):
		print(str(y[b[i] - 1]) + ' ', end='')


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
s1 = set(f)
s2 = set(b)
ans = []
if s2 <= s1:
	d = {}
	for i in range(len(f)):
		if f[i] in d:
			d[f[i]].append(i + 1)
		else:
			d[f[i]] = [i + 1]
	for u in b:
		if u in d and len(d[u]) > 1:
			print('Ambiguity')
			break
		elif u in d:
			ans.append(d[u][0])
	else:
		print('Possible')
		print(' '.join(map(str, ans)))
else:
	print('Impossible')


from collections import Counter
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
fs = set(f)
bs = set(b)
if fs & bs != bs:
	print('Impossible')
	exit(0)
ct = set((k for (k, v) in filter(lambda k: k[1] > 1, Counter(f).items())))
if len(bs.intersection(ct)) > 0:
	print('Ambiguity')
	exit(0)
h = {}
for (i, x) in enumerate(f):
	h[x] = str(i + 1)
print('Possible')
print(' '.join(list(map(lambda xx: h[xx], b))))


from sys import *
inp = lambda : stdin.readline()

def main():
	(n, m) = [int(i) for i in inp().split()]
	(f, b) = ([int(i) for i in inp().split()], [int(i) for i in inp().split()])
	d = {}
	for i in range(len(f)):
		if f[i] not in d:
			d[f[i]] = []
		d[f[i]].append(i + 1)
	(sb, fb) = (set(b), set(f))
	ans = []
	if not sb.issubset(fb):
		print('Impossible')
	else:
		for i in b:
			if len(d[i]) > 1:
				print('Ambiguity')
				exit(0)
			else:
				ans.append(d[i][0])
		print('Possible')
		print(' '.join([str(i) for i in ans]))
main()


__author__ = 'sandeepmellacheruvu'
from collections import defaultdict
(n, m) = input().split()
n = int(n)
m = int(m)
f = list(map(int, input().split()))
b = list(map(int, input().split()))
map = dict(zip(f, [-1] * n))
count = defaultdict(int)
for i in range(len(f)):
	num = f[i]
	map[num] = i + 1
	count[num] += count[num] + 1
isImp = False
isAmb = False
c = []
for i in range(len(b)):
	num = b[i]
	if count[num] == 0:
		isImp = True
		break
	elif count[num] > 1:
		isAmb = True
	else:
		c.append(map[num])
if isImp == True:
	print('Impossible')
elif isAmb == True:
	print('Ambiguity')
else:
	print('Possible')
	for k in range(len(c)):
		print(c[k], end=' ')
	print()


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [-1] * 100050
for i in range(n):
	if a[f[i]] == -1:
		a[f[i]] = i
	else:
		a[f[i]] = -2
for i in b:
	if a[i] == -1:
		exit(print('Impossible'))
for i in b:
	if a[i] == -2:
		exit(print('Ambiguity'))
print('Possible')
for i in b:
	print(a[i] + 1, end=' ')


from collections import Counter

def solve(n, m, f, b):
	d1 = Counter(f)
	d2 = Counter(b)
	(flag1, flag2) = (True, False)
	for (k, v) in d2.items():
		if k not in d1:
			flag1 = False
			break
	if not flag1:
		print('Impossible')
		return
	for (k, v) in d2.items():
		if d1[k] > 1:
			flag2 = True
			break
	if flag2:
		print('Ambiguity')
		return
	d = {k: pos for (pos, k) in enumerate(f, start=1)}
	print('Possible')
	for value in b:
		print(d[value], end=' ')
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
solve(n, m, f, b)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
a = []
b1 = set(b)
f1 = set(f)
for i in b1:
	if i not in f1:
		print('Impossible')
		break
else:
	nikita_pidor = {}
	for i in range(n):
		if f[i] not in nikita_pidor:
			nikita_pidor[f[i]] = [1, i]
		else:
			nikita_pidor[f[i]][0] += 1
	for i in range(m):
		if nikita_pidor[b[i]][0] > 1:
			print('Ambiguity')
			break
		a.append(nikita_pidor[b[i]][1] + 1)
		f[nikita_pidor[b[i]][1]] = -15
	else:
		print('Possible')
		print(*a)


def BuildHashTable(n, f):
	htab = []
	for i in range(n):
		htab[len(htab):] = [[0, -1]]
	for i in range(n):
		j = f[i]
		htab[j - 1][0] = htab[j - 1][0] + 1
		if htab[j - 1][1] == -1:
			htab[j - 1][1] = i + 1
		else:
			htab[j - 1][1] = -2
	return htab

def LookupAndTell(htab, b):
	state = 1
	i = 0
	a = [0] * len(b)
	while i < len(b) and state != 0:
		j = b[i]
		if htab[j - 1][0] == 0:
			print('Impossible')
			state = 0
		elif htab[j - 1][1] < -1:
			state = 2
		else:
			a[i] = htab[j - 1][1]
		i = i + 1
	if state == 1:
		print('Possible')
		print(' '.join(map(str, a)))
	elif state == 2:
		print('Ambiguity')
	return

def CheckSeq(n, m, f, b):
	status = 1
	if len(f) != n or len(b) != m:
		print('Impossible')
		status = 0
	if status == 1:
		for i in range(n):
			if f[i] > n or f[i] < 1:
				print('Impossible')
				status = 0
		for j in range(m):
			if b[j] > n or b[j] < 1:
				print('Impossible')
				status = 0
	return status

def main():
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	b = list(map(int, input().split()))
	check = CheckSeq(n, m, f, b)
	if check == 1:
		h = BuildHashTable(n, f)
		LookupAndTell(h, b)
main()


def first(s):
	return next(iter(s))

def invert(n, fs, bs):
	finv = [set() for _ in range(n)]
	for (i, fi) in enumerate(fs):
		finv[fi - 1].add(i)
	ambiguous = False
	as_ = []
	for b in bs:
		s = finv[b - 1]
		if not s:
			return ('Impossible', None)
		if len(s) > 1:
			ambiguous = True
		as_.append(first(s) + 1)
	return ('Ambiguity' if ambiguous else 'Possible', as_)
(n, m) = map(int, input().split())
fs = tuple(map(int, input().split()))
bs = tuple(map(int, input().split()))
(result, seq) = invert(n, fs, bs)
print(result)
if result == 'Possible':
	print(' '.join(map(str, seq)))


from collections import defaultdict
(n, m) = tuple((int(x) for x in input().split()))
fs = tuple((int(x) for x in input().split()))
bs = tuple((int(x) for x in input().split()))

def solve(n, m, fs, bs):
	backwards = defaultdict(set)
	for i in range(n):
		backwards[fs[i]].add(i + 1)
	original = []
	result = 'Possible'
	for b in bs:
		if len(backwards[b]) == 0:
			print('Impossible')
			return
		if len(backwards[b]) > 1:
			result = 'Ambiguity'
		original.append(list(backwards[b])[0])
	print(result)
	if result == 'Possible':
		print(' '.join(('%s' % o for o in original)))
solve(n, m, fs, bs)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
countF = [0] * n
countB = [0] * n
for elem in f:
	countF[elem - 1] += 1
for elem in b:
	countB[elem - 1] += 1
isAmbiguous = False
isImpossible = False
a = [0] * m
for i in range(n):
	if countF[i] == 0 and countB[i] != 0:
		isImpossible = True
		break
	if countF[i] >= 2 and countB[i] != 0:
		isAmbiguous = True
if isImpossible:
	print('Impossible')
elif isAmbiguous:
	print('Ambiguity')
else:
	FInverse = [0] * n
	for i in range(n):
		FInverse[f[i] - 1] = i
	for i in range(m):
		a[i] = FInverse[b[i] - 1] + 1
	ans = []
	for elem in a:
		ans.append(str(elem))
	print('Possible')
	print(' '.join(ans))


(n, m) = [int(ii) for ii in input().split(' ')]
f = [int(ii) - 1 for ii in input().split(' ')]
b = [int(ii) - 1 for ii in input().split(' ')]
mp = dict([])
for i in range(n):
	if f[i] in mp:
		mp[f[i]].append(i)
	else:
		mp[f[i]] = [i]
res = 'Possible'
for i in range(m):
	if b[i] in mp:
		if len(mp[b[i]]) > 1:
			res = 'Ambiguity'
	else:
		res = 'Impossible'
		break
print(res)
if res == 'Possible':
	print(' '.join((str(mp[b[i]][0] + 1) for i in range(m))))


def mapin():
	return map(int, input().split())
(n, m) = mapin()
f = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a = [0] * n
kk = [0] * n
ans = 0
for i in range(n):
	if kk[f[i] - 1] == 0:
		kk[f[i] - 1] = i + 1
	else:
		kk[f[i] - 1] = -1
kkk = [0] * n
kkkk = [0] * n
for i in range(m):
	kkk[b[i] - 1] = 1
for i in range(n):
	kkkk[f[i] - 1] = 1
for i in range(n):
	if kkk[i] == 1 and kkkk[i] == 0:
		ans = 2
		break
if ans == 1:
	print('Ambiguity')
elif ans == 2:
	print('Impossible')
else:
	anss = []
	for i in range(m):
		temp = kk[b[i] - 1]
		if temp == -1:
			print('Ambiguity')
			exit()
		anss.append(temp)
	print('Possible')
	print(*anss)


from collections import Counter
(n, m) = map(int, input().split())
F = list(map(int, input().split()))
B = list(map(int, input().split()))
x = Counter(F)
y = Counter(B)
ok = True
ambi = False
res = []
for i in y.keys():
	if x[i] == 0:
		ok = False
	if x[i] >= 2:
		ambi = True
d = dict()
for i in range(len(F)):
	if F[i] in d.keys():
		continue
	else:
		d[F[i]] = i + 1
if ok == False:
	print('Impossible')
elif ambi == True:
	print('Ambiguity')
else:
	print('Possible')
	res = []
	for i in range(len(B)):
		res.append(d[B[i]])
	print(*res)


input()
(f, b) = [list(map(int, input().split())) for _ in range(2)]
d = {}
z = []
for i in range(len(f)):
	if f[i] in d:
		z.append(f[i])
	d[f[i]] = i + 1
ans = 2
for it in b:
	if it not in d:
		ans = 0
if ans != 0:
	if len(d) < len(f):
		for it in z:
			if it in b:
				ans = 1
				break
if ans == 2:
	print('Possible')
	print(' '.join((str(d[i]) for i in b)))
elif ans == 1:
	print('Ambiguity')
else:
	print('Impossible')


import sys
try:
	fin = open('in')
except:
	fin = sys.stdin
input = fin.readline
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
freq = [0] * 100010
for u in f:
	freq[u] += 1
if any((freq[t] == 0 for t in b)):
	print('Impossible')
elif any((freq[x] > 1 for x in b)):
	print('Ambiguity')
else:
	print('Possible')
	mm = {}
	for i in range(1, n + 1):
		mm[f[i - 1]] = i
	print(*[mm[k] for k in b])


from collections import defaultdict as ddict
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
idf = ddict(list)
for i in range(n):
	idf[f[i]].append(i)
ans = [0] * m
flag_amb = False
for i in range(m):
	if len(idf[b[i]]) == 0:
		print('Impossible')
		exit()
	if len(idf[b[i]]) > 1:
		flag_amb = True
	ans[i] = idf[b[i]][0] + 1
if flag_amb:
	print('Ambiguity')
else:
	print('Possible')
	print(' '.join(map(str, ans)))


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
f_count = [0 for i in range(n + 1)]
f_pos = [0 for i in range(n + 1)]
for i in range(n):
	f_pos[f[i]] = i + 1
	f_count[f[i]] += 1
ans = []
Ambiguity = False
Impossible = False
for i in range(m):
	if f_count[b[i]] == 1:
		ans.append(f_pos[b[i]])
	elif f_count[b[i]] == 0:
		Impossible = True
		break
	else:
		Ambiguity = True
if Impossible:
	print('Impossible')
elif Ambiguity:
	print('Ambiguity')
else:
	print('Possible')
	print(*ans)


import sys
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
f2 = [0] * 100001
a = [0] * m
for i in range(n):
	if f2[f[i]] != 0:
		f2[f[i]] = -1
	else:
		f2[f[i]] = i + 1
imp = amb = 0
for i in range(m):
	if f2[b[i]] == 0:
		imp = 1
		print('Impossible')
		break
if imp != 1:
	for num in b:
		if f2[num] == -1:
			print('Ambiguity')
			amb = 1
			break
if imp == 0 and amb == 0:
	for i in range(m):
		a[i] = f2[b[i]]
	print('Possible')
	print(*a, sep=' ')


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
b1 = set(b)
f1 = set(f)
u = 0
for i in b1:
	if i not in f1:
		print('Impossible')
		u = 1
		break
if not u:
	d = {}
	for i in range(n):
		if f[i] not in d:
			d[f[i]] = i + 1
		else:
			d[f[i]] = -1
	w = []
	v = 0
	for i in b:
		if d[i] == -1:
			print('Ambiguity')
			v = 1
			break
		else:
			w.append(d[i])
	if not v:
		print('Possible')
		print(*w)


import collections
(n, m) = map(int, input().split())
fs = list(map(int, input().split()))
bs = list(map(int, input().split()))

def solve(n, m, fs, bs):
	if not is_possible(n, m, fs, bs):
		print('Impossible')
		return
	ans = solve2(n, m, fs, bs)
	if not ans:
		print('Ambiguity')
	else:
		print('Possible')
		print(*ans)

def is_possible(n, m, fs, bs):
	setf = set(fs)
	setb = set(bs)
	return setb <= setf

def solve2(n, m, fs, bs):
	finv = collections.defaultdict(set)
	for (i, f) in enumerate(fs):
		finv[f].add(i)
	As = []
	for b in bs:
		fb = finv[b]
		if len(fb) > 1:
			return False
		for a in fb:
			As.append(a + 1)
	return As
solve(n, m, fs, bs)