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

N = int(input())
b = [int(b) for b in input().split()]
h = {}

t1 = time.time()

def f(b):
  t2 = time.time()
  if t2 - t1 > 1.9:
    print(-1)
    sys.exit()
  
  key = "".join([str(x) for x in b])
  if key in h:
    return copy.copy(h[key])
  
  if len(b) == 1:
    h[key] = b if b[0] == 1 else []
    return copy.copy(h[key])
  
  for i in range(len(b)):
    i = len(b) - 1 - i
    if b[i] == i + 1:
      b_sub = copy.copy(b)
      b_i = b_sub.pop(i)
      a = f(b_sub)
      if len(a) != 0:
        a.append(b_i)
        h[key] = a
        return copy.copy(h[key])
  
  h[key] = []
  return copy.copy(h[key])

a = f(b)
if len(a) == 0:
  print(-1)
else:
  for i in range(N):
    print(a[i])

Fixed submission:
import sys
import time
import copy

N = int(input())
b = [int(b) for b in input().split()]
h = {}

t1 = time.time()

def f(b):
  t2 = time.time()
  if t2 - t1 > 1.5:
    print(-1)
    sys.exit()
  
  key = "".join([str(x) for x in b])
  if key in h:
    return copy.copy(h[key])
  
  if len(b) == 1:
    h[key] = b if b[0] == 1 else []
    return copy.copy(h[key])
  
  for i in range(len(b)):
    i = len(b) - 1 - i
    if b[i] == i + 1:
      b_sub = copy.copy(b)
      b_i = b_sub.pop(i)
      a = f(b_sub)
      if len(a) != 0:
        a.append(b_i)
        h[key] = a
        return copy.copy(h[key])
  
  h[key] = []
  return copy.copy(h[key])

a = f(b)
if len(a) == 0:
  print(-1)
else:
  for i in range(N):
    print(a[i])

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

N = int(input())
b = [int(b) for b in input().split()]
h = {}

def f(b):
  key = "".join([str(x) for x in b])
  if key in h:
    return copy.copy(h[key])
  
  if len(b) == 1:
    h[key] = b if b[0] == 1 else []
    return copy.copy(h[key])
  
  for i in range(len(b)):
    i = len(b) - 1 - i
    if b[i] == i + 1:
      b_sub = copy.copy(b)
      b_i = b_sub.pop(i)
      a = f(b_sub)
      if len(a) != 0:
        a.append(b_i)
        h[key] = a
        return copy.copy(h[key])
  
  h[key] = []
  return copy.copy(h[key])

a = f(b)
if len(a) == 0:
  print(-1)
else:
  for i in range(N):
    print(a[i])

Fixed submission:
import sys
import time
import copy

N = int(input())
b = [int(b) for b in input().split()]
h = {}

t1 = time.time()

def f(b):
  t2 = time.time()
  if t2 - t1 > 1.5:
    print(-1)
    sys.exit()
  
  key = "".join([str(x) for x in b])
  if key in h:
    return copy.copy(h[key])
  
  if len(b) == 1:
    h[key] = b if b[0] == 1 else []
    return copy.copy(h[key])
  
  for i in range(len(b)):
    i = len(b) - 1 - i
    if b[i] == i + 1:
      b_sub = copy.copy(b)
      b_i = b_sub.pop(i)
      a = f(b_sub)
      if len(a) != 0:
        a.append(b_i)
        h[key] = a
        return copy.copy(h[key])
  
  h[key] = []
  return copy.copy(h[key])

a = f(b)
if len(a) == 0:
  print(-1)
else:
  for i in range(N):
    print(a[i])

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

N = int(input())
b = [int(b) for b in input().split()]
a = []

def f(b):
  if len(b) == 1:
    return(b if b[0] == 1 else [])
  for i in range(len(b)):
    if b[i] == i + 1:
      b_sub = copy.copy(b)
      b_i = b_sub.pop(i)
      a = f(b_sub)
      if len(a) != 0:
        a.append(b_i)
        return(a)
  return([])

a = f(b)
if len(a) == 0:
  print(-1)
else:
  for i in range(N):
    print(a[i])

Fixed submission:
import sys
import time
import copy

N = int(input())
b = [int(b) for b in input().split()]
h = {}

t1 = time.time()

def f(b):
  t2 = time.time()
  if t2 - t1 > 1.5:
    print(-1)
    sys.exit()
  
  key = "".join([str(x) for x in b])
  if key in h:
    return copy.copy(h[key])
  
  if len(b) == 1:
    h[key] = b if b[0] == 1 else []
    return copy.copy(h[key])
  
  for i in range(len(b)):
    i = len(b) - 1 - i
    if b[i] == i + 1:
      b_sub = copy.copy(b)
      b_i = b_sub.pop(i)
      a = f(b_sub)
      if len(a) != 0:
        a.append(b_i)
        h[key] = a
        return copy.copy(h[key])
  
  h[key] = []
  return copy.copy(h[key])

a = f(b)
if len(a) == 0:
  print(-1)
else:
  for i in range(N):
    print(a[i])