Buggy python submission (verdict: Runtime Error):
def remove(data):
    global result
    pos = min(len(data), max(data))
    for n in range(pos-1, -1, -1):
        if data[n] == n + 1:
            result.append(data.pop(n))
            #print('remove {0} '.format(n + 1), end='')
            if len(data) == 0:
                #print('OK')
                return True
            else:
                #print(data)
                if remove(data):
                    return True
    else:
        return False

_ = input()
B = list(map(int, input().split()))

result = []

if remove(B):
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)


Fixed submission:
_ = input()
data = list(map(int, input().split()))

result = []
pos = min(len(data), max(data)) - 1

while pos >= 0:
    if data[pos] == pos + 1:
        x = data.pop(pos)
        #print('remove {0} {1}'.format(x, data))
        result.append(x)
        if len(data) == 0:
            break
        pos = min(len(data), max(data)) - 1
    else:
        pos -= 1

if len(data) == 0:
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
def remove(data):
    global result
    pos = min(len(data), max(data))
    for n in range(pos-1, -1, -1):
        if data[n] == n + 1:
            result.append(n + 1)
            if len(data) == 1:
                #print('OK')
                return True
            else:
                #print('remove {0} '.format(n + 1), end='')
                #print(data[:n] + data[n+1:])
                if remove(data[:n] + data[n+1:]):
                    return True
    else:
        #print('try again')
        if len(result) > 0:
            result.pop(-1)
        return False

_ = input()
B = list(map(int, input().split()))

result = []

if remove(B):
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)


Fixed submission:
_ = input()
data = list(map(int, input().split()))

result = []
pos = min(len(data), max(data)) - 1

while pos >= 0:
    if data[pos] == pos + 1:
        x = data.pop(pos)
        #print('remove {0} {1}'.format(x, data))
        result.append(x)
        if len(data) == 0:
            break
        pos = min(len(data), max(data)) - 1
    else:
        pos -= 1

if len(data) == 0:
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
def remove(data):
    global result
    for n in range(len(data)-1, -1, -1):
        if data[n] == n + 1:
            result.append(n + 1)
            if len(data) == 1:
                #print('OK')
                return True
            else:
                #print('remove {0} '.format(n + 1), end='')
                #print(data[:n] + data[n+1:])
                if remove(data[:n] + data[n+1:]):
                    return True
    else:
        #print('try again')
        if len(result) > 0:
            result.pop(-1)
        return False

_ = input()
B = list(map(int, input().split()))

result = []

if remove(B):
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)


Fixed submission:
_ = input()
data = list(map(int, input().split()))

result = []
pos = min(len(data), max(data)) - 1

while pos >= 0:
    if data[pos] == pos + 1:
        x = data.pop(pos)
        #print('remove {0} {1}'.format(x, data))
        result.append(x)
        if len(data) == 0:
            break
        pos = min(len(data), max(data)) - 1
    else:
        pos -= 1

if len(data) == 0:
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
def remove(data):
    global result
    for n in range(len(data)):
        if data[n] == n + 1:
            result.append(n + 1)
            if len(data) == 1:
                #print('OK')
                return True
            else:
                #print('remove {0} '.format(n + 1), end='')
                #print(data[:n] + data[n+1:])
                if remove(data[:n] + data[n+1:]):
                    return True
    else:
        #print('try again')
        if len(result) > 0:
            result.pop(-1)
        return False

_ = input()
B = list(map(int, input().split()))

result = []

if remove(B):
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)


Fixed submission:
_ = input()
data = list(map(int, input().split()))

result = []
pos = min(len(data), max(data)) - 1

while pos >= 0:
    if data[pos] == pos + 1:
        x = data.pop(pos)
        #print('remove {0} {1}'.format(x, data))
        result.append(x)
        if len(data) == 0:
            break
        pos = min(len(data), max(data)) - 1
    else:
        pos -= 1

if len(data) == 0:
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)