CodeEff/ECCO huggingface dataset:
# Original solution
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


class SEGMENT_TREE:
    def __init__(self, N):
        self.N = N
        self.tree = [0] * (2 * N)  # 問題により修正

    def init(self, arr):
        N = self.N
        for i in range(N):
            self.tree[N + i] = arr[i]
        for i in range(N - 1, 0, -1):
            self.tree[i] = gcd(
                self.tree[i * 2], self.tree[i * 2 + 1])  # 問題により修正

    def update(self, p, value):
        i = p + self.N
        self.tree[i] = value
        while i > 1:
            self.tree[i >> 1] = gcd(self.tree[i], self.tree[i ^ 1])  # 問題により修正
            i >>= 1

    def query(self, l, r):
        N = self.N
        res = 0  # 問題により修正
        l += N
        r += N
        while l < r:
            if (l & 1):
                res = gcd(res, self.tree[l])  # 問題により修正
                l += 1
            if (r & 1):
                r -= 1
                res = gcd(res, self.tree[r])  # 問題により修正
            l >>= 1
            r >>= 1
        return res


if __name__ == "__main__":
    N = int(eval(input()))
    A = list(map(int, input().split()))
    seg = SEGMENT_TREE(N)
    seg.init(A)
    ans = 0
    for i, a in enumerate(A):
        seg.update(i, 0)
        ans = max(ans, seg.query(0, N))
        seg.update(i, a)

    print(ans)

# Optimized solution
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


class SEGMENT_TREE:
    def __init__(self, N):
        self.N = N
        self.tree = [0] * (2 * N)  # 問題により修正

    def init(self, arr):
        N = self.N
        for i in range(N):
            self.tree[N + i] = arr[i]
        for i in range(N - 1, 0, -1):
            self.tree[i] = gcd(
                self.tree[i * 2], self.tree[i * 2 + 1])  # 問題により修正

    def update(self, p, value):
        i = p + self.N
        self.tree[i] = value
        while i > 1:
            self.tree[i // 2] = gcd(self.tree[i], self.tree[i ^ 1])  # 問題により修正
            i //= 2

    def query(self, l, r):
        N = self.N
        res = 0  # 問題により修正
        l += N
        r += N
        while l < r:
            if (l & 1):
                res = gcd(res, self.tree[l])  # 問題により修正
                l += 1
            if (r & 1):
                r -= 1
                res = gcd(res, self.tree[r])  # 問題により修正
            l //= 2
            r //= 2
        return res


if __name__ == "__main__":
    N = int(eval(input()))
    A = list(map(int, input().split()))
    seg = SEGMENT_TREE(N)
    seg.init(A)
    ans = 0
    for i in range(N):
        tmp = gcd(seg.query(0, i), seg.query(i + 1, N))
        ans = max(ans, tmp)
    print(ans)
# Original solution
def make_divisors(n):
    divisors = []

    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort(reverse=True)
    return divisors


N = int(eval(input()))
A = sorted([int(x) for x in input().split()])
ans = 1

for i in range(2):
    divisors = make_divisors(A[i])

    for divisor in divisors:
        indivisible_count = 0
        for j in range(N):
            if A[j] % divisor != 0:
                indivisible_count += 1

        if indivisible_count <= 1 and divisor > ans:
            ans = divisor

print(ans)


# Optimized solution
def make_divisors(n):
    divisors = []

    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors


N = int(eval(input()))
A = sorted([int(x) for x in input().split()])

ans = 1
divisors = make_divisors(A[0]) + make_divisors(A[1])
divisors = sorted(set(divisors), reverse=True)

for divisor in divisors:
    indivisible_count = 0
    for i in range(N):
        if A[i] % divisor != 0:
            indivisible_count += 1

    if indivisible_count <= 1:
        ans = divisor
        break

print(ans)
# Original solution
# 2019-11-18 00:38:19(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 

def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
    s = sys.stdin.readline().rstrip()

    happy_count = 0
    happy_count += sum(1 for i in range(n-1) if s[i] == s[i+1])
    
    happy_count += 2 * k
    ans = min(happy_count, n - 1)
    print(ans)
    
if __name__ == "__main__":
    main()



# Optimized solution
# 2019-11-18 00:38:19(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 

def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
    s = sys.stdin.readline().rstrip()

    happy_count = sum([0] + [1 for i in range(n-1) if s[i] == s[i+1]])
    
    happy_count += 2 * k
    ans = min(happy_count, n - 1)
    print(ans)
        
if __name__ == "__main__":
    main()
# Original solution
N,K=list(map(int, input().split()))
S=list(input())

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

for i in range(1,min(K*2,l),2):
	s=L[i][0]
	if s=="L": L[i][0]="R"
	elif s=="R": L[i][0]="L"


ans=0
prev=None
for t in L:
	s=t[0]
	cnt=t[1]
	if prev is None:
		prev=s
		lcnt=cnt
	else:
		if prev==s:
			lcnt+=cnt
		elif prev!=s:
			ans+=(lcnt-1)
			lcnt=cnt
		prev=s
else:
	ans+=(lcnt-1)
	
print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
import sys
N,K=list(map(int, sys.stdin.readline().split()))
S=sys.stdin.readline().strip()
L=[]
cnt=0
for i,x in enumerate(S):
    if i==0:
        cnt+=1
        prev=x
    else:
        if prev==x: #前の文字と今の文字が同じ
            cnt+=1
        else:       #前の文字と今の文字が異なる
            L.append(cnt)
            cnt=1
        prev=x
else:
    L.append(cnt)

print(sum(L)-max(1,len(L)-2*K))
# Original solution
import sys,math,collections,itertools
input = sys.stdin.readline

N,K=list(map(int,input().split()))
S=input().rstrip()

ori_num=0
turn_num=0
for i in range(N):
    if i>0:
        if S[i-1] =='L' and S[i] =='L':
            ori_num += 1
        if S[i-1] != S[i]:
            turn_num +=1
        
    if i<N-1:
        if S[i] =='R' and S[i+1] =='R':
            ori_num += 1
while K:
    if turn_num >1:
        turn_num -= 2
        K -= 1
        ori_num += 2
    elif turn_num ==1:
        ori_num +=1
        K=0
print(ori_num)


# Optimized solution
import sys,math,collections,itertools
input = sys.stdin.readline

N,K=list(map(int,input().split()))
S=input().rstrip()

ori_num=0
turn_num=0
for i in range(N):
    if i>0:
        if S[i-1] =='L' and S[i] =='L':
            ori_num += 1
        if S[i-1] != S[i]:
            turn_num +=1
        
    if i<N-1:
        if S[i] =='R' and S[i+1] =='R':
            ori_num += 1

if turn_num >=2*K:
    ori_num += 2*K
else:
    num = turn_num//2
    num2 = turn_num%2
    ori_num += 2*num+num2
    
print(ori_num)
# Original solution
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    cnt = 0
    for i in range(1, n):
        if s[i-1] == s[i]:
            cnt += 1
    print((min(n - 1, cnt + k * 2)))


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    cnt = 0
    for i in range(1, n):
        if s[i] == s[i-1]:
            cnt += 1
    print((min(n - 1, cnt + k * 2)))


if __name__ == '__main__':
    solve()
# Original solution
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc140/tasks/abc140_d

N, K = list(map(int, input().split()))
S = input().strip()

happiness = 0
for idx in range(1, N):
    if S[idx] == S[idx - 1]:
        happiness += 1

# 一人しか幸せにできないときがあるか?
#
# あっ...これは不要なのでは...
# 単に後述の幸せの最大値で丸めればよいのでは
# always_two_happiness = S[0] == S[-1]

# 幸せの最大値
max_happiness = N - 1

for i in range(K):
    happiness += 2

print((min(happiness, max_happiness)))


# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N, K = list(map(int, input().split()))
S = input().strip()

# 初期の幸せ度を調べる
happiness = 0
previous_face = S[0]
for i in range(1, N):
    if S[i] == previous_face:
        happiness += 1
    else:
        previous_face = S[i]

# 並べ替え後の幸せ度
happiness = happiness + 2 * K
if N - 1 < happiness:
    happiness = N - 1

# 出力
print(happiness)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = list(map(int, input().split()))
s = input().rstrip()

def split(s):
    new = [s[0]]
    for i in range(n-1):
        if s[i] != s[i+1]:
            new.append(s[i+1])
        else:
            new[-1] += s[i+1]
    return new

def transform(s, k):
    for _ in range(k):
        s = split(s)
        if len(s) == 1:
            s = ''.join(s)
            break
        idx = 1
        s[idx] = s[idx].replace('L', 'X').replace('R', 'L').replace('X', 'R')
        s = ''.join(s)
    return s


s = transform(s, k)


def count(s):
    cnt = 0
    for i in range(n):
        if i+1 < len(s) and s[i] == 'R' and s[i+1] == 'R':
            cnt += 1
        elif i-1 >= 0 and s[i] == 'L' and s[i-1] == 'L':
            cnt += 1
    return cnt


print((count(s)))


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = list(map(int, input().split()))
s = input().rstrip()

def count(s):
    cnt = 0
    for i in range(n):
        if i+1 < len(s) and s[i] == 'R' and s[i+1] == 'R':
            cnt += 1
        elif i-1 >= 0 and s[i] == 'L' and s[i-1] == 'L':
            cnt += 1
    return cnt


print((min(count(s)+2*k, n-1)))
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(eval(input()))
def getList():
    return list(map(int, input().split()))
import math

n, k = getList()

s = input().strip()
s = s

state = "X"
cur_seq = 0
seq_nums = []
n_separate = 0


for c in s:
    # print(c, state == c)
    if state == c:
        cur_seq += 1
    else:
        state = c
        seq_nums.append(cur_seq)
        cur_seq = 1
        n_separate += 1


# print(n_separate)
print((min(n - n_separate + 2 * k, n - 1)))



# Optimized solution
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
 
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def getmoji(k):
    return chr(ord("a") + k)

def main():
    n, k = getList()
    s = getS()

    ko, fuko = 0, 0
    for i, j in zip(s, s[1:]):
        if i == j:
            ko += 1
        else:
            fuko += 1
    print((ko + min(k*2, fuko)))


if __name__ == "__main__":
    main()
# Original solution
import sys

input = sys.stdin.readline

ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def rle(s):
    import itertools
    return list([(x[0], len(list(x[1]))) for x in itertools.groupby(s)])


n, k = ril()
s = rs()
s = rle(s)
m = len(s)
if m <= 2 * k:
    print((n - 1))
else:
    print((n - m + 2 * k))

# Optimized solution
import sys

input = sys.stdin.readline

ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, k = ril()
s = rs()
m = 1
for c0, c1 in zip(s, s[1:]):
    if c0 != c1:
        m += 1
if m <= 2 * k:
    print((n - 1))
else:
    print((n - m + 2 * k))
# Original solution
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = list(map(int, readline().split()))
    S = readline().strip()

    ans = groups = 0
    for k, g in groupby(S):
        ans += len(list(g)) - 1
        groups += 1

    ans += 2 * K
    if ans > N - 1:
        ans = N - 1

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = list(map(int, readline().split()))
    S = readline().strip()

    ans = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            ans += 1

    ans += 2 * K
    if ans > N - 1:
        ans = N - 1

    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
b = LI()

result = []
while True:
    #  print(b)
    for i in range(1, len(b)+1):
        #  print(i)
        if b[-i] == len(b)-i+1:
            #  print('break')
            result.append(b[-i])
            del b[-i]
            break
    else:
        if not b:
            break
        print(-1)
        exit()
for i in result[::-1]:
    print(i)


# Optimized solution
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
b = LI()

result = []
while True:
    #  print(b)
    for i in range(1, len(b)+1):
        #  print(i)
        if b[-i] == len(b)-i+1:
            #  print('break')
            result.append(b[-i])
            b.pop(-i)
            break
    else:
        if not b:
            break
        print(-1)
        exit()
for i in result[::-1]:
    print(i)
# Original solution
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
b = LI()

result = []
while True:
    #  print(b)
    for i in range(1, len(b)+1):
        #  print(i)
        if b[-i] == len(b)-i+1:
            #  print('break')
            result.append(b[-i])
            b.pop(-i)
            break
    else:
        if not b:
            break
        print(-1)
        exit()
for i in result[::-1]:
    print(i)




# Optimized solution
N = int(input())
B = [int(x) - 1 for x in input().split()]
#  print('b', B)
ans = []
while B:
    popped = -1
    for i in reversed(range(len(B))):
        if B[i] == i:
            ans.append(i + 1)
            popped = B.pop(i)
            break
    if popped == -1:
        print(-1)
        quit()
print(*ans[::-1], sep="\n")
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
ansL=[]
c=0
f=0
for j in range(n):
  for i in range(len(l)-1,-1,-1):
    if l[i]==i+1:
      ansL.append(l.pop(i))
      c+=1
      break
if c!=n:
  print((-1))
else:
  for k in range(len(ansL)-1,-1,-1):
    print((ansL[k]))

# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
L=[]
c=0
for j in range(n):
  for i in range(len(l)-1,-1,-1):
    if l[i]==i+1:
      L.insert(0,l.pop(i))
      c+=1
      break
if c!=n:
  print((-1))
else:
  for k in range(len(L)):
    print((L[k]))
# Original solution
n=int(eval(input()))
a=[]
b=list(map(int,input().split()))
for i in range(n):
  for j in range(n-i-1,-1,-1):
    if b[j]==j+1:
      a.append(b.pop(j))
      break
if len(a)<n:
  print((-1))
  exit()
a.reverse()
for i in a:
  print(i)

# Optimized solution
n=int(eval(input()))
a=[]
b=list(map(int,input().split()))
for i in range(n):
  for j in range(n)[n-i-1::-1]:
    if b[j]==j+1:
      a.append(b.pop(j))
      break
if len(a)<n:
  print((-1))
  exit()
a.reverse()
for i in a:
  print(i)
# Original solution
def main():
    n = int(eval(input()))
    b = list(map(int, input().split()))
    f = True
    ans = []
    while len(b) > 0:
        sf = True
        for i in reversed(list(range(len(b)))):
            if b[i] == i+1:
                b.pop(i)
                ans.append(i+1)
                sf = False
                break
        if sf:
            f = False
            break
    if f:
        for v in reversed(ans):
            print(v)
    else:
        print("-1")

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    b = list(map(int, input().split()))
    ans = []
    f = True
    for i in reversed(list(range(n))):
        F = True
        for j in reversed(list(range(i+1))):
            if b[j] == j+1:
                ans.append(b.pop(j))
                F = False
                break
        if F:
            f = False
            break
    if f:
        for v in reversed(ans):
            print(v)
    else:
        print((-1))

if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
b = list(map(int, input().split()))
a = [1, 2, 3, 4, 5]

def f(a, ans):
    if len(a) == 0:
        for i in range(len(ans)):
            print((ans[len(ans) - i - 1]))
        exit()
    for i in range(len(a)):
        if i + 1 == a[i]:
            f(a[0:i] + a[i + 1:len(a)], ans + [i + 1])

f(b, [])
print((-1))



# Optimized solution
N = int(eval(input()))
b = list(map(int, input().split()))
a = [1, 2, 3, 4, 5]

def f(a, ans):
    if len(a) == 0:
        for i in range(len(ans)):
            print((ans[len(ans) - i - 1]))
        exit()
    for i in range(len(a) - 1, -1, -1):
        if i + 1 == a[i]:
            f(a[0:i] + a[i + 1:len(a)], ans + [i + 1])
            break


f(b, [])
print((-1))
# Original solution
def main():
    n, *b = list(map(int, open(0).read().split()))

    m = []
    for k in range(1, n+1):
        for i in range(n - k, -1, -1):
            if b[i] == i + 1:
                b.pop(i)
                m.append(i+1)
                break

    if len(b) > 0:
        print((-1))
    else:
        print(('\n'.join(map(str, m[::-1]))))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    n, *b = list(map(int, open(0).read().split()))

    m = []
    for k in range(1, n + 1):
        for i in range(n - k, -1, -1):
            if b[i] == i + 1:
                b.pop(i)
                m.append(i + 1)
                break
        else:
            print((-1))
            exit()

    print(('\n'.join(map(str, m[::-1]))))


if __name__ == '__main__':
    main()
# Original solution
def BFS(Bs,del_idx,result):
    if Bs==[1]:
        return result
    
    if del_idx!=None:
        del Bs[del_idx]

    for i,b in enumerate(Bs):
        if i+1==b:
            DBs=Bs.copy()
            result.append(i+1)
            out=BFS(DBs,i,result)
            if out:
                return out
            else:
                del result[-1]

    return None


def Solve():
    output=[]
    N=int(eval(input()))
    Bs=[int(x) for x in input().split()]
    return BFS(Bs,None,[])
        

        
result=Solve()
if result:
    result.reverse()
    for r in result:
        print(r)
else:
    print((-1))


# Optimized solution
def BFS(Bs,del_idx,result):
    if Bs==[1]:
        return result
    
    if del_idx!=None:
        del Bs[del_idx]


    for i,b in enumerate(Bs):
        if b>i+1:
            return None
        
    for i,b in enumerate(Bs):
        if i+1==b:
            DBs=Bs.copy()
            result.append(i+1)
            out=BFS(DBs,i,result)
            if out:
                return out
            else:
                del result[-1]

    return None


def Solve():
    output=[]
    N=int(eval(input()))
    Bs=[int(x) for x in input().split()]
    return BFS(Bs,None,[])
        

        
result=Solve()
if result:
    result.reverse()
    for r in result:
        print(r)
else:
    print((-1))
# Original solution
def main():
    N = int(eval(input()))
    B = list(map(int, input().split()))
    
    Bs = [B]
    Rs = [[]]
    for i in range(N):
        Bs_new = []
        Rs_new = []
        for b,r in zip(Bs,Rs):
            for j in range(N-i):
                if (b[j] == j+1):
                    tmp = list(b)
                    tmp2 = list(r)
                    tmp2.insert(0,tmp.pop(j))
                    Bs_new.append(tmp)
                    Rs_new.append(tmp2)
        Bs = Bs_new
        Rs = Rs_new
    
    if (0 < len(Rs)):
        R = Rs[0]
        print(("\n".join([str(i) for i in R])))
    else:
        print((-1))
main()


# Optimized solution
def check(b, n):
    if (1 == n):
        if (1 == b[0]):
            return [1]
        else:
            return []
    else:
        for (i,b_) in enumerate(b):
            if ((i+1) == b_):
                tmp = list(b)
                del tmp[i]
                res = check(tmp, n-1)
                #print(res, n-1)
                if (0 < len(res)):
                    #print(res, b_)
                    res.append(b_)
                    return res
        return []

def main():
    N = int(eval(input()))
    B = list(map(int, input().split()))
    
    res = check(B, N)
    if (0 < len(res)):
        print(("\n".join([str(i) for i in res])))
    else:
        print((-1))

main()