Please help me with this! I am getting a TLE error in the code of ambiguous permutations.

while True:
n = int(input())
x=1
a=[]
if n > 0:
l = list(map(int, input().split()))
while(x<=n):
for i in range(n):
if(l[i]==x):
g=i+1
a.append(g)
x=x+1
if (l==a):
print(“ambiguous”)
else:
print(“non-ambiguous”)
else:
break

CodeChef: Practical coding for everyone - Link for my solution