Help me in solving PERMUT2 problem

My issue

Receiving the below Error while submitting the code.

Please suggest the solution.

My code

n = int(input())
while(n!=0):
    A = list(map(int, input().split()))
    InA = [n]
    count = 0
    for i in range (0,n):
        for j in range(0,n-1):
            if A[j] == i+1:
                InA.insert(i, j+1)
            j += 1 
        i += 1
    
    for k in range(0,n):
        if A[k] == InA[k]:
          count += 1 
    if count == n:
        print("ambiguous")
    else:
        print("not ambiguous")
    n = int(input())    

Problem Link: PERMUT2 Problem - CodeChef