Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
b = [int(x) for x in input().split()]
li=[]
def dfs(B,li):
    if(B == []):
        return True
    if(max(B)>len(B)):
        return False
    for index,i in enumerate(B):
        if(index == i-1):
            if(index == 0):
                if(dfs(B[1:],li)):
                    li.append(i)
                    return True
            else:
                if(dfs(B[:index]+B[index+1:],li)):
                    li.append(i)
                    return True
    return False

if(dfs(b,li)):
    for i in li:
        print(i)
else:
    print(-1)

Fixed submission:
N = int(input())
b = [int(x) for x in input().split()]
li=[]
def dfs(B,li):
    cand = []
    if(B == []):
        return True
    if(max(B)>len(B)):
        return False
    for i in range(1,len(B)+1):
        if(i in B):
            if(B.index(i)+1<i):
                return False
            elif(B.index(i)+1==i):
                cand.append(i)

    for i in cand:
        if(dfs(B[:i-1]+B[i:],li)):
            li.append(i)
            return True

    return False

if(dfs(b,li)):
    for i in li:
        print(i)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
b = [int(x) for x in input().split()]
li=[]
def dfs(B,li):
    if(B == []):
        return True
    for index,i in enumerate(B):
        if(index == i-1):
            if(index == 0):
                if(dfs(B[1:],li)):
                    li.append(i)
                    return True
            else:
                if(dfs(B[:index]+B[index+1:],li)):
                    li.append(i)
                    return True
    return False

if(dfs(b,li)):
    for i in li:
        print(i)
else:
    print(-1)


Fixed submission:
N = int(input())
b = [int(x) for x in input().split()]
li=[]
def dfs(B,li):
    cand = []
    if(B == []):
        return True
    if(max(B)>len(B)):
        return False
    for i in range(1,len(B)+1):
        if(i in B):
            if(B.index(i)+1<i):
                return False
            elif(B.index(i)+1==i):
                cand.append(i)

    for i in cand:
        if(dfs(B[:i-1]+B[i:],li)):
            li.append(i)
            return True

    return False

if(dfs(b,li)):
    for i in li:
        print(i)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
b = [int(x) for x in input().split()]
li=[]
def dfs(B,li):
    if(B == []):
        return True
    for index,i in enumerate(B):
        if(index == i-1):
            if(index == 0):
                if(dfs(B[1:],li)):
                    li.append(i)
                    return True
            else:
                if(dfs(B[:index]+B[index+1:],li)):
                    li.append(i)
                    return True
    return False

if(dfs(b,li)):
    for i in li:
        print(i)
else:
    print(-1)


Fixed submission:
N = int(input())
b = [int(x) for x in input().split()]
li=[]
def dfs(B,li):
    cand = []
    if(B == []):
        return True
    if(max(B)>len(B)):
        return False
    for i in range(1,len(B)+1):
        if(i in B):
            if(B.index(i)+1<i):
                return False
            elif(B.index(i)+1==i):
                cand.append(i)

    for i in cand:
        if(dfs(B[:i-1]+B[i:],li)):
            li.append(i)
            return True

    return False

if(dfs(b,li)):
    for i in li:
        print(i)
else:
    print(-1)