Some programming contest problems are really tricky: not only do they
require a different output format from what you might have expected, but
also the sample output does not show the difference. For an example,
let us look at permutations.

A permutation of the integers 1 to n is an
ordering of
these integers. So the natural way to represent a permutation is
to list the integers in this order. With n = 5, a
permutation might look like 2, 3, 4, 5, 1. 

However, there is another possibility of representing a permutation:
You create a list of numbers where the i-th number is the
position of the integer i in the permutation. 
Let us call this second
possibility an inverse permutation. The inverse permutation
for the sequence above is 5, 1, 2, 3, 4.

An ambiguous permutation is a permutation which cannot be
distinguished from its inverse permutation. The permutation 1, 4, 3, 2
for example is ambiguous, because its inverse permutation is the same.
To get rid of such annoying sample test cases, you have to write a
program which detects if a given permutation is ambiguous or not.

-----Input Specification-----
The input contains several test cases.

The first line of each test case contains an integer n
(1 ≤ n ≤ 100000).
Then a permutation of the integers 1 to n follows
in the next line. There is exactly one space character
between consecutive integers.
You can assume that every integer between 1 and n
appears exactly once in the permutation.

The last test case is followed by a zero.

-----Output Specification-----
For each test case output whether the permutation is ambiguous or not.
Adhere to the format shown in the sample output.

-----Sample Input-----
4
1 4 3 2
5
2 3 4 5 1
1
1
0

-----Sample Output-----
ambiguous
not ambiguous
ambiguous

Difficulty: interview

Starter code:

Solutions:
def invper(ar):
 ar1=[0]*(len(ar))
 for i in range(len(ar)):
  ar1[ar[i]-1]=i+1
 return ar1
t=int(input())

while(t!=0):
 ar=list(map(int,input().split()))
 ar1=invper(ar)
 if(ar==ar1):
  print("ambiguous")
 else:
  print("not ambiguous")
 t = int(input())


while int(input()) != 0:
 l = list(map(int,input().split()))
 invArray = [0 for j in range(len(l))]
 for i in range(len(l)):
  invArray[l[i]-1] = i + 1
 if invArray == l:
  print("ambiguous")
 else:
  print("not ambiguous") 


# cook your dish here
def inv(arr):
 arr1 = [0] * (len(arr))
 for i in range(len(arr)):
  arr1[arr[i] - 1] = i + 1
 return arr1

t = int(input())

while t != 0:
 arr = list(map(int, input().split(" ")))
 arr1 = inv(arr)
 if (arr == arr1):
  print("ambiguous")
 else:
  print("not ambiguous")
 t = int(input())

while int(input()) != 0:
 permutation = list(map(int,input().split()))
 inverse_permutation = [0 for i in range(len(permutation))]
 for index in range(len(permutation)):
  inverse_permutation[permutation[index]-1] = index+1
 print('ambiguous') if inverse_permutation == permutation else print('not         ambiguous')
 

while int(input()) != 0:
 permutation = list(map(int,input().split()))
 inverse_permutation = [0 for i in range(len(permutation))]
 for index in range(len(permutation)):
  inverse_permutation[permutation[index]-1] = index+1
 print('ambiguous') if inverse_permutation == permutation else print('not         ambiguous')
 

# cook your dish here
def __starting_point():
 try:
  while int(input()) != 0 :
   l=list(map(int,input().split()))
   l1=[0] * len(l)
   for i in range(len(l)):
    l1[l[i]-1] = i+1
   print("ambiguous" if l == l1 else "not ambiguous" )
 except EOFError :
  print('EOFError')
__starting_point()

# cook your dish here
try:
 def inv(arr):
  arr1 = [0] * (len(arr))
  for i in range(len(arr)):
   arr1[arr[i] - 1] = i + 1
  return arr1
 
 t = int(input())
 while (t != 0):
  arr = list(map(int, input().split(' ')))
  arr1 = inv(arr)
  if (arr == arr1):
   print("ambiguous")
  else:
   print("not ambiguous")
  t = int(input())
except: pass


# cook your dish here
t = int(input())
while t!= 0:
 l = list(map(int, input().split()))
 l1 = [0]*len(l)
 
 for i in range(len(l)):
  l1[l[i]-1] = i+1
  
 if l1 == l:
  print('ambiguous')
 else:
  print('not ambiguous')
 t = int(input())

t = int(input())
while t!= 0:
 l = list(map(int, input().split()))
 l1 = [0]*len(l)
 for i in range(len(l)):
  l1[l[i]-1] = i+1
 if l1 == l:
  print('ambiguous')
 else:
  print('not ambiguous')
 t = int(input())

def invper(ar):
 ar1=[0]*(len(ar))
 for i in range(len(ar)):
  ar1[ar[i]-1]=i+1
 return ar1
t=int(input())

while(t!=0):
 ar=list(map(int,input().split()))
 ar1=invper(ar)
 if(ar==ar1):
  print("ambiguous")
 else:
  print("not ambiguous")
 t = int(input())

# cook your dish here
def invper(ar):
 ar1=[0]*(len(ar))
 for i in range(len(ar)):
  ar1[ar[i]-1]=i+1
 return ar1
t=int(input())
while(t!=0):
 ar=list(map(int,input().split()))
 ar1=invper(ar)
 if(ar==ar1):
  print("ambiguous")
 else:
  print("not ambiguous")
 t = int(input())

def invper(ar):
 ar1=[0]*(len(ar))
 for i in range(len(ar)):
  ar1[ar[i]-1]=i+1
 return ar1
t=int(input())
while(t!=0):
 ar=list(map(int,input().split()))
 ar1=invper(ar)
 if(ar==ar1):
  print("ambiguous")
 else:
  print("not ambiguous")
 t = int(input())

def checker(lst):
 le = len(lst)
 nlst = [0]*le
 for i in range(le):
  nlst[lst[i]-1] = i+1
  

 if nlst == lst:
  print("ambiguous")
 else:
  print("not ambiguous")


def __starting_point():
 while True:
  t = int(input())
  if t == 0:
   return
  else:
   arr = [int(i) for i in input().split()]
   checker(arr)

__starting_point()

# cook your dish here
def invper(ar):
 ar1=[0]*(len(ar))
 for i in range(1,len(ar)):
  ar1[ar[i]]=i
 return ar1
t=int(input())
while(t!=0):
 ar=list(map(int,input().split()))
 ar.insert(0,0)
 ar1=invper(ar)
 if(ar==ar1):
  print("ambiguous")
 else:
  print("not ambiguous")
 t = int(input())

# cook your dish here
n=int(input())
while n:
 l=list(map(int,input().split()))
 invl=[None]*n
 for j in range(n):
  i=j+1
  invl[l[j]-1]=i
 for i in range(n):
  if l[i]!=invl[i]:
   print("not ambiguous")
   break
 else:
  print("ambiguous")
 n=int(input())


while int(input())!= 0:
 x = list(map(int, input().split()))
 y = len(x)
 length = [0]*y
 for i in range(y):
  k = x[i]
  length[k-1] = i+1
 if x == length:
  print("ambiguous")
 else:
  print("not ambiguous")

# cook your dish here
while int(input())!=0:
 l=list(map(int,input().split()))
 ln=len(l)
 ll=[0]*ln
 for i in range(ln):
  k=l[i]
  ll[k-1]=i+1
 if l==ll:
  print("ambiguous")
 else:
  print("not ambiguous")

# cook your dish here
while True:
 n=int(input())
 if n==0:
  break
 l=list(map(int,input().split()))
 l1=[0]*n
 for i in range(n):
  l1[l[i]-1]=i+1
 if l==l1:
  print('ambiguous')
 else :
  print('not ambiguous')


while True:
 n=int(input())
 if n==0:
  break
 li=list(map(int, input().split()))
 
 x=[0]*n


 for i in range(n):
  z=li[i]
  x[z-1]=i+1

 if x==li:
  print("ambiguous")
 else:
  print("not ambiguous")

# cook your dish here
while(int(input())!=0):
  l=list(map(int,input().split()))
  t=len(l)
  l1=[0]*t
  for i in range(t):
   c=l[i]
   l1[c-1]=i+1
  if l==l1:
   print("ambiguous")
  else:
   print("not ambiguous")


while(int(input())):
 l=list(map(int,input().split()))
 h=len(l)
 l1=[0]*h
 for i in range(h):
  c=l[i]
  l1[c-1]=i+1
 if l==l1:
  print("ambiguous")
 else:
  print("not ambiguous")


while(int(input())!=0):
  l=list(map(int,input().split()))
  t=len(l)
  l1=[0]*t
  for i in range(t):
   c=l[i]
   l1[c-1]=i+1
  if l==l1:
   print("ambiguous")
  else:
   print("not ambiguous")


# cook your dish here
t=int(input())
while(t):
 l=list(map(int,input().split()))
 k=10
 for i in range(len(l)):
  if(l[l[i]-1]!=i+1):
   print("not ambiguous")
   k=1
   break
 if(k==10):
  print("ambiguous")
 t=int(input())

while True:
 n = int(input())
 if n==0:
  break
 else:
  ambiguous = 1
  a =[int(k) for k in input().split()]
  for i in range(0, n):
   if a[i]- 1 >= n or a[i] < 1 or a[a[i] - 1] != i + 1:
    print('not ambiguous')
    ambiguous = 0
    break
  if ambiguous == 1:
   print('ambiguous')

# cook your dish here
while True:
 n=int(input())
 if n==0:
  break
 f=0
 a=[int(x) for x in input().split()]
 for i in range(n):
  if a[a[i]-1]!=i+1:
   print('not ambiguous')
   f=1
   break
 if f==0:
  print('ambiguous')