Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of trees. Sasha wants to match each tree with a sequence a0, a1, ..., ah, where h is the height of the tree, and ai equals to the number of vertices that are at distance of i edges from root. 

Unfortunately, this time Sasha's intuition was wrong, and there could be several trees matching the same sequence. To show it, you need to write a program that, given the sequence ai, builds two non-isomorphic rooted trees that match that sequence, or determines that there is only one such tree.

Two rooted trees are isomorphic, if you can reenumerate the vertices of the first one in such a way, that the index of the root becomes equal the index of the root of the second tree, and these two trees become equal.

The height of a rooted tree is the maximum number of edges on a path from the root to any other vertex.

Input

The first line contains a single integer h (2 ≤ h ≤ 105) — the height of the tree.

The second line contains h + 1 integers — the sequence a0, a1, ..., ah (1 ≤ ai ≤ 2·105). The sum of all ai does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence.

Output

If there is only one tree matching this sequence, print "perfect".

Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print <image> integers, the k-th of them should be the parent of vertex k or be equal to zero, if the k-th vertex is the root.

These treese should be non-isomorphic and should match the given sequence.

Examples

Input

2
1 1 1


Output

perfect


Input

2
1 2 2


Output

ambiguous
0 1 1 3 3
0 1 1 3 2

Note

The only tree in the first example and the two printed trees from the second example are shown on the picture:

<image>

Source: codeforces | Difficulty: MEDIUM
Tags: Tree algorithms

Constructive algorithms


Solutions:
h = int(input())
a = list(map(int, input().split()))
(p, c, f) = (0, 0, False)
(s1, s2) = ([], [])
for i in a:
	for j in range(i):
		s1.append(c)
		if j == i - 1 and (not f) and (p >= 2) and (i >= 2):
			f = True
			s2.append(c - 1)
		else:
			s2.append(c)
	p = i
	c += i
print('perfect' if not f else 'ambiguous')
if f:
	print(' '.join(map(str, s1)))
	print(' '.join(map(str, s2)))


h = int(input())
a = list(map(int, input().split()))
k = 0
for i in range(h):
	if a[i] > 1 and a[i + 1] > 1:
		k = i + 1
		break
else:
	print('perfect')
	exit()
print('ambiguous')
h1 = 1
p = 1
print(0, end=' ')
while h1 <= h:
	for i in range(a[h1]):
		print(p, end=' ')
	p += a[h1 - 1]
	h1 += 1
print('')
h1 = 1
p = 1
print(0, end=' ')
while h1 <= h:
	if h1 == k:
		for i in range(a[h1] - 1):
			print(p, end=' ')
		print(p + 1, end=' ')
		p += a[h1 - 1]
		h1 += 1
		continue
	for i in range(a[h1]):
		print(p, end=' ')
	p += a[h1 - 1]
	h1 += 1


n = int(input())
c = list(map(int, input().split()))
f = True
for i in range(n):
	if c[i + 1] > 1 and c[i] > 1:
		f = False
if f:
	print('perfect')
else:
	last = 0
	print('ambiguous')
	g = 0
	for i in range(n + 1):
		for j in range(c[i]):
			print(g, end=' ')
		g += c[i]
		if i > 0 and last == 0:
			if c[i] > 1 and c[i - 1] > 1:
				last = i
	print()
	g = 0
	for i in range(n + 1):
		if i != last:
			for j in range(c[i]):
				print(g, end=' ')
		else:
			for j in range(c[i] - 1):
				print(g, end=' ')
			print(g - 1, end=' ')
		g += c[i]


h = int(input())
d = list(map(int, input().split()))
f = True
ix = -1
c = 0
for i in range(len(d) - 1):
	if d[i] > 1 and d[i + 1] > 1:
		f = False
		ix = i
		break
	c += d[i]
if f:
	print('perfect')
else:
	print('ambiguous')
	b = 0
	s = 0
	for i in range(ix):
		for j in range(d[i]):
			print(b, end=' ')
		s += d[i]
		b = s
	for i in range(d[ix]):
		print(b, end=' ')
	s += d[ix]
	b = s
	for i in range(d[ix + 1]):
		print(b, end=' ')
	s += d[ix + 1]
	b = s
	for i in range(ix + 2, len(d)):
		for j in range(d[i]):
			print(b, end=' ')
		s += d[i]
		b = s
	print()
	b = 0
	s = 0
	for i in range(ix):
		for j in range(d[i]):
			print(b, end=' ')
		s += d[i]
		b = s
	for i in range(d[ix]):
		print(b, end=' ')
	s += d[ix]
	b = s
	for i in range(d[ix + 1] - 1):
		print(b, end=' ')
	print(b - 1, end=' ')
	s += d[ix + 1]
	b = s
	for i in range(ix + 2, len(d)):
		for j in range(d[i]):
			print(b, end=' ')
		s += d[i]
		b = s


n = int(input().strip())
a = [int(x) for x in input().split()]
m = 0
for i in range(1, n):
	if a[i] > 1 and a[i + 1] > 1:
		print('ambiguous')
		m = i
		break
if m == 0:
	print('perfect')
else:
	count = 0
	for i in range(n + 1):
		curr = count
		for j in range(a[i]):
			print(curr, end=' ')
			count += 1
	print()
	count = 0
	for i in range(n + 1):
		curr = count
		for j in range(a[i]):
			if i == m + 1 and j == 0:
				print(curr - 1, end=' ')
			else:
				print(curr, end=' ')
			count += 1
	print()


h = int(input())
a = list(map(int, input().split()))
perfect = True
for i in range(1, len(a)):
	if a[i] != 1 and a[i - 1] != 1:
		perfect = False
print('perfect' if perfect else 'ambiguous')
ret1 = [0] * sum(a)
ret2 = [0] * sum(a)
node = 0
p = 0
if perfect == False:
	for i in range(len(a)):
		for j in range(a[i]):
			ret1[node] = p
			node += 1
		p = node
	p1 = 0
	p2 = 0
	node = 0
	for i in range(len(a)):
		for j in range(a[i]):
			if j & 1:
				ret2[node] = p1
			else:
				ret2[node] = p2
			node += 1
		p1 = node
		p2 = node
		if a[i] != 1:
			p1 = node
			p2 = node - 1
	print(' '.join((str(x) for x in ret1)))
	print(' '.join((str(x) for x in ret2)))


h = int(input())
a = list(map(int, input().split()))
s = 0
flag = 0
for i in range(0, h):
	if a[i] > 1 and a[i + 1] > 1:
		flag = 1
if flag == 0:
	print('perfect')
	exit(0)
si = sum(a)
d = []
led = 0
for i in range(h + 1):
	if led > si:
		break
	for j in range(a[i]):
		d.append(s)
		led += 1
	s += a[i]
j = 0
for i in range(1, h + 1):
	if a[i] > 1 and a[i - 1] > 1:
		j = i
		break
sumu = sum(a[:j])
print('ambiguous')
print(*d[:si])
d[sumu + 1] -= 1
print(*d[:si])


n = int(input())
ar = list(map(int, input().split()))
b = False
c = False
for x in ar:
	if x > 1:
		if b == True:
			c = True
			break
		b = True
	else:
		b = False
if not c:
	print('perfect')
else:
	print('ambiguous')
	ar1 = []
	ar2 = []
	c = 0
	b = 0
	d = 0
	for x in range(n + 1):
		if ar[x] > 1:
			if b and (not d):
				for el in range(ar[x] - 1):
					ar1.append(c)
					ar2.append(c - 1)
				ar1.append(c)
				ar2.append(c)
				d = 1
			else:
				for el in range(ar[x]):
					ar1.append(c)
					ar2.append(c)
			b = True
		else:
			b = False
			for el in range(ar[x]):
				ar1.append(c)
				ar2.append(c)
		c += ar[x]
	print(*ar1)
	print(*ar2)


h = int(input())
a = list(map(int, input().split()))
ok = True
for i in range(h):
	if a[i] >= 2 and a[i + 1] >= 2:
		ok = False
		idx = i + 1
if ok:
	print('perfect')
else:
	print('ambiguous')
	ans = []
	p = 0
	for x in a:
		ans.extend([p] * x)
		p = len(ans)
	print(' '.join(map(str, ans)))
	ans[sum(a[:idx])] -= 1
	print(' '.join(map(str, ans)))


h = int(input())
A = list(map(int, input().split()))
f = False
for (i, a) in enumerate(A):
	if f and a != 1:
		f = None
		break
	else:
		f = a != 1
if f is not None:
	print('perfect')
else:
	T = []
	for (j, a) in enumerate(A):
		if j == i:
			x = len(T)
		T += [len(T)] * a
	print('ambiguous')
	print(' '.join(map(str, T)))
	T[x + 1] = x - 1
	print(' '.join(map(str, T)))


from sys import stdin as cin
from sys import stdout as cout

def main():
	h = int(cin.readline())
	a = list(map(int, cin.readline().split()))
	f = 1
	for i in range(h):
		if a[i] > 1 and a[i + 1] > 1:
			f = 0
			break
	if f:
		print('perfect')
		return
	print('ambiguous')
	s = sum(a)
	b = [0] * s
	c = [0] * s
	w = 1
	r = 1
	f = 1
	for i in range(1, len(a)):
		for j in range(a[i]):
			b[w] = r
			c[w] = r
			if f and a[i - 1] > 1 and (a[i] > 1):
				f = 0
				c[w] -= 1
			w += 1
		r = w
	print(*b)
	print(*c)
main()


n = int(input())
l = list(map(int, input().split()))
f = 0
for i in range(n):
	if l[i] > 1 and l[i + 1] > 1:
		ind = i
		f += 1
		break
if f == 0:
	print('perfect')
else:
	print('ambiguous')
	(l1, l2) = ([], [])
	cnt = 0
	for i in range(len(l)):
		for j in range(l[i]):
			l1.append(cnt)
		cnt += l[i]
	print(*l1)
	cnt1 = 0
	for i in range(len(l)):
		if i == ind + 1:
			k = cnt1 - 1
			for j in range(l[i] - 1):
				l2.append(cnt1)
			l2.append(k)
			cnt1 += l[i]
		else:
			for j in range(l[i]):
				l2.append(cnt1)
			cnt1 += l[i]
	print(*l2)


def print_iso(nnodes, counter):
	print('ambiguous')
	final_tree1 = []
	final_tree2 = []
	c = 0
	parent = 0
	for n in nnodes:
		if c != counter:
			for i in range(0, n):
				final_tree1.append(parent)
				final_tree2.append(parent)
		else:
			final_tree1.append(parent - 1)
			final_tree2.append(parent)
			for i in range(0, n - 1):
				final_tree1.append(parent)
				final_tree2.append(parent)
		parent += n
		c += 1
	final_tree1 = [str(i) for i in final_tree1]
	final_tree2 = [str(i) for i in final_tree2]
	print(' '.join(final_tree1))
	print(' '.join(final_tree2))

def main():
	height = int(input())
	nnodes = input()
	nnodes = nnodes.split(' ')
	nnodes = [int(i) for i in nnodes]
	perfect = True
	prev = 1
	counter = 0
	for n in nnodes:
		if n > 1 and prev > 1:
			print_iso(nnodes, counter)
			perfect = False
			break
		prev = n
		counter += 1
	if perfect:
		print('perfect')
main()


import sys
f = sys.stdin
n = f.readline()
n = int(n)
cl = f.readline().split()
cl = [int(x) for x in cl]
c_index = 0
p1 = ['0']
p2 = ['0']
ambiguous = False
cur_index = 1
for (i, c) in enumerate(cl):
	if i == 0:
		continue
	if i > 0 and cl[i - 1] > 1 and (c > 1):
		ambiguous = True
		p1 += [str(cur_index)] * c
		p2 += [str(cur_index - 1)] + [str(cur_index)] * (c - 1)
	else:
		p1 += [str(cur_index)] * c
		p2 += [str(cur_index)] * c
	cur_index += c
if ambiguous:
	print('ambiguous')
	print(' '.join(p1))
	print(' '.join(p2))
else:
	print('perfect')


def tree(h, a, special=False):
	ind = 0
	parent = [-1] * sum(a)
	bottom = []
	for i in range(a[-1]):
		bottom.append(ind)
		ind += 1
	prev = bottom
	for y in range(h - 1, -1, -1):
		root = ind
		ind += 1
		if special and a[y] > 1 and (a[y + 1] > 1):
			for node in prev[1:]:
				parent[node] = root
			parent[prev[0]] = root + 1
			special = False
		else:
			for node in prev:
				parent[node] = root
		nextlayer = [root]
		for i in range(a[y] - 1):
			nextlayer.append(ind)
			ind += 1
		prev = nextlayer
	return (parent, special)
h = int(input())
a = [int(x) for x in input().split()]
(p1, special) = tree(h, a)
(p2, special) = tree(h, a, special=True)
if not special:
	print('ambiguous')
	print(*[x + 1 for x in p1])
	print(*[x + 1 for x in p2])
else:
	print('perfect')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(inp())
	a = lis()
	cnt = False
	for i in range(1, n + 1):
		if a[i] > 1 and a[i - 1] > 1:
			cnt = True
	if not cnt:
		print('perfect')
		return
	print('ambiguous')
	ans = [0]
	par = 1
	for i in range(1, n + 1):
		for j in range(a[i]):
			ans.append(par)
		par += a[i - 1]
	ans2 = [0]
	par = 1
	for i in range(1, n + 1):
		for j in range(a[i] - 1):
			ans2.append(par)
		if a[i - 1] > 1:
			ans2.append(par + 1)
		else:
			ans2.append(par)
		par += a[i - 1]
	print(' '.join((str(ans[i]) for i in range(len(ans)))))
	print(' '.join((str(ans2[i]) for i in range(len(ans2)))))
testcase(1)


n = int(input())
arr = list(map(int, input().strip().split(' ')))
ans = 0
j = arr[1]
for i in range(2, n + 1):
	if j > 1 and arr[i] > 1:
		ans = 1
		break
	j = arr[i]
if ans == 0:
	print('perfect')
else:
	print('ambiguous')
	print(0, end=' ')
	for i in range(arr[1]):
		print(1, end=' ')
	prev = 1 + arr[1]
	for i in range(2, n + 1):
		for j in range(arr[i]):
			print(prev, end=' ')
		prev += arr[i]
	print()
	print(0, end=' ')
	for i in range(arr[1]):
		print(1, end=' ')
	k = arr[1]
	prev = 1 + arr[1]
	flag = 0
	for i in range(2, n + 1):
		if k > 1 and arr[i] > 1 and (flag == 0):
			print(prev - 1, end=' ')
			flag = 1
			for j in range(arr[i] - 1):
				print(prev, end=' ')
		else:
			for j in range(arr[i]):
				print(prev, end=' ')
		prev += arr[i]
		k = arr[i]
	print()


n = int(input())
a = list(map(int, input().split()))
pre = a[0]
index = -1
for i in range(1, n + 1):
	if pre >= 2 and a[i] >= 2:
		index = i
		break
	pre = a[i]
else:
	print('perfect')
	exit()
print('ambiguous')
N = sum(a)
R = [0]
for i in range(1, n + 1):
	k = len(R)
	for j in range(a[i]):
		R.append(k)
L = [0]
flag = False
for i in range(1, n + 1):
	k = len(L)
	m = 0
	if i == index:
		L.append(k - a[i - 1] + 1)
		m = 1
	for j in range(a[i] - m):
		L.append(k)
print(*R)
print(*L)


n = int(input())
a = list(map(int, input().split()))
ans = 0
f = 0
for i in range(1, n + 1):
	if a[i] >= 2 and a[i - 1] >= 2:
		f = i
		ans = 1
if ans == 0:
	print('perfect')
else:
	print('ambiguous')
	s1 = '0'
	s2 = '0'
	p = 0
	ans = 1
	for i in range(1, len(a)):
		s1 += (' ' + str(ans)) * a[i]
		ans += a[i]
	print(s1)
	ans = 1
	p = 0
	for i in range(1, len(a)):
		if i == f:
			s2 += ' ' + str(ans - 1)
			a[i] -= 1
			p = 1
		s2 += (' ' + str(ans)) * a[i]
		if p == 1:
			ans += 1
			p = 0
		ans += a[i]
	print(s2)


n = int(input())
h = [int(i) for i in input().split()]
flag = 0
for i in range(n):
	if h[i] >= 2 and h[i + 1] >= 2:
		flag = i
if flag:
	a = []
	c = 0
	for i in range(n + 1):
		for j in range(h[i]):
			a.append(c)
		c += h[i]
	b = []
	c = 0
	for i in range(n + 1):
		for j in range(h[i]):
			if i == flag + 1 and j == 0:
				b.append(c - 1)
			else:
				b.append(c)
		c += h[i]
	print('ambiguous')
	print(' '.join([str(i) for i in a]))
	print(' '.join([str(i) for i in b]))
else:
	print('perfect')


h = int(input())
a = list(map(int, input().split()))
for i in range(h):
	if a[i] != 1 and a[i + 1] != 1:
		I = i
		f = False
		break
else:
	f = True
if f:
	print('perfect')
else:
	print('ambiguous')
	(ans1, ans2) = ([0], [0])
	last_el = 1
	last_i = 0
	f = False
	for (i, el) in enumerate(a[1:]):
		for k in range(el):
			ans1.append(last_el)
			if k != el - 1:
				ans2.append(last_el)
		if i == I:
			ans2.append(last_el + 1)
			f = True
		else:
			ans2.append(last_el)
		last_i += a[i]
		last_el = last_i + 1
	print(' '.join(map(str, ans1)))
	print(' '.join(map(str, ans2)))


h = int(input())
l = [int(i) for i in input().split()]
n = 0
v = []
pc = []
k = l[0]
x = 0
z = 0
y = 0
b = [0]
b1 = ''
for i in range(h + 1):
	k = l[i]
	while k > 0:
		v.append(x)
		k -= 1
		z += 1
	pc.append(z)
	x += 1
for i in range(1, h + 1):
	y += l[i - 1]
	if l[i] > 1 and l[i - 1] > 1:
		n = 1
		print('ambiguous')
		for i in range(1, z):
			b.append(pc[v[i] - 1])
		for i in range(len(b)):
			b1 += str(b[i]) + ' '
		print(b1)
		b[y + 1] -= 1
		b1 = ''
		for i in range(len(b)):
			b1 += str(b[i]) + ' '
		print(b1)
		break
if n == 0:
	print('perfect')


n = int(input())
p = list(map(int, input().split()))

def check():
	global z
	for i in range(n):
		if p[i] != 1 and p[i + 1] != 1:
			z = i
			return True
	return False
z = 0
if check():
	print('ambiguous')
	x = 1
	s = ['0']
	zx = 0
	for i in range(1, n + 1):
		a = x
		for j in range(p[i]):
			s.append(str(a))
			x += 1
		if z == i and (not zx):
			z = len(s) + 1
			zx = x - 1
	print(' '.join(s))
	s[z] = str(zx)
	print(' '.join(s))
else:
	print('perfect')


n = int(input())
(*a,) = map(int, input().split())
(b, c) = ([0], [0])
cur = 1
for i in range(1, n + 1):
	for j in range(a[i]):
		b.append(cur)
	cur += a[i]
cur = 1
for i in range(1, n + 1):
	if a[i] > 1 and a[i - 1] > 1:
		c.append(cur - 1)
		for j in range(1, a[i]):
			c.append(cur)
	else:
		for j in range(a[i]):
			c.append(cur)
	cur += a[i]
if b == c:
	exit(print('perfect'))
print('ambiguous')
print(*b)
print(*c)


h = int(input())
nums = [int(x) for x in input().split()]
if not any([nums[i] > 1 and nums[i + 1] > 1 for i in range(h)]):
	print('perfect')
else:
	print('ambiguous')
	cur = 1
	flag = False
	print(0, end=' ')
	for l in range(1, h + 1):
		[print(cur, end=' ') for i in range(nums[l])]
		cur += nums[l]
	print()
	cur = 1
	flag = False
	print(0, end=' ')
	for l in range(1, h + 1):
		if not flag and nums[l] > 1 and (nums[l - 1] > 1):
			flag = True
			print(cur - 1, end=' ')
			[print(cur, end=' ') for i in range(nums[l] - 1)]
		else:
			[print(cur, end=' ') for i in range(nums[l])]
		cur += nums[l]


h = int(input())
arr = list(map(int, input().split()))
s = 0
flag = True
for i in range(0, h):
	if arr[i] > 1 and arr[i + 1] > 1:
		flag = False
if flag:
	print('perfect')
else:
	total = sum(arr)
	ch = []
	temp = 0
	for i in range(h + 1):
		if temp > total:
			break
		for j in range(arr[i]):
			ch.append(s)
			temp += 1
		s += arr[i]
	j = 0
	for i in range(1, h + 1):
		if arr[i] > 1 and arr[i - 1] > 1:
			j = i
			break
	tot2 = sum(arr[:j])
	print('ambiguous')
	ans1 = list(ch[:total])
	print(*ans1)
	ch[tot2 + 1] -= 1
	ans2 = list(ch[:total])
	print(*ans2)


def printarr(arr):
	n = len(arr)
	for i in range(n):
		print(arr[i], end=' ')
	print('')
h = int(input())
level = [0] + [int(i) for i in input().split()]
flag = 1
for i in range(1, h + 1):
	if level[i] > 1 and level[i + 1] > 1:
		flag = 0
		split = i + 1
if flag:
	print('perfect')
else:
	print('ambiguous')
	sums = [0]
	curr = 0
	for i in range(1, h + 2):
		curr += level[i]
		sums.append(curr)
	a = []
	b = []
	for i in range(1, h + 2):
		if i != split:
			a.extend([sums[i - 1]] * level[i])
			b.extend([sums[i - 1]] * level[i])
		else:
			a.extend([sums[i - 1]] * level[i])
			b.append(sums[i - 1] - 1)
			b.extend([sums[i - 1]] * (level[i] - 1))
	printarr(a)
	printarr(b)


import sys
lines = []
for line in sys.stdin:
	lines.append(line.rstrip('\r\n\t '))
h = int(lines[0])
ids = lines[1].split(' ')
leafs1 = '0'
leafs2 = '0'
parents = []
last_id = 1
is_perfect = True
leafs = int(ids[1])
last_leafs = leafs
for j in range(0, leafs):
	last_id += 1
	leafs1 += ' 1'
	leafs2 += ' 1'
	parents.append(last_id)
for i in range(3, h + 2):
	leafs = int(ids[i - 1])
	s0 = ' ' + str(parents[0])
	if last_leafs > 1 and leafs > 1:
		is_perfect = False
		last_id += 1
		s1 = ' ' + str(parents[1])
		parents = []
		leafs1 += s0
		leafs2 += s1
		parents.append(last_id)
		for j in range(1, leafs):
			last_id += 1
			leafs1 += s0
			leafs2 += s0
			parents.append(last_id)
	else:
		parents = []
		for j in range(0, leafs):
			last_id += 1
			leafs1 += s0
			leafs2 += s0
			parents.append(last_id)
	last_leafs = leafs
if is_perfect:
	print('perfect')
else:
	print('ambiguous')
	print(leafs1)
	print(leafs2)


h = int(input())
a = list(map(int, input().split()))
perfect = True
for i in range(h):
	if a[i] > 1 and a[i + 1] > 1:
		perfect = False
		break
if perfect:
	print('perfect')
else:
	print('ambiguous')
	tree1 = list(range(h + 1))
	tree2 = list(tree1)
	for i in range(1, h + 1):
		tree1.extend([i] * (a[i] - 1))
	for i in range(1, h + 1):
		p = i
		if a[i] > 1 and a[i - 1] > 1:
			p = len(tree2)
		tree2.extend([p] * (a[i] - 1))
	print(' '.join(map(str, tree1)))
	print(' '.join(map(str, tree2)))


h = int(input())
L = [int(x) for x in input().split()]

def f():
	for i in range(1, len(L)):
		if L[i] > 1 and L[i - 1] > 1:
			return [False, i]
	return [True]
bb = f()
if bb[0]:
	print('perfect')
else:
	y = 0
	r = []
	rr = []
	b = True
	for (k, x) in enumerate(L):
		for i in range(x):
			r.append(y)
			rr.append(y)
		y = len(r)
		if b and k == bb[1]:
			rr[-1] -= 1
			b = False
	print('ambiguous')
	print(*r)
	print(*rr)


def read():
	return tuple((int(x) for x in input().split()))

def main():
	(h,) = read()
	a = read()
	tree = []
	fi = 0
	flag = False
	for (i, x) in enumerate(a):
		if fi == 0:
			if not flag and x > 1:
				flag = True
			elif flag and x > 1:
				fi = len(tree)
			else:
				flag = False
		tree.extend([len(tree)] * x)
	if fi == 0:
		print('perfect')
		return
	else:
		print('ambiguous')
	print(' '.join((str(x) for x in tree)))
	tree[fi] = fi - 1
	print(' '.join((str(x) for x in tree)))
main()


n = int(input())
h = list(map(int, input().split()))
t1 = [0]
t2 = [0]
ans = 'perfect'
for i in range(1, len(h)):
	l = len(t1)
	if h[i - 1] > 1 and h[i] > 1:
		l = len(t1)
		pl = len(t1) - 1
		for j in range(h[i]):
			t1.append(l)
		for j in range(h[i]):
			if j % 2:
				t2.append(l)
			else:
				t2.append(pl)
		ans = 'ambiguous'
	else:
		for j in range(h[i]):
			t1.append(l)
			t2.append(l)
if ans == 'perfect':
	print(ans)
else:
	print(ans)
	print(' '.join([str(i) for i in t1]))
	print(' '.join([str(i) for i in t2]))


def do_amb(v, n, sum):
	print('ambiguous')
	diff = []
	for i in v:
		temp = len(diff)
		diff.extend((temp for j in range(i)))
	print(' '.join((str(i) for i in diff)))
	diff[sum + 1] = sum - 1
	print(' '.join((str(i) for i in diff)))
n = int(input())
v = [int(i) for i in input().split()]
ans = []
ind = -1
sum = 0
for i in v:
	if i != 1 and v[ind] != 1:
		do_amb(v, ind, sum)
		exit()
	sum += i
	ind += 1
print('perfect')


import sys
from collections import Counter, deque

def lInt(d=None):
	return map(int, input().split(d))
(n, *_) = lInt()
a = list(lInt())
a.append(0)
j = 0
tot = sum(a)
try:
	for (i, va) in enumerate(a):
		if va > 1 and a[i - 1] > 1:
			print('ambiguous')
			j = i
			raise
except:
	p = 0
	ans = []
	for i in range(0, n + 1):
		va = a[i]
		for u in range(va):
			ans.append(p)
		p += va
	for u in ans:
		sys.stdout.write(str(u) + ' ')
	print('')
	p = 0
	ans = []
	for i in range(0, n + 1):
		va = a[i]
		if i == j:
			for u in range(va // 2):
				ans.append(p - 1)
			for u in range(va // 2, va):
				ans.append(p)
		else:
			for u in range(va):
				ans.append(p)
		p += va
	for u in ans:
		sys.stdout.write(str(u) + ' ')
	print('')
else:
	print('perfect')


import sys
sys.setrecursionlimit(1000000)
read = sys.stdin.readline
h = int(read())
ds = list(map(int, read().split()))
amb = False
for i in range(h):
	if ds[i] > 1 and ds[i + 1] > 1:
		amb = True
		break
if amb:
	print('ambiguous')
	tree1 = []
	tree2 = []
	(f, l) = (0, 0)
	for d in ds:
		tree1 += [f] * d
		tree2 += [f] * (d // 2) + [l] * (d - d // 2)
		l += d
		f = l - d + 1
	print(' '.join(map(str, tree1)), ' '.join(map(str, tree2)), sep='\n')
else:
	print('perfect')


h = int(input())
l = list(map(int, input().split()))
x = False
pos = 0
s = 1
for i in range(h):
	if l[i] != 1 and l[i + 1] != 1:
		pos = i + 1
		x = True
		print('ambiguous')
		break
if not x:
	print('perfect')
else:
	ch = '0'
	ch1 = '0'
	for i in range(1, len(l)):
		ch += (' ' + str(s)) * l[i]
		if i != pos:
			ch1 += (' ' + str(s)) * l[i]
		else:
			ch1 += ' ' + str(s - 1) + (' ' + str(s)) * (l[i] - 1)
		s += l[i]
	print(ch)
	print(ch1)


def main():
	from sys import stdin, stdout
	from collections import defaultdict
	h = int(input())
	if h <= 1:
		stdout.write('perfect\n')
		return
	a = list(map(int, stdin.readline().strip().split(' ')))
	ambiguous = False
	for i in range(0, h + 1):
		if a[i] > 1 and a[i - 1] > 1:
			ambiguous = True
			break
	if not ambiguous:
		stdout.write('perfect\n')
		return
	stdout.write('ambiguous\n')
	t = defaultdict(list)
	prev = 1
	cur = 2
	r = [0]
	for i in range(1, h + 1):
		for j in range(a[i]):
			t[prev].append(cur)
			cur += 1
		for l in t[prev]:
			r.append(prev)
		prev = cur - 1
	stdout.write(' '.join(list(map(str, r))) + '\n')
	t = defaultdict(list)
	prev = 1
	cur = 2
	r = [0]
	o = True
	for i in range(1, h + 1):
		for j in range(a[i]):
			t[prev].append(cur)
			cur += 1
		for l in t[prev]:
			if a[i] > 1 and a[i - 1] > 1 and o:
				r.append(prev - 1)
				o = False
			else:
				r.append(prev)
		prev = cur - 1
	stdout.write(' '.join(list(map(str, r))) + '\n')
main()


n = int(input())
a = list(map(int, input().split()))
for i in range(2, n + 1):
	if a[i] != 1 and a[i - 1] != 1:
		print('ambiguous')
		break
else:
	print('perfect')
	exit()
s1 = ''
s2 = ''
cnt = 0
for i in range(n + 1):
	s1 += a[i] * (str(cnt) + ' ')
	if i > 1 and a[i] != 1 and (a[i - 1] != 1):
		s2 += str(cnt - 1) + ' '
		s2 += (a[i] - 1) * (str(cnt) + ' ')
	else:
		s2 += a[i] * (str(cnt) + ' ')
	cnt += a[i]
print(s1)
print(s2)