#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int h = 0;

  cin >> h;

  vector<int> a(h);

  int ok = -1, am = 0;

  for(int i = 0; i < h + 1; i++) {
    cin >> a[i];
    am += a[i];
    if(i && a[i] > 1 && a[i - 1] > 1) ok = 1;
  }

  if(ok == -1) { cout << "perfect\n"; return 0; }

  cout << "ambiguous\n";

  int left = 1, cur = 0, cpos = 0;

  for(int i = 0; i < am; i++) {
    cout << cur << ' ';
    left--;
    if(left == 0) {
      left = a[++cpos];
      cur = i + 1;
    }
  }

  cout << endl;

  bool u = false;

  left = 1, cur = 0, cpos = 0;

  for(int i = 0; i < am; i++) {
    cout << cur << ' ';
    left--;
    if(!u && cpos && a[cpos - 1] > 1 && a[cpos] > 1) {
      u = true;
      cur--;
    }
    if(!left) {
      left = a[++cpos];
      cur = i + 1;
    }
  }

  return 0;
}
/*

*/


#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void solve(){
    ll n;cin>>n;
    ll arr[n+1];
    for(int i=0;i<=n;i++)   cin>>arr[i];
    vector<long long int> ans[2];
    ans[0].pb(0);
    ans[1].pb(0);
    vector<long long int>tree[n+1];
    tree[0].push_back(1);
    int oo = 2;
    for(int i = 1;i<=n;i++){
        auto j = tree[i-1].back();
        auto beck = tree[i-1][0];
        for(int k = 0;k<arr[i]-1;k++){
            tree[i].push_back(oo);
            oo++;
            ans[0].push_back(j);
            ans[1].push_back(j);
        }
        tree[i].push_back(oo);
        oo++;
        ans[0].push_back(j);
        ans[1].push_back(beck);
    }
    if(ans[0]==ans[1]){
        cout<<"perfect"<<"\n";
        return;
    }else{
        cout<<"ambiguous"<<"\n";
    }
    for(auto i:ans[0]){
        cout<<i<<" ";
    }
    cout<<"\n";
    for(auto i:ans[1]){
        cout<<i<<" ";
    }
    cout<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;

int parent[1000001];
int siz[1000001];
int val[1000001];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    siz[v] = 1;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (siz[a] < siz[b])
            swap(a, b);
        parent[b] = a;
        siz[a] += siz[b];
    }
}

#define MAXN   1000001
int spf[MAXN];
void sieve(){
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)  spf[i] = i;
    for (int i=4; i<MAXN; i+=2) spf[i] = 2;
    for (int i=3; i*i<MAXN; i++){
        if (spf[i] == i){
            for (int j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
vector<int> getFactorization(int x){
    vector<int> ret;
    while (x != 1){
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
void pre(){}
void solve(){
    ll n;cin>>n;
    ll arr[n+1];
    for(int i=0;i<=n;i++){
        cin>>arr[i];
    }
    bool flag = 1;
    for(int i=1;i<=n;i++){
        if(arr[i]!=1 && arr[i-1]!=1){
            cout<<"ambiguous"<<"\n";
            flag = 0;
        }
    }
    if(flag){
        cout<<"perfect"<<"\n";
        return;
    }
    vector<long long int> ans[2];
    ans[0].pb(0);
    ans[1].pb(0);
    vector<long long int>tree[n+1];
    tree[0].push_back(1);
    int oo = 2;
    for(int i = 1;i<=n;i++){
        auto j = tree[i-1].back();
        auto beck = tree[i-1][0];
        for(int k = 0;k<arr[i]-1;k++){
            tree[i].push_back(oo);
            oo++;
            ans[0].push_back(j);
            ans[1].push_back(j);
        }
        tree[i].push_back(oo);
        oo++;
        ans[0].push_back(j);
        ans[1].push_back(beck);
    }
    for(auto i:ans[0]){
        cout<<i<<" ";
    }
    cout<<"\n";
    for(auto i:ans[1]){
        cout<<i<<" ";
    }
    cout<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    sieve();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }
}


#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void solve(){
    ll n;cin>>n;
    ll arr[n+1];
    for(int i=0;i<=n;i++)   cin>>arr[i];
    vector<long long int> ans[2];
    ans[0].pb(0);
    ans[1].pb(0);
    vector<long long int>tree[n+1];
    tree[0].push_back(1);
    int oo = 2;
    for(int i = 1;i<=n;i++){
        auto j = tree[i-1].back();
        auto beck = tree[i-1][0];
        for(int k=0;k<arr[i]-1;k++){
            tree[i].push_back(oo);
            oo++;
            ans[0].push_back(j);
            ans[1].push_back(j);
        }
        if(arr[i]!=1 && arr[i-1]!=1){
            tree[i].push_back(oo);
            oo++;
            ans[0].push_back(j);
            ans[1].push_back(beck);
        }else{
            tree[i].push_back(oo);
            oo++;
            ans[0].push_back(j);
            ans[1].push_back(j);
        }
    }
    if(ans[0]==ans[1]){
        cout<<"perfect"<<"\n";
        return;
    }else{
        cout<<"ambiguous"<<"\n";
    }
    for(auto i:ans[0]){
        cout<<i<<" ";
    }
    cout<<"\n";
    for(auto i:ans[1]){
        cout<<i<<" ";
    }
    cout<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;

int parent[1000001];
int siz[1000001];
int val[1000001];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    siz[v] = 1;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (siz[a] < siz[b])
            swap(a, b);
        parent[b] = a;
        siz[a] += siz[b];
    }
}

#define MAXN   1000001
int spf[MAXN];
void sieve(){
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)  spf[i] = i;
    for (int i=4; i<MAXN; i+=2) spf[i] = 2;
    for (int i=3; i*i<MAXN; i++){
        if (spf[i] == i){
            for (int j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
vector<int> getFactorization(int x){
    vector<int> ret;
    while (x != 1){
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
void pre(){}
void solve(){
    ll n;cin>>n;
    ll arr[n+1];
    for(int i=0;i<=n;i++){
        cin>>arr[i];
    }
    bool flag = 1;
    for(int i=1;i<=n;i++){
        if(arr[i]!=1 && arr[i-1]!=1){
            cout<<"ambigous"<<"\n";
            flag = 0;
        }
    }
    if(flag){
        cout<<"perfect"<<"\n";
        return;
    }
    vector<long long int> ans[2];
    ans[0].pb(0);
    ans[1].pb(0);
    vector<long long int>tree[n+1];
    tree[0].push_back(1);
    int oo = 2;
    for(int i = 1;i<=n;i++){
        auto j = tree[i-1].back();
        auto beck = tree[i-1][0];
        for(int k = 0;k<arr[i]-1;k++){
            tree[i].push_back(oo);
            oo++;
            ans[0].push_back(j);
            ans[1].push_back(j);
        }
        tree[i].push_back(oo);
        oo++;
        ans[0].push_back(j);
        ans[1].push_back(beck);
    }
    for(auto i:ans[0]){
        cout<<i<<" ";
    }
    cout<<"\n";
    for(auto i:ans[1]){
        cout<<i<<" ";
    }
    cout<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    sieve();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

#define rep(i,n) for (int i = 0; i < n; i++)
#define repd(i,n) for (int i = n-1; i >= 0; i--)
#define fo(i,a,b) for (int i = a; i < b; i++)
#define fod(i,a,b) for (int i = a; i >= b; i--)
#define umap unordered_map
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define pqmin priority_queue<int,vector<int>,greater<int>>
#define pqmax priority_queue<int>
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
// #define w(t) int t; cin>>t; while (t--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define out(x) cout<<x<<endl;
#define print(a, n) rep (i, n) cout<<a[i]<<" "; cout<<endl;
#define clr(a, x) memset(a, x, sizeof a)

const int mod = 1e9+7;
const int N = 1e5;
const int inf = 1e9;

//=====================================================

template<typename... T>
void read(T&... args) {((cin >> args), ...);}
template<typename... T>
void write(T&&... args) {((cout << args << " "), ...);}
template<typename... T>
void writeline(T&&... args) {((cout << args << " "), ...); cout << endl;}

int add(int a,int b){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
string binary(int x) {string res = ""; rep(i, 32) res += (1<<i & x)?'1':'0'; return res; }
int in(int x, int y, int z) { if (y > z) swap(y, z); return (x >= y && x <= z);}

// struct customCompare {
//     bool operator () (pii x, pii y) {
//         return x.first > y.second;
//     }
// };

// class g {
// public:
// 	int val;
// 	vector<int> adj;
// 	int par;
// 	int indeg;
// 	int outdeg;
// };

//=====================================================

bool isIsomorphic(int a[], int h) {
	rep (i, h)
		if (a[i] > 1)
			return false;
	return true;
}

void buildTree(int a[], int h) {
	int n = 0;
	rep (i, h) n += a[i];

	int tree1[n], tree2[n];
	int diff = -1;
	int i = 0, j = 0, p = 0;

	while (i < h) {
		if (diff == -1 && a[i] > 1)
			diff = i+1;

		int cnt = a[i];
		if (diff == i) {
			tree1[j] = p;
			tree2[j] = p-1;
			j++; cnt--;
		}

		while (cnt--) {
			tree1[j] = tree2[j] = p;
			j++;
		}

		p = j;
		i++;
	}

	print(tree1, n);
	print(tree2, n);
}

void solve () {
	int h;
	read(h);
	int a[h+1];
	rep (i, h+1) read(a[i]);

	if (isIsomorphic(a, h)) {
		cout << "perfect";
	}
	else {
		cout << "ambiguous" << endl;
		h++;
		buildTree(a, h);
	}
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

#define rep(i,n) for (int i = 0; i < n; i++)
#define repd(i,n) for (int i = n-1; i >= 0; i--)
#define fo(i,a,b) for (int i = a; i < b; i++)
#define fod(i,a,b) for (int i = a; i >= b; i--)
#define umap unordered_map
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define pqmin priority_queue<int,vector<int>,greater<int>>
#define pqmax priority_queue<int>
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
// #define w(t) int t; cin>>t; while (t--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define out(x) cout<<x<<endl;
#define print(a, n) rep (i, n) cout<<a[i]<<" "; cout<<endl;
#define clr(a, x) memset(a, x, sizeof a)

const int mod = 1e9+7;
const int N = 1e5;
const int inf = 1e9;

//=====================================================

template<typename... T>
void read(T&... args) {((cin >> args), ...);}
template<typename... T>
void write(T&&... args) {((cout << args << " "), ...);}
template<typename... T>
void writeline(T&&... args) {((cout << args << " "), ...); cout << endl;}

int add(int a,int b){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
string binary(int x) {string res = ""; rep(i, 32) res += (1<<i & x)?'1':'0'; return res; }
int in(int x, int y, int z) { if (y > z) swap(y, z); return (x >= y && x <= z);}

// struct customCompare {
//     bool operator () (pii x, pii y) {
//         return x.first > y.second;
//     }
// };

// class g {
// public:
// 	int val;
// 	vector<int> adj;
// 	int par;
// 	int indeg;
// 	int outdeg;
// };

//=====================================================

bool isIsomorphic(int a[], int h) {
	rep (i, h)
		if (a[i] > 1)
			return false;
	return true;
}

void buildTree(int a[], int h) {
	int n = 0;
	rep (i, h) n += a[i];

	int tree1[n], tree2[n];
	int diff = -1;
	int i = 0, j = 0, p = 0;

	while (i < h) {
		if (diff == -1 && a[i] > 1)
			diff = i+1;

		int cnt = a[i];
		while (cnt--) {
			tree1[j] = p;
			tree2[j] = (diff == i ? p-1 : p);
			j++;
		}

		p = j;
		i++;
	}

	print(tree1, n);
	print(tree2, n);
}

void solve () {
	int h;
	read(h);
	int a[h+1];
	rep (i, h+1) read(a[i]);

	if (isIsomorphic(a, h)) {
		cout << "perfect";
	}
	else {
		cout << "ambiguous" << endl;
		h++;
		buildTree(a, h);
	}
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

#define rep(i,n) for (int i = 0; i < n; i++)
#define repd(i,n) for (int i = n-1; i >= 0; i--)
#define fo(i,a,b) for (int i = a; i < b; i++)
#define fod(i,a,b) for (int i = a; i >= b; i--)
#define umap unordered_map
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define pqmin priority_queue<int,vector<int>,greater<int>>
#define pqmax priority_queue<int>
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
// #define w(t) int t; cin>>t; while (t--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define out(x) cout<<x<<endl;
#define print(a, n) rep (i, n) cout<<a[i]<<" "; cout<<endl;
#define clr(a, x) memset(a, x, sizeof a)

const int mod = 1e9+7;
const int N = 1e5;
const int inf = 1e9;

//=====================================================

template<typename... T>
void read(T&... args) {((cin >> args), ...);}
template<typename... T>
void write(T&&... args) {((cout << args << " "), ...);}
template<typename... T>
void writeline(T&&... args) {((cout << args << " "), ...); cout << endl;}

int add(int a,int b){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
string binary(int x) {string res = ""; rep(i, 32) res += (1<<i & x)?'1':'0'; return res; }
int in(int x, int y, int z) { if (y > z) swap(y, z); return (x >= y && x <= z);}

// struct customCompare {
//     bool operator () (pii x, pii y) {
//         return x.first > y.second;
//     }
// };

// class g {
// public:
// 	int val;
// 	vector<int> adj;
// 	int par;
// 	int indeg;
// 	int outdeg;
// };

//=====================================================

bool isIsomorphic(int a[], int h) {
	rep (i, h+1) {
		if (a[i] > 1 && a[i-1] > 1)
			return false;
	}
	return true;
}

void buildTree(int a[], int h) {
	int n = 0;
	rep (i, h) n += a[i];

	int tree1[n], tree2[n];
	int diff = -1;
	int i = 0, j = 0, p = 0;

	while (i < h) {
		if (diff == -1 && a[i] > 1 && a[i+1] > 1) {
			diff = i+1;
		}

		int cnt = a[i];
		if (diff == i) {
			tree1[j] = p;
			tree2[j] = p-1;
			j++; cnt--;
		}

		while (cnt--) {
			tree1[j] = tree2[j] = p;
			j++;
		}

		p = j;
		i++;
	}

	print(tree1, n);
	print(tree2, n);
}

void solve () {
	int h;
	read(h);
	int a[h+1];
	rep (i, h+1) read(a[i]);

	if (isIsomorphic(a, h)) {
		cout << "perfect";
	}
	else {
		cout << "ambiguous" << endl;
		h++;
		buildTree(a, h);
	}
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

#define rep(i,n) for (int i = 0; i < n; i++)
#define repd(i,n) for (int i = n-1; i >= 0; i--)
#define fo(i,a,b) for (int i = a; i < b; i++)
#define fod(i,a,b) for (int i = a; i >= b; i--)
#define umap unordered_map
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define pqmin priority_queue<int,vector<int>,greater<int>>
#define pqmax priority_queue<int>
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
// #define w(t) int t; cin>>t; while (t--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define out(x) cout<<x<<endl;
#define print(a, n) rep (i, n) cout<<a[i]<<" "; cout<<endl;
#define clr(a, x) memset(a, x, sizeof a)

const int mod = 1e9+7;
const int N = 1e5;
const int inf = 1e9;

//=====================================================

template<typename... T>
void read(T&... args) {((cin >> args), ...);}
template<typename... T>
void write(T&&... args) {((cout << args << " "), ...);}
template<typename... T>
void writeline(T&&... args) {((cout << args << " "), ...); cout << endl;}

int add(int a,int b){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
string binary(int x) {string res = ""; rep(i, 32) res += (1<<i & x)?'1':'0'; return res; }
int in(int x, int y, int z) { if (y > z) swap(y, z); return (x >= y && x <= z);}

// struct customCompare {
//     bool operator () (pii x, pii y) {
//         return x.first > y.second;
//     }
// };

// class g {
// public:
// 	int val;
// 	vector<int> adj;
// 	int par;
// 	int indeg;
// 	int outdeg;
// };

//=====================================================

bool isIsomorphic(int a[], int h) {
	rep (i, h) {
		if (a[i] >= 3)
			return false;
		if (a[i] == 1)
			continue;
		if (a[i] == 2 && a[i-1] == 2)
			return false;
	}

	return h==0 || a[h-1]==1 || a[h]==1;
}

void buildTree(int a[], int h) {
	int n = 0;
	rep (i, h) n += a[i];

	int tree1[n], tree2[n];
	int diff = -1;
	int i = 0, j = 0, p = 0;

	while (i < h) {
		if (diff == -1 ) {
			if (a[i] > 1 && a[i+1] > 1)
				diff = i+1;
			else if (a[i] >= 3)
				diff = i+1;
		}

		int cnt = a[i];
		if (diff == i) {
			tree1[j] = p;
			tree2[j] = p-1;
			j++; cnt--;
		}

		while (cnt--) {
			tree1[j] = tree2[j] = p;
			j++;
		}

		p = j;
		i++;
	}

	print(tree1, n);
	print(tree2, n);
}

void solve () {
	int h;
	read(h);
	int a[h+1];
	rep (i, h+1) read(a[i]);

	if (isIsomorphic(a, h)) {
		cout << "perfect";
	}
	else {
		cout << "ambiguous" << endl;
		h++;
		buildTree(a, h);
	}
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solve();

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
const ll mod = 998244353;
const int maxn = 2e5 + 33;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	int h, n, amb = 0;
	vi a;
	cin >> h;
	a.resize(h+1);
	for(auto &i : a) cin >> i, n += i;
	for(int i = 0; i < h; i++)
		if(a[i] >= 2)
			amb=1;
	if(amb==0) {
		cout << "perfect";
		return 0;
	}
	cout << "ambiguous\n";
	int pr = 1;
	cout << "0 ";
	for(int i = 1; i <= h; i++) {
		for(int k = 0; k < a[i]; k++)
		cout << pr << " ";
		pr+=a[i-1];
	}
	cout << "\n";
	pr = 1;
		cout << "0 ";
		for(int i = 1; i <= h; i++) {
			for(int k = 0; k < a[i]; k++)
			cout << (pr+(a[i-1]>1)) << " ";
			pr+=a[i-1];
		}
		cout << "\n";
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
const ll mod = 998244353;
const int maxn = 2e5 + 33;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	int h, n, amb = 0;
	vi a;
	cin >> h;
	a.resize(h+1);
	for(auto &i : a) cin >> i, n += i;
	for(int i = 1; i <= h; i++)
		if(a[i] > 1&&a[i-1] > 1)
			amb=1;
	if(amb==0) {
		cout << "perfect";
		return 0;
	}
	cout << "ambiguous\n";
	int pr = 1;
	cout << "0 ";
	for(int i = 1; i <= h; i++) {
		for(int k = 0; k < a[i]; k++)
		cout << pr << " ";
		pr+=a[i-1];
	}
	cout << "\n";
	pr = 1;
		cout << "0 ";
		for(int i = 1; i <= h; i++) {
			for(int k = 0; k < a[i]; k++)
			cout << (pr+(a[i-1]>1&&k==0)) << " ";
			pr+=a[i-1];
		}
		cout << "\n";
}


#pragma GCC diagnostic ignored "-Wunused-result"
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (auto &x : a) cin >> x;
	bool perfect = true;
	for (int i = 1; i <= n; i++) {
		if (a[i] > 1 && a[i - 1] > 1) perfect = false;
	}
	if (perfect) {
		cout << "perfect\n";
		return;
	}
	cout << "ambiguous\n";
	vector<int> v1 = {0}, v2 = {0};
	int prev = 0;
	for (int h = 1; h <= n; h++) {
		for (int i = 0; i < a[h]; i++) {
			v1.push_back(prev + 1);
			v2.push_back(prev + (a[h - 1] == 1 ? 0 : i % 2) + 1);
		}
		prev += a[h];
	}

	for (auto x : v1) cout << x << " ";
	cout << "\n";
	for (auto x : v2) cout << x << " ";
	cout << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
#ifdef MADE_BY_SERT
	int T = 2;
	for (int i = 1; i < T; i++) solve();
#endif
}


    #pragma GCC diagnostic ignored "-Wunused-result"
    #include <bits/stdc++.h>
    #define all(v) v.begin(), v.end()
    using namespace std;
    typedef long long ll;

    void solve() {
    	int n;
    	cin >> n;
    	vector<int> a(n + 1);
    	for (auto &x : a) cin >> x;
    	bool perfect = true;
    	for (int i = 1; i <= n; i++) {
    		if (a[i] > 1 && a[i - 1] > 1) perfect = false;
    	}
    	if (perfect) {
    		cout << "perfect\n";
    		return;
    	}
    	cout << "ambiguous\n";
    	vector<int> v1 = {0}, v2 = {0};
    	int prev = 0;
    	for (int h = 1; h <= n; h++) {
    		for (int i = 0; i < a[h]; i++) {
    			v1.push_back(prev + 1);
    			v2.push_back(prev + (a[h - 1] == 1 ? 0 : -i % 2) + 1);
    		}
    		prev += a[h];
    	}

    	for (auto x : v1) cout << x << " ";
    	cout << "\n";
    	for (auto x : v2) cout << x << " ";
    	cout << "\n";
    }

    int main() {
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    	solve();
    #ifdef MADE_BY_SERT
    	int T = 2;
    	for (int i = 1; i < T; i++) solve();
    #endif
    }


#pragma GCC diagnostic ignored "-Wunused-result"
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (auto &x : a) cin >> x;
	bool perfect = true;
	for (int i = 1; i <= n; i++) {
		if (a[i] > 1 && a[i - 1] > 1) perfect = false;
	}
	if (perfect) {
		cout << "perfect\n";
		return;
	}
	cout << "ambigious\n";
	vector<int> v1 = {0}, v2 = {0};
	int prev = 0;
	for (int h = 1; h <= n; h++) {
		for (int i = 0; i < a[h]; i++) {
			v1.push_back(prev + 1);
			v2.push_back(prev + (a[h - 1] == 1 ? 0 : i % 2) + 1);
		}
		prev += a[h];
	}

	for (auto x : v1) cout << x << " ";
	cout << "\n";
	for (auto x : v2) cout << x << " ";
	cout << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
#ifdef MADE_BY_SERT
	int T = 2;
	for (int i = 1; i < T; i++) solve();
#endif
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));

int main(){
	ll n,m;
	while(cin >> n){
		int cont[n+5]={};
		f(n+1){
			cin >> cont[i];
		}
		int s1[100005],s2[100005];
		int l=1,r=1;
		int lr=1,rr=1;
		for(int i=1;i<=n;i++){
			l=r+1;
			r=r+cont[i];
			for(int j=l;j<=r;j++){
				s1[j]=lr;
				s2[j]=rr;
			}
			lr=l;
			rr=r;
		}
		int f=0;
		f1(rr){
			if(s1[i]!=s2[i]){
				f=1;
				break;
			}
		}
		if(f){
			cout<<"ambiguous"<<endl;
			f1(rr)cout<<s1[i]<<' ';
			cout<<endl;
			f1(rr)cout<<s2[i]<<' ';
			cout<<endl;
		}
		else{
			cout<<"perfect"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));

int main(){
	ll n,m;
	while(cin >> n){
		int cont[n+5]={};
		f(n+1){
			cin >> cont[i];
		}
		int s1[100005],s2[100005];
		int l=1,r=1;
		int lr=1,rr=1;
		for(int i=1;i<=n;i++){
			l=r+1;
			r=r+cont[i];
			for(int j=l;j<=r;j++){
				s1[j]=lr;
				s2[j]=((j-l)&1)?rr:lr;
			}
			lr=l;
			rr=r;
		}
		int f=0;
		f1(rr){
			if(s1[i]!=s2[i]){
				f=1;
				break;
			}
		}
		if(f){
			cout<<"ambiguous"<<endl;
			f1(rr)cout<<s1[i]<<' ';
			cout<<endl;
			f1(rr)cout<<s2[i]<<' ';
			cout<<endl;
		}
		else{
			cout<<"perfect"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	ll n,m;
	while(cin >> n){
		int cont[n+5]={};
		f(n+1){
			cin >> cont[i];
		}
		int s1[200005],s2[200005];
		int l=1,r=1;
		int lr=1,rr=1;
		for(int i=1;i<=n;i++){
			l=r+1;
			r=r+cont[i];
			for(int j=l;j<=r;j++){
				s1[j]=lr;
				s2[j]=((j-l)&1)?rr:lr;
			}
			lr=l;
			rr=r;
		}
		int f=0;
		f1(rr){
			if(s1[i]!=s2[i]){
				f=1;
				break;
			}
		}
		if(f){
			cout<<"ambiguous"<<endl;
			f1(rr)cout<<s1[i]<<' ';
			cout<<endl;
			f1(rr)cout<<s2[i]<<' ';
			cout<<endl;
		}
		else{
			cout<<"perfect"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	ll n,m;
	while(cin >> n){
		int cont[n+5]={};
		f(n+1){
			cin >> cont[i];
		}
		int s1[100005],s2[100005];
		int l=1,r=1;
		int lr=1,rr=1;
		for(int i=1;i<=n;i++){
			l=r+1;
			r=r+cont[i];
			for(int j=l;j<=r;j++){
				s1[j]=lr;
				s2[j]=((j-l)&1)?rr:lr;
			}
			lr=l;
			rr=r;
		}
		int f=0;
		f1(rr){
			if(s1[i]!=s2[i]){
				f=1;
				break;
			}
		}
		if(f){
			cout<<"ambiguous"<<endl;
			f1(rr)cout<<s1[i]<<' ';
			cout<<endl;
			f1(rr)cout<<s2[i]<<' ';
			cout<<endl;
		}
		else{
			cout<<"perfect"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define pob pop_back()
#define ms0(s) memset(s,0,sizeof s)
#define ff first
#define ss second
typedef long long int ll;
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define prq priority_queue<ll>  //max-heap
#define psq priority_queue<ll,vector<ll>,greater<ll>>  //min-heap
#define m_p make_pair
#define vcc vector<char>
#define vss vector<string>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define setbit(n) __builtin_popcountll(n)
const ll mxn = 0;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
	// cin>>t;
	while (t--)
	{
		ll i, j, k, n, m;
		cin >> n;
		n++;
		vll a(n);
		ll f = 0;
		for (i = 0; i < n; i++) {
			cin >> a[i];
			if (i > 0 && a[i] > 1 && a[i - 1] > 1)
				f = 1;
		}
		if (f)
		{
			cout << "ambiguous\n";
			vvll tab;
			vll x;
			x.pb(0);
			tab.pb(x);
			for (i = 0, k = 1; i < n; i++)
			{
				vll tmp;
				while (a[i]--)
				{
					tmp.pb(k++);
				}
				tab.pb(tmp);
			}
			for (i = 1; i <= n; i++)
			{
				for (j = 0; j < tab[i].size(); j++)
					cout << tab[i - 1][0] << " ";
			}
			cout << "\n";
			for (i = 1; i <= n; i++)
			{
				ll l = tab[i - 1].size() - 1;
				for (j = 0, k = 0; j < tab[i].size(); j++, k++)
				{
					cout << tab[i - 1][min(l, k)] << " ";
				}
			}
			cout << "\n";
		}
		else
		{
			cout << "perfect\n";
		}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(__typeof(b) i = a; i <= b; ++i)
#define REP(i, n) for(__typeof(n) i = 0; i < n; ++i)
#define Long long long
#define Mod 1000000007

void mainProgram();

int main() {
#ifdef LOCAL_PROJECT
    freopen("main.inp", "r", stdin);
#endif

    mainProgram();

#ifdef LOCAL_PROJECT
    fclose(stdin);
#endif

    return 0;
}

int H, h[100001];

void mainProgram() {
    scanf("%d", &H);
    FOR(i, 0, H) {
        scanf("%d", &h[i]);
    }

    int m = 0;
    FOR(i, 0, H - 1) {
        if (h[i] > 1 && h[i+1] > 1) {
            printf("ambiguous");

            // First Tree
            printf("\n0 ");
            m = 1;
            FOR(a, 1, H) {
                FOR(b, 1, h[a]) {
                    printf("%d ", m);
                }
                m += h[a];
            }
            // Second Tree
            printf("\n0 ");
            m = 1;
            FOR(a, 1, i) {
                FOR(b, 1, h[a]) {
                    printf("%d ", m);
                }
                m += h[a];
            }

            printf("%d ", m - 1);
            FOR(b, 2, h[i+1]) {
                printf("%d ", m);
            }

            m += h[i + 1];
            FOR(a, i+2, H) {
                FOR(b, 1, h[a]) {
                    printf("%d ", m);
                }
                m += h[a];
            }
            return;
        }
    }

    // Perfect case
    printf("perfect\n");
}


#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(__typeof(b) i = a; i <= b; ++i)
#define REP(i, n) for(__typeof(n) i = 0; i < n; ++i)
#define Long long long
#define Mod 1000000007

void mainProgram();

int main() {
#ifdef LOCAL_PROJECT
    freopen("main.inp", "r", stdin);
#endif

    mainProgram();

#ifdef LOCAL_PROJECT
    fclose(stdin);
#endif

    return 0;
}

int H, h[100001], n, mom[200002];

void mainProgram() {
    scanf("%d", &H);
    FOR(i, 0, H) {
        scanf("%d", &h[i]);
        n += h[i];
    }

    int m = 0;
    FOR(i, 0, H - 1) {
        if (h[i] > 1 && h[i+1] > 1) {
            printf("ambiguous");

            // First Tree
            printf("\n0 ");
            m = 1;
            FOR(a, 1, n) {
                FOR(b, 1, h[a]) {
                    printf("%d ", m);
                }
                m += h[a];
            }
            // Second Tree
            printf("\n0 ");
            m = 1;
            FOR(a, 1, i) {
                FOR(b, 1, h[a]) {
                    printf("%d ", m);
                }
                m += h[a];
            }

            printf("%d ", m - 1);
            FOR(b, 2, h[i+1]) {
                printf("%d ", m);
            }

            m += h[i + 1];
            FOR(a, i+2, n) {
                FOR(b, 1, h[a]) {
                    printf("%d ", m);
                }
                m += h[a];
            }
            return;
        }
    }

    // Perfect case
    printf("perfect\n");
}


#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(__typeof(b) i = a; i <= b; ++i)
#define REP(i, n) for(__typeof(n) i = 0; i < n; ++i)
#define Long long long
#define Mod 1000000007

void mainProgram();

int main() {
#ifdef LOCAL_PROJECT
    freopen("main.inp", "r", stdin);
#endif

    mainProgram();

#ifdef LOCAL_PROJECT
    fclose(stdin);
#endif

    return 0;
}

int H, h[100001], n, mom[200002];

void mainProgram() {
    cin >> H;
    FOR(i, 0, H) {
        cin >> h[i];
        n += h[i];
    }

    int m = 0;
    FOR(i, 0, H - 1) {
        if (h[i] > 1 && h[i+1] > 1) {
            cout << "ambiguous";

            // First Tree
            cout << "\n" << 0 << " ";
            m = 1;
            FOR(a, 1, n) {
                FOR(b, 1, h[a]) {
                    cout << m << " ";
                }
                m += h[a];
            }
            // Second Tree
            cout << "\n" << 0 << " ";
            m = 1;
            FOR(a, 1, i) {
                FOR(b, 1, h[a]) {
                    cout << m << " ";
                }
                m += h[a];
            }

            cout << m - 1 << " ";
            FOR(b, 2, h[i+1]) {
                cout << m << " ";
            }

            m += h[i + 1];
            FOR(a, i+2, n) {
                FOR(b, 1, h[a]) {
                    cout << m << " ";
                }
                m += h[a];
            }
            return;
        }
    }

    // Perfect case
    cout << "perfect\n";
}


/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define deb(x) cout<<#x<<" "<<x<<el;
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n==1) return x;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                              //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

template<typename T>
T maxx(T a,T b)
{
  if(a<b) re b;
  re b;
}
template<typename T, typename... Args>
T maxx(T a,T b, Args... args)
{
    re(maxx(maxx(a,b),args...));
}

template<typename T>
T minn(T a,T b)
{
  if(a<b) re a;
  re b;
}
template<typename T, typename... Args>
T minn(T a,T b, Args... args)
{
    re(minn(minn(a,b),args...));
}

template<typename T>
void read(T& a)
{
  cin>>a;
}
template<typename T, typename... Args>
void read(T& a,Args&... args)
{
  cin>>a; read(args...);
}

template<typename T>
void write(T a)
{
  cout<<a<<' ';
}
template<typename T, typename... Args>
void write(T a,Args... args)
{
  cout<<a<<' '; write(args...);
}

inline ll min(ll a,ll b)
{
  if(a<b) re a;
  else re b;
}
inline ll max(ll a,ll b)
{
  if(a<b) re b;
  else re a;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=((ans*((n-i)%N))%N*modInverse(i+1,N))%N;
  }
  re ans;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    cin>>n;
    vi v(n+1);
    take(v,n+1);
    m=0;
    int ind=-1;
    forup(i,n)
    {
      if(v[i]>1 && v[i+1]>1) {m=1;ind=i;break;}
    }
    if(!m) {cout<<"perfect"; re 0;}
    m=0;
    write("ambiguous");cout<<el;
    forup(i,n+1)
    {
      forup(j,v[i])
      {
        write(m);
      }
      m+=v[i];
    }
    cout<<el;
    m=0;
    forup(i,ind)
    {
      forup(j,v[i])
      {
        write(m);
      }
      m+=v[i];
    }
    forup(j,v[ind])
    {
      write(m);
    }
    m++;
    write(m);
    m++;
    forup(j,v[ind+1]-1)
    write(m);
    m+=v[ind+1]-1;
    forf(i,ind+2,n+1)
    {
      forup(j,v[i])
      {
        write(m);
      }
      m+=v[i];
    }

  }

  return 0;
}


/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define deb(x) cout<<#x<<" "<<x<<el;
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n==1) return x;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                              //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

template<typename T>
T maxx(T a,T b)
{
  if(a<b) re b;
  re b;
}
template<typename T, typename... Args>
T maxx(T a,T b, Args... args)
{
    re(maxx(maxx(a,b),args...));
}

template<typename T>
T minn(T a,T b)
{
  if(a<b) re a;
  re b;
}
template<typename T, typename... Args>
T minn(T a,T b, Args... args)
{
    re(minn(minn(a,b),args...));
}

template<typename T>
void read(T& a)
{
  cin>>a;
}
template<typename T, typename... Args>
void read(T& a,Args&... args)
{
  cin>>a; read(args...);
}

template<typename T>
void write(T a)
{
  cout<<a<<' ';
}
template<typename T, typename... Args>
void write(T a,Args... args)
{
  cout<<a<<' '; write(args...);
}

inline ll min(ll a,ll b)
{
  if(a<b) re a;
  else re b;
}
inline ll max(ll a,ll b)
{
  if(a<b) re b;
  else re a;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=((ans*((n-i)%N))%N*modInverse(i+1,N))%N;
  }
  re ans;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    cin>>n;
    vi v(n+1);
    take(v,n+1);
    m=0;
    int ind=-1;
    forup(i,n)
    {
      if(v[i]>1 && v[i+1]>1) {m=1;ind=i;break;}
    }
    if(!m) {cout<<"perfect"; re 0;}
    m=0;
    write("ambiguous");cout<<el;
    forup(i,n+1)
    {
      forup(j,v[i])
      {
        write(m);
      }
      m+=v[i];
    }
    cout<<el;
    m=0;
    forup(i,ind)
    {
      forup(j,v[i])
      {
        write(m);
      }
      m+=v[i];
    }
    forup(j,v[ind])
    {
      write(m);
    }
    m++;
    write(m);
    m++;
    forup(j,v[ind+1]-1)
    write(m);
    m-=2;
    m+=v[ind];
    m+=v[ind+1];
    forf(i,ind+2,n+1)
    {
      forup(j,v[i])
      {
        write(m);
      }
      m+=v[i];
    }

  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;          cin>>n;
    int a[n+1];
    for(auto i=0;i<n+1;++i){
        cin>>a[i];
    }
    int h;
    bool flag=false;
    for(auto i=0;i<n;++i){
        if(a[i]>1 && a[i+1]>1 ){
            h=i;
            flag=true;
            break;
        }
    }
    if(flag==true){
        cout<<"ambiguous"<<endl;
        for(auto i=0;i<h;++i){
            cout<<i<<" ";
        }
        for(auto i=0;i<a[h];++i){
            cout<<h<<" ";
        }
        for(auto i=0;i<a[h+1]-1;++i){
            cout<<h+1<<" ";
        }
        cout<<h+2<<" ";
        int current1=h+a[h]+1;
        for(auto i=h+2;i<n+1;++i){
            for(auto j=0;j<a[i];++j){
                cout<<current1<<" ";
            }
            current1+=a[i]-1;
        }
        cout<<endl;
        for(auto i=0;i<h;++i){
            cout<<i<<" ";
        }
        for(auto i=0;i<a[h];++i){
            cout<<h<<" ";
        }
        for(auto i=0;i<a[h+1];++i){
            cout<<h+1<<" ";
        }
        int current2=h+a[h]+1;
        for(auto i=h+2;i<n+1;++i){
            for(auto j=0;j<a[i];++j){
                cout<<current2<<" ";
            }
            current2+=a[i]-1;
        }

    }
    else cout<<"perfect";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int h,i,j,x,l,r,pa[200200],pb[200200];
bool ans;
int main() {
  scanf("%d",&h);
  for (j=0; j<=h; j++) {
    scanf("%d",&x);
    for (i=1; i<=x; i++) {
      pa[r+i]=l;
      pb[r+i]=min(l+i-1,r);
      if (pa[r+i]!=pb[r+i]) ans=true;
    }
    l=r+1;
    r=r+x;
  }
  if (ans) {
    puts("ambiguous");
    for (i=1; i<=r; i++) printf("%d ",pa[i]); puts("");
    for (i=1; i<=r; i++) printf("%d ",pb[i]); puts("");
  } else puts("perfect");
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;          cin>>n;
    int a[n+1];
    for(auto i=0;i<n+1;++i){
        cin>>a[i];
    }
    int h;
    bool flag=false;
    for(auto i=0;i<n;++i){
        if(a[i]>1 && a[i+1]>1 ){
            h=i;
            flag=true;
            break;
        }
    }
    if(flag==true){
        cout<<"ambiguous"<<endl;
        for(auto i=0;i<h;++i){
            cout<<i<<" ";
        }
        for(auto i=0;i<a[h];++i){
            cout<<h<<" ";
        }
        for(auto i=0;i<a[h+1]-1;++i){
            cout<<h+1<<" ";
        }
        cout<<h+2<<" ";
        int current1=h+a[h]+a[h+1];
        for(auto i=h+1;i<n+1;++i){
            for(auto j=0;j<a[i+1];++j){
                cout<<current1<<" ";
            }
            current1+=a[i+1];
        }
        cout<<endl;
        for(auto i=0;i<h;++i){
            cout<<i<<" ";
        }
        for(auto i=0;i<a[h];++i){
            cout<<h<<" ";
        }
        for(auto i=0;i<a[h+1];++i){
            cout<<h+1<<" ";
        }
        int current2=h+a[h]+a[h+1];
        for(auto i=h+1;i<n+1;++i){
            for(auto j=0;j<a[i+1];++j){
                cout<<current2<<" ";
            }
            current2+=a[i+1];
        }

    }
    else cout<<"perfect";
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    cin >> a;
    int sum = 0;
    for (auto i : a) sum += i;
    bool flag = false;
    for (int i = 0; i <= n; ++i) {
        if (flag) {
            cout << "ambiguous\n";
            vector<vector<int>> h(n + 1);
            vector<int> ans1(sum), ans2(sum);
            for (int j = 0; j < i - 1; ++j) ans1[j] = ans2[j] = j;
            for (int j = 0; j < a[i - 1]; ++j)
                ans1[i - 1 + j] = ans2[i - 1 + j] = i - 1;
            for (int j = 0; j < a[i]; ++j)
                ans1[i + a[i - 1] + j - 1] = i, ans2[i + a[i - 1] + j - 1] = i + 1;
            int curr = i + a[i] + 1;
            for (int j = i + 1; j <= n; ++j) {
                int past = curr;
                for (int t = 0; t < a[j]; ++t)
                    ans1[curr] = ans2[curr] = past, ++curr;
            }
            for (auto i : ans1) cout << i << ' ';
            cout << '\n';
            for (auto i : ans2) cout << i << ' ';
            return 0;
        }
        if (a[i] > 1) flag = true;
    }
    cout << "perfect";
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    cin >> a;
    int sum = 0;
    for (auto i : a) sum += i;
    bool flag = false;
    for (int i = 1; i <= n; ++i) {
        if (a[i - 1] > 1 && a[i] > 1) {
            cout << "ambiguous\n";
            vector<vector<int>> h(n + 1);
            vector<int> ans1(sum), ans2(sum);
            for (int j = 0; j < i - 1; ++j) ans1[j] = ans2[j] = j;
            for (int j = 0; j < a[i - 1]; ++j)
                ans1[i - 1 + j] = ans2[i - 1 + j] = i - 1;
            ans1[i + a[i] - 1] = i, ans2[i + a[i] - 1] = i + 1;
            for (int j = 1; j < a[i]; ++j) {
                ans1[i + a[i - 1] + j - 1] = ans2[i + a[i - 1] + j - 1] = i;
            }
            int curr = i + a[i] + 1;
            for (int j = i + 1; j <= n; ++j) {
                int past = curr;
                for (int t = 0; t < a[j]; ++t)
                    ans1[curr] = ans2[curr] = past, ++curr;
            }
            for (auto i : ans1) cout << i << ' ';
            cout << '\n';
            for (auto i : ans2) cout << i << ' ';
            return 0;
        }
    }
    cout << "perfect";
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    cin >> a;
    int sum = 0;
    for (auto i : a) sum += i;
    bool flag = false;
    for (int i = 0; i <= n; ++i) {
        if (flag) {
            cout << "ambiguous\n";
            vector<vector<int>> h(n + 1);
            vector<int> ans1(sum), ans2(sum);
            for (int j = 0; j < i - 1; ++j) ans1[j] = ans2[j] = j;
            for (int j = 0; j < a[i - 1]; ++j)
                ans1[i - 1 + j] = ans2[i - 1 + j] = i - 1;
            ans1[i + a[i] - 1] = i, ans2[i + a[i] - 1] = i + 1;
            for (int j = 1; j < a[i]; ++j) {
                ans1[i + a[i - 1] + j - 1] = ans2[i + a[i - 1] + j - 1] = i;
            }
            int curr = i + a[i] + 1;
            for (int j = i + 1; j <= n; ++j) {
                int past = curr;
                for (int t = 0; t < a[j]; ++t)
                    ans1[curr] = ans2[curr] = past, ++curr;
            }
            for (auto i : ans1) cout << i << ' ';
            cout << '\n';
            for (auto i : ans2) cout << i << ' ';
            return 0;
        }
        if (a[i] > 1) flag = true;
    }
    cout << "perfect";
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    cin >> a;
    int sum = 0;
    for (auto i : a) sum += i;
    bool flag = false;
    for (int i = 1; i <= n; ++i) {
        if (a[i - 1] > 1 && a[i] > 1) {
            cout << "ambiguous\n";
            vector<int> ans(sum);
            int curr = 0;
            for (auto t : a) {
                int past = curr;
                for (int j = 0; j < t; ++j)
                    ans[curr] = past, ++curr;
            }
            vector<int> ans2 = ans;
            int s = 0;
            for (int j = 0; j < i; ++j) s += a[j];
            ans2[s]--;
            for (auto i : ans) cout << i << ' ';
            cout << '\n';
            for (auto i : ans2) cout << i << ' ';
            cout << '\n';
            return 0;
        }
    }
    cout << "perfect";
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    cin >> a;
    int sum = 0;
    for (auto i : a) sum += i;
    bool flag = false;
    for (int i = 1; i <= n; ++i) {
        if (a[i - 1] > 1 && a[i] > 1) {
            cout << "ambiguous\n";
            vector<int> ans(sum);
            int curr = 0;
            for (auto t : a) {
                int past = curr;
                for (int j = 0; j < t; ++j)
                    ans[curr] = past, ++curr;
            }
            vector<int> ans2 = ans;
            ans2[i + a[i - 1] - 1]--;
            for (auto i : ans) cout << i << ' ';
            cout << '\n';
            for (auto i : ans2) cout << i << ' ';
            cout << '\n';
            return 0;
        }
    }
    cout << "perfect";
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    cin >> a;
    int sum = 0;
    for (auto i : a) sum += i;
    bool flag = false;
    for (int i = 1; i <= n; ++i) {
        if (a[i - 1] > 1 && a[i] > 1) {
            cout << "ambiguous\n";
            vector<int> ans(sum);
            int curr = 0;
            for (auto t : a) {
                int past = curr;
                for (int j = 0; j < t; ++j)
                    ans[curr] = past, ++curr;
            }
            vector<int> ans2 = ans;
            ans2[i + a[i - 1]]--;
            for (auto i : ans) cout << i << ' ';
            cout << '\n';
            for (auto i : ans2) cout << i << ' ';
            cout << '\n';
            return 0;
        }
    }
    cout << "perfect";
    return 0;
}


#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    cin >> a;
    int sum = 0;
    for (auto i : a) sum += i;
    bool flag = false;
    for (int i = 0; i <= n; ++i) {
        if (flag && a[i] > 1) {
            cout << "ambiguous\n";
            vector<vector<int>> h(n + 1);
            vector<int> ans1(sum), ans2(sum);
            for (int j = 0; j < i - 1; ++j) ans1[j] = ans2[j] = j;
            for (int j = 0; j < a[i - 1]; ++j)
                ans1[i - 1 + j] = ans2[i - 1 + j] = i - 1;
            ans1[i + a[i] - 1] = i, ans2[i + a[i] - 1] = i + 1;
            for (int j = 1; j < a[i]; ++j) {
                ans1[i + a[i - 1] + j - 1] = ans2[i + a[i - 1] + j - 1] = i;
            }
            int curr = i + a[i] + 1;
            for (int j = i + 1; j <= n; ++j) {
                int past = curr;
                for (int t = 0; t < a[j]; ++t)
                    ans1[curr] = ans2[curr] = past, ++curr;
            }
            for (auto i : ans1) cout << i << ' ';
            cout << '\n';
            for (auto i : ans2) cout << i << ' ';
            return 0;
        }
        if (a[i] > 1) flag = true;
    }
    cout << "perfect";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int p, h;
int dep[110000];
int dep_first[110000];
int a[110000];
int parent[110000];
int main(){
    cin >> h;
    int ambiguous = -1;
    p = 1;
    for(int i = 0;i <= h;i++){
        cin >> a[i];
        dep_first[i] = p;
        for(int j = 0;j < a[i];j++){
            if(i)parent[p] = dep_first[i-1];
            dep[p++] = i;
        }
        if(i && a[i] > 1 && a[i-1] > 1)ambiguous = i;

    }
    if(ambiguous==-1){
        cout << "perfect" << endl;
        return 0;
    }
    cout << "ambiguous" << endl;
    for(int i = 1;i < p;i++){
        cout << parent[i] <<  " ";
    }cout << endl;
    parent[dep_first[ambiguous] + 1] = dep_first[ambiguous-1] + 1;
    for(int i = 1;i < p;i++){
        cout << parent[i] <<  " ";
    }cout << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int p, h;
int dep[220000];
int dep_first[220000];
int a[220000];
int parent[220000];
int main(){
    cin >> h;
    int ambiguous = -1;
    p = 1;
    for(int i = 0;i <= h;i++){
        cin >> a[i];
        dep_first[i] = p;
        for(int j = 0;j < a[i];j++){
            if(i)parent[p] = dep_first[i-1];
            dep[p++] = i;
        }
        if(i && a[i] > 1 && a[i-1] > 1)ambiguous = i;

    }
    if(ambiguous==-1){
        cout << "perfect" << endl;
        return 0;
    }
    cout << "ambiguous" << endl;
    for(int i = 1;i < p;i++){
        cout << parent[i] <<  " ";
    }cout << endl;
    parent[dep_first[ambiguous] + 1] = dep_first[ambiguous-1] + 1;
    for(int i = 1;i < p;i++){
        cout << parent[i] <<  " ";
    }cout << endl;
    return 0;
}


#include<bits/stdc++.h>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<					// giving space
#define MOD 1000000007				// for mod
#define ll long long

// Vector
#define vi vector<int>					//integer vector
#define vll vector<long long,long long>
#define pb push_back					//vector element insertion
#define er(v,i) v.erase(v.begin()+i)			// erase ith element in a vector
#define erng(v,x) v.erase(v.begin(),v.begin()+x)       	// delete a range in array

//Stack
/*  stack<int> s;						//declaring stack
s.push(1)						// enter  element in stack
s.top()							//returns top element in stack
s.pop()							//removes top element in  stack
*/
// pair
#define pii pair<int,int>					//pair integers
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)			// entering pair element in vector(size not defined)

//Hashmap
/* map<string,string> a;				//declaration
a[“abc”]=”xyz”;					// element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;			//iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");		//finding element in map
  cout << itz->second;

//*/

using namespace std;
int co[10005];
bool vis[10005];
int cnt=0;
vi graph[10005];
void dfs(int i,int c)
{
    //cout<<i sp co[i] sp c sp cnt<<endl;
    vis[i]=1;
    if(co[i]!=c)cnt++;
    for(auto j:graph[i])
    {
        if(!vis[j])dfs(j,co[i]);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,u;
  cin>>n;

  vi h(n+1),v1(n+1),v2(n+1);
  int f=1;
  for0(i,n+1){cin>>u;h[i]=u;}
        //cout<<0<<" ";
        int a=0,b=0;
        for0(i,n+1)
        {
            for(int j=0;j<h[i];j++)
            {
                v1[i]=a;
                b++;
            }
            a=a+b;
            b=0;
        }
        cout<<endl;
        //<<0<<" ";
        a=0;
        for0(i,n+1)
        {
            for(int j=0;j<h[i];j++)
            {
                int c=min(1,j);
                c=max(a-c,i);
                v2[i]=c;
                if(c!=v1[i])f=0;
                b++;
            }
            a=a+b;
            b=0;
        }
    if(f)cout<<"perfect";
    else {cout<<"ambiguous\n"; for0(i,n+1)cout<<v1[i]<<" ";}
  return 0;
}


#include<bits/stdc++.h>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<					// giving space
#define MOD 1000000007				// for mod
#define ll long long

// Vector
#define vi vector<int>					//integer vector
#define vll vector<long long,long long>
#define pb push_back					//vector element insertion
#define er(v,i) v.erase(v.begin()+i)			// erase ith element in a vector
#define erng(v,x) v.erase(v.begin(),v.begin()+x)       	// delete a range in array

//Stack
/*  stack<int> s;						//declaring stack
s.push(1)						// enter  element in stack
s.top()							//returns top element in stack
s.pop()							//removes top element in  stack
*/
// pair
#define pii pair<int,int>					//pair integers
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)			// entering pair element in vector(size not defined)

//Hashmap
/* map<string,string> a;				//declaration
a[“abc”]=”xyz”;					// element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;			//iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");		//finding element in map
  cout << itz->second;

//*/

using namespace std;
int co[10005];
bool vis[10005];
int cnt=0;
vi graph[10005];
void dfs(int i,int c)
{
    //cout<<i sp co[i] sp c sp cnt<<endl;
    vis[i]=1;
    if(co[i]!=c)cnt++;
    for(auto j:graph[i])
    {
        if(!vis[j])dfs(j,co[i]);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,u;
  cin>>n;
  vi h(n+1);
  int f=1;
  for0(i,n+1){cin>>u;if(u!=1)f=0;h[i]=u;}
  if(f)cout<<"perfect";
  else
    {
        cout<<"ambiguous\n";
        //cout<<0<<" ";
        int a=0,b=0;
        for0(i,n+1)
        {
            for(int j=0;j<h[i];j++)
            {
                cout<<a<<" ";
                b++;
            }
            a=a+b;
            b=0;
        }
        cout<<endl;
        //<<0<<" ";
        a=0;
        for0(i,n+1)
        {
            for(int j=0;j<h[i];j++)
            {
                int c=min(1,j);
                c=max(a-c,i);
                cout<<c<<" ";
                b++;
            }
            a=a+b;
            b=0;
        }
    }
  return 0;
}


#include<bits/stdc++.h>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<					// giving space
#define MOD 1000000007				// for mod
#define ll long long

// Vector
#define vi vector<int>					//integer vector
#define vll vector<long long,long long>
#define pb push_back					//vector element insertion
#define er(v,i) v.erase(v.begin()+i)			// erase ith element in a vector
#define erng(v,x) v.erase(v.begin(),v.begin()+x)       	// delete a range in array

//Stack
/*  stack<int> s;						//declaring stack
s.push(1)						// enter  element in stack
s.top()							//returns top element in stack
s.pop()							//removes top element in  stack
*/
// pair
#define pii pair<int,int>					//pair integers
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)			// entering pair element in vector(size not defined)

//Hashmap
/* map<string,string> a;				//declaration
a[“abc”]=”xyz”;					// element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;			//iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");		//finding element in map
  cout << itz->second;

//*/

using namespace std;
int co[10005];
bool vis[10005];
int cnt=0;
vi graph[10005];
void dfs(int i,int c)
{
    //cout<<i sp co[i] sp c sp cnt<<endl;
    vis[i]=1;
    if(co[i]!=c)cnt++;
    for(auto j:graph[i])
    {
        if(!vis[j])dfs(j,co[i]);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,u;
  cin>>n;

  vi h(n+1),v1,v2;
  int f=1;
  for0(i,n+1)cin>>h[i];
  for(int i=0;i<n;i+=2)if(h[i]!=1)f=0;
        //cout<<0<<" ";
        int a=0,b=0;
        for0(i,n+1)
        {
            for(int j=0;j<h[i];j++)
            {
                v1.pb(a);
                b++;
            }
            a=a+b;
            b=0;
        }
        //cout<<endl;
        //<<0<<" ";
        a=0;
        int cnt=0;
        for(int i=0;i<n+1;i++)
        {
            for(int j=0;j<h[i];j++)
            {

                int c=min(1,j);
                c=max(a-c,i);
                v2.pb(c);
                b++;
                cnt++;
            }
            a=a+b;
            b=0;
        }
    if(f)cout<<"perfect";
    else {cout<<"ambiguous\n"; for0(k,v1.size())cout<<v1[k]<<" ";
        cout<<endl;for0(k,v2.size())cout<<v2[k]<<" ";
        }
  return 0;
}


#include<bits/stdc++.h>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<					// giving space
#define MOD 1000000007				// for mod
#define ll long long

// Vector
#define vi vector<int>					//integer vector
#define vll vector<long long,long long>
#define pb push_back					//vector element insertion
#define er(v,i) v.erase(v.begin()+i)			// erase ith element in a vector
#define erng(v,x) v.erase(v.begin(),v.begin()+x)       	// delete a range in array

//Stack
/*  stack<int> s;						//declaring stack
s.push(1)						// enter  element in stack
s.top()							//returns top element in stack
s.pop()							//removes top element in  stack
*/
// pair
#define pii pair<int,int>					//pair integers
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)			// entering pair element in vector(size not defined)

//Hashmap
/* map<string,string> a;				//declaration
a[“abc”]=”xyz”;					// element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;			//iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");		//finding element in map
  cout << itz->second;

//*/

using namespace std;
int co[10005];
bool vis[10005];
int cnt=0;
vi graph[10005];
void dfs(int i,int c)
{
    //cout<<i sp co[i] sp c sp cnt<<endl;
    vis[i]=1;
    if(co[i]!=c)cnt++;
    for(auto j:graph[i])
    {
        if(!vis[j])dfs(j,co[i]);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,u;
  cin>>n;

  vi h(n+1),v1,v2;
  int f=1;
  for0(i,n+1)cin>>h[i];
  for(int i=0;i<n+1;i++){if(h[i]!=1&&f==1)f=2;
  else if(f==2&&h[i]!=1){f=0;}
  if(h[i]==1){if(f)f=1;}
  }

        //cout<<0<<" ";
        int a=0,b=0;
        for0(i,n+1)
        {
            for(int j=0;j<h[i];j++)
            {
                v1.pb(a);
                b++;
            }
            a=a+b;
            b=0;
        }
        //cout<<endl;
        //<<0<<" ";
        a=0;
        int cnt=0;
        for(int i=0;i<n+1;i++)
        {
            for(int j=0;j<h[i];j++)
            {

                int c=min(1,j);
                c=max(a-c,i);
                v2.pb(c);
                b++;
                cnt++;
            }
            a=a+b;
            b=0;
        }
    if(f)cout<<"perfect";
    else {cout<<"ambiguous\n"; for0(k,v1.size())cout<<v1[k]<<" ";
        cout<<endl;for0(k,v2.size())cout<<v2[k]<<" ";
        }
  return 0;
}


#include<bits/stdc++.h>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<					// giving space
#define MOD 1000000007				// for mod
#define ll long long

// Vector
#define vi vector<int>					//integer vector
#define vll vector<long long,long long>
#define pb push_back					//vector element insertion
#define er(v,i) v.erase(v.begin()+i)			// erase ith element in a vector
#define erng(v,x) v.erase(v.begin(),v.begin()+x)       	// delete a range in array

//Stack
/*  stack<int> s;						//declaring stack
s.push(1)						// enter  element in stack
s.top()							//returns top element in stack
s.pop()							//removes top element in  stack
*/
// pair
#define pii pair<int,int>					//pair integers
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)			// entering pair element in vector(size not defined)

//Hashmap
/* map<string,string> a;				//declaration
a[“abc”]=”xyz”;					// element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;			//iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");		//finding element in map
  cout << itz->second;

//*/

using namespace std;
int co[10005];
bool vis[10005];
int cnt=0;
vi graph[10005];
void dfs(int i,int c)
{
    //cout<<i sp co[i] sp c sp cnt<<endl;
    vis[i]=1;
    if(co[i]!=c)cnt++;
    for(auto j:graph[i])
    {
        if(!vis[j])dfs(j,co[i]);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,u;
  cin>>n;

  vi h(n+1),v1,v2;
  int f=1;
  for0(i,n+1){cin>>u;h[i]=u;}
        //cout<<0<<" ";
        int a=0,b=0;
        for0(i,n+1)
        {
            for(int j=0;j<h[i];j++)
            {
                v1.pb(a);
                b++;
            }
            a=a+b;
            b=0;
        }
        //cout<<endl;
        //<<0<<" ";
        a=0;
        int cnt=0;
        for(int i=0;i<n+1;i++)
        {
            for(int j=0;j<h[i];j++)
            {

                int c=min(1,j);
                c=max(a-c,i);
                v2.pb(c);
                if(c!=v1[cnt])f=0;
                b++;
                cnt++;
            }
            a=a+b;
            b=0;
        }
    if(f)cout<<"perfect";
    else {cout<<"ambiguous\n"; for0(k,v1.size())cout<<v1[k]<<" ";
        cout<<endl;for0(k,v2.size())cout<<v2[k]<<" ";
        }
  return 0;
}


#include<bits/stdc++.h>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<					// giving space
#define MOD 1000000007				// for mod
#define ll long long

// Vector
#define vi vector<int>					//integer vector
#define vll vector<long long,long long>
#define pb push_back					//vector element insertion
#define er(v,i) v.erase(v.begin()+i)			// erase ith element in a vector
#define erng(v,x) v.erase(v.begin(),v.begin()+x)       	// delete a range in array

//Stack
/*  stack<int> s;						//declaring stack
s.push(1)						// enter  element in stack
s.top()							//returns top element in stack
s.pop()							//removes top element in  stack
*/
// pair
#define pii pair<int,int>					//pair integers
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)			// entering pair element in vector(size not defined)

//Hashmap
/* map<string,string> a;				//declaration
a[“abc”]=”xyz”;					// element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;			//iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");		//finding element in map
  cout << itz->second;

//*/

using namespace std;
int co[10005];
bool vis[10005];
int cnt=0;
vi graph[10005];
void dfs(int i,int c)
{
    //cout<<i sp co[i] sp c sp cnt<<endl;
    vis[i]=1;
    if(co[i]!=c)cnt++;
    for(auto j:graph[i])
    {
        if(!vis[j])dfs(j,co[i]);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,in;
  cin>>n;
  vi h(n+1);
  for0(i,n+1)cin>>h[i];
  int f=1;
  for0(i,n+1){if(h[i]!=1){if(h[i-1]!=1){f=0;in=i;}}}
  if(f)cout<<"perfect";
  else {
    cout<<"ambiguous\n";
    int a=0,b=0;
    for0(i,n+1)
    {
        for0(j,h[i]){cout<<a<<" ";
        b++;}
        a+=b;
        b=0;
    }
    cout<<endl;a=0;

    for0(i,n+1)
    {
        for0(j,h[i])
        {   int c=0;
            if(i==in&&j==1)c=1;
            cout<<a-c<<" ";
            b++;}
            a+=b;
            b=0;
        }
    }
  return 0;
}


#include<bits/stdc++.h>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<					// giving space
#define MOD 1000000007				// for mod
#define ll long long

// Vector
#define vi vector<int>					//integer vector
#define vll vector<long long,long long>
#define pb push_back					//vector element insertion
#define er(v,i) v.erase(v.begin()+i)			// erase ith element in a vector
#define erng(v,x) v.erase(v.begin(),v.begin()+x)       	// delete a range in array

//Stack
/*  stack<int> s;						//declaring stack
s.push(1)						// enter  element in stack
s.top()							//returns top element in stack
s.pop()							//removes top element in  stack
*/
// pair
#define pii pair<int,int>					//pair integers
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)			// entering pair element in vector(size not defined)

//Hashmap
/* map<string,string> a;				//declaration
a[“abc”]=”xyz”;					// element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;			//iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");		//finding element in map
  cout << itz->second;

//*/

using namespace std;
int co[10005];
bool vis[10005];
int cnt=0;
vi graph[10005];
void dfs(int i,int c)
{
    //cout<<i sp co[i] sp c sp cnt<<endl;
    vis[i]=1;
    if(co[i]!=c)cnt++;
    for(auto j:graph[i])
    {
        if(!vis[j])dfs(j,co[i]);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,u;
  cin>>n;

  vi h(n+1),v1,v2;
  int f=1;
  for0(i,n+1)cin>>h[i];
  for(int i=0;i<n+1;i+=2)if(h[i]!=1)f=0;
        //cout<<0<<" ";
        int a=0,b=0;
        for0(i,n+1)
        {
            for(int j=0;j<h[i];j++)
            {
                v1.pb(a);
                b++;
            }
            a=a+b;
            b=0;
        }
        //cout<<endl;
        //<<0<<" ";
        a=0;
        int cnt=0;
        for(int i=0;i<n+1;i++)
        {
            for(int j=0;j<h[i];j++)
            {

                int c=min(1,j);
                c=max(a-c,i);
                v2.pb(c);
                b++;
                cnt++;
            }
            a=a+b;
            b=0;
        }
    if(f)cout<<"perfect";
    else {cout<<"ambiguous\n"; for0(k,v1.size())cout<<v1[k]<<" ";
        cout<<endl;for0(k,v2.size())cout<<v2[k]<<" ";
        }
  return 0;
}


#include "bits/stdc++.h"
using namespace std;

//Utility functions
#define pb push_back
#define sz size()
#define mp make_pair
#define fi first
#define se second
#define foreach(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) //traverse an STL data structure
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } //sort array of objects(structs)[Lambda function]
//sort(begin(v), end(v), [] (int a, int b) { return a > b; });

//Constants
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define MOD 998244353

//Printing
#define coutRV(a,L,R) FE(i,L,R) cout<<a[i]<<" \n"[i==R] ;
#define coutV(a) coutRV(a,0,a.size()-1)

//For loops
#define F(i,a,b)    for(int i=a; i<b; i++)
#define FE(i,a,b)   for(int i=a; i<=b; i++)
#define FRE(i,b,a)  for(int i=b; i>=a; i--)
#define FA(n,container)   for(auto n : container)

//For debug
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

//Definitions
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vviwv(vecname, N, M, value) vector<vector<int> > vecname(N, vector<int> (M, value)) //For DP
#define vvlwv(vecname, N, M, value) vector<vector<ll> > vecname(N, vector<ll> (M, value)) //For DP
#define pii pair<int,int>
#define ll long long
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

//Directions
const int fx[4][2]  = {{0,1}, {0,-1}, {1,0}, {-1,0}};
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};

//Input
#define cini(i) int i; cin>>i;
#define cini2(i,j) int i,j; cin>>i>>j;
#define cini3(i,j,k) int i,j,k; cin>>i>>j>>k;
#define cini4(i,j,k,l) int i,j,k,l; cin>>i>>j>>k>>l;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cins(s) string s; cin>>s;
#define cinv(a, n) vi a(n); F(i,0,n) { cin>>a[i]; }
#define cinvll(a, n) vll a(n); F(i,0,n) { cin>>a[i]; }
#define cinvs(s, n) vs s(n); F(i,0,n) { cin>>s[i]; }
#define cinvd(a, n) vd a(n); F(i,0,n) { cin>>a[i]; }

//
//Input
//The first line contains single integer n (3 ≤ n ≤ 2·105) — the number of squares in the park.
//
//Each of the next (n - 1) lines contains two integers x and y (1 ≤ x, y ≤ n) — the indices of two
//squares directly connected by a path.
//
//It is guaranteed that any square is reachable from any other using the paths.
//
//Output
//In the first line print single integer k — the minimum number of colors Andryusha has to use.
//
//In the second line print n integers, the i-th of them should be equal to the balloon color on the i-th
//square. Each of these numbers should be within range from 1 to k.
//

//int N = 2e5+10;
//vvi gr(N);
//vi deg(N,0);
//int cnt=1;
//vi color(N,0);
//vi parent(N,-1);
//
//void dfs(int u)
//{
//	FA(v, gr[u])
//	{
//		if(v==parent[u])
//			continue;
//		int pcolor = color[parent[u]];
//		int gcolor = color[parent[parent[u]]];
//		int mini   = min(pcolor, gcolor);
//		if(pcolor!=1)
//			color[v] = 1;
//		else if(gcolor!=2)
//			color[v] = 2;
//		else
//			color[v] = 3;
//		dfs(v);
//	}
//	return;
//}
//
//int main()
//{
//    fastIO;
//    cini(n);
//    F(i,0,n-1)
//    {
//    	cini2(u,v);
//    	gr[u].pb(v);
//    	gr[v].pb(u);
//    	deg[u]++;
//    	deg[v]++;
//    }
//
//    int k = *max_element(all(deg)) + 1;
//    cout<<k<< endl;
//    color[1]=cnt++;
//    parent[1] = -1;
//
//    FA(v, gr[1])
//    {
//    	color[v] = cnt++ ;
//    	parent[v] = 1;
//    }
//
//    FA(v, gr[1])
//    {
//    	FA(z, gr[v])
//    	{
//    		parent[z] = v;
//    		dfs(z);
//    	}
//    }
//
//    return 0;
//}
//
//

int N = 2e5+10;
vi par1(N,0);
vi par2(N,0);

int main()
{
	cini(h);
	cinv(a,h+1);
	int n = accumulate(all(a),0);
	int mark=0;
	FRE(i,h,0)
	{
		if(a[i]!=1)
		{
			mark=i;
			break;
		}
	}
	if(!mark)
	{
		cout<<"perfect";
		return 0;
	}
	cout<<"ambiguous"<<endl;
	par1[1] = 0;
	int till = 1;
	int lefti = 1;
	F(i,1,h+1)
	{
		int x = a[i];
		debug(i,x);
		FE(j,till+1, till+x)
		{
			par1[j] = lefti;;
		}
		lefti = till+1;
		till = till+x;
		debug(lefti, till);
	}

	par2[1] = 0;
	till = 1;
	lefti = 1;
	F(i,1,h+1)
	{
		int x = a[i];
		debug(i,x);

		if(i==mark)
		{
			FE(j,till+1, till+x-1)
			{
				par2[j] = lefti;
			}
			par2[till+x] = lefti+1;
			lefti = till+1;
			till = till+x;
			debug(lefti, till);
			continue;
		}

		FE(j,till+1, till+x)
		{
			par2[j] = lefti;
		}
		lefti = till+1;
		till = till+x;
		debug(lefti, till);
	}

	coutRV(par1,1,n);
	coutRV(par2,1,n);
}


#include "bits/stdc++.h"
using namespace std;

//Utility functions
#define pb push_back
#define sz size()
#define mp make_pair
#define fi first
#define se second
#define foreach(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) //traverse an STL data structure
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } //sort array of objects(structs)[Lambda function]
//sort(begin(v), end(v), [] (int a, int b) { return a > b; });

//Constants
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define MOD 998244353

//Printing
#define coutRV(a,L,R) FE(i,L,R) cout<<a[i]<<" \n"[i==R] ;
#define coutV(a) coutRV(a,0,a.size()-1)

//For loops
#define F(i,a,b)    for(int i=a; i<b; i++)
#define FE(i,a,b)   for(int i=a; i<=b; i++)
#define FRE(i,b,a)  for(int i=b; i>=a; i--)
#define FA(n,container)   for(auto n : container)

//For debug
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

//Definitions
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vvi vector<vector<int> > //For UnGraph
#define vvpi vector<vector<pii> > //For DirGraph
#define vviwv(vecname, N, M, value) vector<vector<int> > vecname(N, vector<int> (M, value)) //For DP
#define vvlwv(vecname, N, M, value) vector<vector<ll> > vecname(N, vector<ll> (M, value)) //For DP
#define pii pair<int,int>
#define ll long long
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

//Directions
const int fx[4][2]  = {{0,1}, {0,-1}, {1,0}, {-1,0}};
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};

//Input
#define cini(i) int i; cin>>i;
#define cini2(i,j) int i,j; cin>>i>>j;
#define cini3(i,j,k) int i,j,k; cin>>i>>j>>k;
#define cini4(i,j,k,l) int i,j,k,l; cin>>i>>j>>k>>l;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cins(s) string s; cin>>s;
#define cinv(a, n) vi a(n); F(i,0,n) { cin>>a[i]; }
#define cinvll(a, n) vll a(n); F(i,0,n) { cin>>a[i]; }
#define cinvs(s, n) vs s(n); F(i,0,n) { cin>>s[i]; }
#define cinvd(a, n) vd a(n); F(i,0,n) { cin>>a[i]; }

//
//Input
//The first line contains single integer n (3 ≤ n ≤ 2·105) — the number of squares in the park.
//
//Each of the next (n - 1) lines contains two integers x and y (1 ≤ x, y ≤ n) — the indices of two
//squares directly connected by a path.
//
//It is guaranteed that any square is reachable from any other using the paths.
//
//Output
//In the first line print single integer k — the minimum number of colors Andryusha has to use.
//
//In the second line print n integers, the i-th of them should be equal to the balloon color on the i-th
//square. Each of these numbers should be within range from 1 to k.
//

//int N = 2e5+10;
//vvi gr(N);
//vi deg(N,0);
//int cnt=1;
//vi color(N,0);
//vi parent(N,-1);
//
//void dfs(int u)
//{
//	FA(v, gr[u])
//	{
//		if(v==parent[u])
//			continue;
//		int pcolor = color[parent[u]];
//		int gcolor = color[parent[parent[u]]];
//		int mini   = min(pcolor, gcolor);
//		if(pcolor!=1)
//			color[v] = 1;
//		else if(gcolor!=2)
//			color[v] = 2;
//		else
//			color[v] = 3;
//		dfs(v);
//	}
//	return;
//}
//
//int main()
//{
//    fastIO;
//    cini(n);
//    F(i,0,n-1)
//    {
//    	cini2(u,v);
//    	gr[u].pb(v);
//    	gr[v].pb(u);
//    	deg[u]++;
//    	deg[v]++;
//    }
//
//    int k = *max_element(all(deg)) + 1;
//    cout<<k<< endl;
//    color[1]=cnt++;
//    parent[1] = -1;
//
//    FA(v, gr[1])
//    {
//    	color[v] = cnt++ ;
//    	parent[v] = 1;
//    }
//
//    FA(v, gr[1])
//    {
//    	FA(z, gr[v])
//    	{
//    		parent[z] = v;
//    		dfs(z);
//    	}
//    }
//
//    return 0;
//}
//
//

int N = 2e5+10;
vi par1(N,0);
vi par2(N,0);

int main()
{
	cini(h);
	cinv(a,h+1);
	int n = accumulate(all(a),0);

	int mark1=0,cut;
	FE(i,0,h-1)
	{
		if(a[i]>1 && a[i+1]>1)
		{
			cut=i;
			mark1=1;
		}
	}
	if(!mark1)
	{
		cout<<"perfect";
		return 0;
	}

	cout<<"ambiguous"<<endl;
	par1[1] = 0;
	int till = 1;
	int lefti = 1;
	FE(i,1,h)
	{
		int x = a[i];
		debug(i,x,till,lefti);
		FE(j,till+1, till+x)
		{
			par1[j] = lefti;;
		}
		lefti = till+1;
		till = till+x;
		debug(lefti, till);
	}

	par2[1] = 0;
	till = 1;
	lefti = 1;
	F(i,1,h+1)
	{
		int x = a[i];
		debug(i,x);

		if(i==cut+1)
		{
			FE(j,till+1, till+x-1)
			{
				par2[j] = lefti;
			}
			par2[till+x] = lefti+1;
			lefti = till+1;
			till = till+x;
			debug(lefti, till);
			continue;
		}

		FE(j,till+1, till+x)
		{
			par2[j] = lefti;
		}
		lefti = till+1;
		till = till+x;
		debug(lefti, till);
	}

	coutRV(par1,1,n);
	coutRV(par2,1,n);
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int h;
    cin >> h;
    ++h;
    vi a(h);

    int n = 0;
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
        n += a[i];
    }

    if (a[0] != 1) {
        cout << "perfect\n";
        return 0;
    }

    vi left_par(n), right_par(n);
    left_par[0] = right_par[0] = -1;
    int s = 1;
    for (int i = 1; i < h; ++i) {
        int old_s = s - a[i - 1];
        int e = s + a[i];

        for (int j = s; j < e; ++j) {
            left_par[j] = old_s;
            right_par[j] = s - 1;
        }

        s = e;
    }

    if (left_par == right_par) {
        cout << "perfect\n";
    } else {
        cout << "ambiguous\n";
        for (int i = 0; i < n; ++i) {
            cout << left_par[i] + 1 << ' ';
        }
        cout << '\n';
        for (int i = 0; i < n; ++i) {
            cout << right_par[i] + 1 << ' ';
        }
        cout << '\n';
    }

    return 0;
}