Buggy python submission (verdict: Runtime Error):
root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        for i in temp[-1]:
            root.append(i)
            string.pop(i-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)

Fixed submission:
import copy

N=int(input())
a = list(map(int,input().split()))


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        root.append(temp[-1])
        string.pop(temp[-1]-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import sys

sys.setrecursionlimit(200000000)

N=int(input())
a = list(map(int,input().split()))

def dfs(string, root):
    temps = [i+1 for i in range(len(string))]
    output=-1
    if len(string)==0:
        return root
    
    for i,s in enumerate(string):
        if i+1==s:
            temp_root = copy.deepcopy(root)
            temp_string=copy.deepcopy(string)
            temp_root.append(i+1)
            temp_string.pop(i)
            temp = dfs(temp_string, temp_root)
            
            if temp!=-1:
                output=temp
                break
    return output

output=dfs(a, [])

output

if isinstance(output, list):
    for i in output[::-1]:
        print(i)
else:
    print(output)

Fixed submission:
import copy

N=int(input())
a = list(map(int,input().split()))


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        root.append(temp[-1])
        string.pop(temp[-1]-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import sys

sys.setrecursionlimit(200000000)

N=int(input())
a = list(map(int,input().split()))
values = set(a)

dicts={}
def dfs(string, root):
    temps = [i+1 for i in range(len(string))]
    output=-1
    if len(string)==0:
        return root
    
    for i,s in enumerate(string):
        if i+1==s:
            temp_root = copy.deepcopy(root)
            temp_string=copy.deepcopy(string)
            temp_root.append(i+1)
            temp_string.pop(i)
            temp = dfs(temp_string, temp_root)
            
            if temp!=-1:
                output=temp
    return output

output=dfs(a, [])

output

if isinstance(output, list):
    for i in output[::-1]:
        print(i)
else:
    print(output)

Fixed submission:
import copy

N=int(input())
a = list(map(int,input().split()))


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        root.append(temp[-1])
        string.pop(temp[-1]-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import sys

sys.setrecursionlimit(200000000)

N=int(input())
a = list(map(int,input().split()))
values = set(a)

dicts={}
def dfs(index, string, values, N, root):
    temp=[]
    if index == N:
        dicts[" ".join(list(map(str,string)))] = root
        return None
    
    length = len(string)+1
    
    for i in values:

        if i > index:
            break
        temp_str = copy.deepcopy(string)
        temp_root = copy.deepcopy(root)
        temp_str.insert(i-1,i)
        temp_root.append(i)
        
        dfs(index+1, temp_str, values, N, temp_root)
        

        

dfs(1,[], values, N+1, [])

output = " ".join(list(map(str,a)))

if output in dicts:
    for i in dicts[output]:
        print(i)
else:
    print(-1)

Fixed submission:
import copy

N=int(input())
a = list(map(int,input().split()))


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        root.append(temp[-1])
        string.pop(temp[-1]-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)