Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

S = input()
Q = int(input())
T = [input() for i in range(Q)]

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        S = "".join([t[4], S])
      else:
        S = "".join([S, t[4]])
    else:
      if(count):
        S = "".join([S, t[4]])
      else:
        S = "".join([t[4], S])

if(count):
  print(S)
else:
  print(S[::-1])


### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
for i in range(q):
    for j in range(n):
        if T[i] == S[j]:
            count += 1
            break
print count

### FIXED CODE ###

# -*- coding: utf-8 -*-

def sort(a, left, right):
    if left < right:
        mid = (left+right)/2
        pivot = a[mid]
        a[mid] = a[left]
        p = left
        for i in range(left+1, right+1):
            if a[i] < pivot:
                p = p+1
                p, i = i, p
        a[left] = a[p]
        a[p] = pivot
        sort(a, left, p-1)
        sort(a, p+1, right)

def search(a, target):
    lo = 0
    hi = n-1
    while lo <= hi:
        mid = (lo+hi)/2
        if target <= a[mid]:
            hi = mid-1
        if target >= a[mid]:
            lo = mid+1
    if lo == hi+2:
        return True
    else:
        return False

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
sort(S, 0, n-1)
for i in range(q):
    if search(S, T[i]):
        count += 1
print count
### BUGGY CODE ###

import copy

h, w = map(int, input().split())

grid = [[False] * (w + 2)]
for _ in range(h):
    grid.append([False] + [x == '#' for x in input()] + [False])
grid.append([False] * (w + 2))

cnt = 0
while True:
    flag = True
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            # print('#' if grid[i][j] else '.', end='')
            if grid[i][j] is False:
                flag = False
        # print()
    if flag:
        break

    new_grid = copy.deepcopy(grid)
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] is True:
                new_grid[i][j + 1] = True
                new_grid[i][j - 1] = True
                new_grid[i + 1][j] = True
                new_grid[i - 1][j] = True
    grid = new_grid
    cnt += 1

print(cnt)


### FIXED CODE ###

h, w = map(int, input().split())

grid = [[True] * (w + 2)]
for _ in range(h):
    grid.append([True] + [x == '#' for x in input()] + [True])
grid.append([True] * (w + 2))

q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if grid[i][j] is True:
            q.append((i, j))

cnt = 0
while q:
    qq = []
    for i, j in q:
        if not grid[i + 1][j]:
            grid[i + 1][j] = True
            qq.append((i + 1, j))
        if not grid[i - 1][j]:
            grid[i - 1][j] = True
            qq.append((i - 1, j))
        if not grid[i][j + 1]:
            grid[i][j + 1] = True
            qq.append((i, j + 1))
        if not grid[i][j - 1]:
            grid[i][j - 1] = True
            qq.append((i, j - 1))

    cnt += 1
    q = qq

print(cnt - 1)
### BUGGY CODE ###

def main():
    n = int(input())
    al = list(map(int, input().split()))

    base_2_cnt = [0]*60 
    for a in al:
        for i in range(60):
            if ((a >> i) & 1): base_2_cnt[i] += 1

    ans = 0
    for i in range(60):
        base_01_comb = base_2_cnt[i] * (n-base_2_cnt[i])
        ans += base_01_comb * (2**i)
        ans %= 10**9+7

    print(ans%(10**9+7))

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    MOD = 10**9+7
    n = int(input())
    al = list(map(int, input().split()))

    base_2_cnt = [0]*60 
    for a in al:
        for i in range(60):
            if ((a >> i) & 1): base_2_cnt[i] += 1

    ans = 0
    curr_2 = 1
    for i in range(60):
        base_01_comb = base_2_cnt[i] * (n-base_2_cnt[i])
        ans += base_01_comb * curr_2
        ans %= MOD
        curr_2*=2
        curr_2%=MOD

    print(ans%MOD)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
lst = list(map(int, input().split()))
ans = 0
a,b = 0,0
lst2=[0]

for i in range(n):
    lst2.append(lst2[-1]+lst[i])

temp = set()

for i in range(n):
    l = lst2.count(i)
    if l > 1 and i not in temp:
        temp.add(i)
        ans += l*(l-1)//2
print(ans)


"""
6
1 3 -4 2 2 -2


7
1 -1 1 -1 1 -1 1

5
1 -2 3 -4 5


0 0 0 0 0
"""

### FIXED CODE ###

n = int(input())
lst = list(map(int, input().split()))
ans = 0
a,b = 0,0
lst2=[0]
d = {0:1}
for i in range(n):
    s = lst2[-1]+lst[i]
    lst2.append(s)
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1

temp = set()

for i in d:
    l = d[i]
    if l > 1 and i not in temp:
        temp.add(i)
        ans += l*(l-1)//2
print(ans)


"""
6
1 3 -4 2 2 -2


7
1 -1 1 -1 1 -1 1

5
1 -2 3 -4 5


0 0 0 0 0
"""
### BUGGY CODE ###

N = int(input())
c = input()
ans = [-1] * (N+1)

for i in range(0, N+1):
  l = c[:i]
  r = c[i:]
  R = l.count("W")
  W = r.count("R")
  ans[i] = max(R, W)

print(min(ans))

### FIXED CODE ###

N = int(input())
c = input()
ans = [-1] * (N+1)

for i in range(0, N+1):
  if i == 0:
    l = c[:i]
    r = c[i:]
    W = l.count("W")
    R = r.count("R")
  else:
    if (c[i-1]) == "W":
      W += 1
    elif (c[i-1]) == "R":
      R -= 1

  ans[i] = max(R, W)
      
print(min(ans))
### BUGGY CODE ###

n = int(input())
aaa = map(int, input().split())
ans = 1
for a in aaa:
    ans *= a
print(int(ans) if ans <= 10 ** 18 else -1)

### FIXED CODE ###

import sys
read = sys.stdin.readline
n = int(input())
aaa = list(map(int, read().split()))
aaa.sort()
ans = 1
for a in aaa:
    ans *= a
    if ans == 0:
        break
    if ans > 10 ** 18:
        ans = -1
        break
print(int(ans))
### BUGGY CODE ###

from fractions import gcd

def lcm(c,d):
    return c//gcd(c,d)*d
mod=10**9+7
n=int(input())
a=[int(i) for i in input().split()]
l=a[0]
for i in range(1,n):
    l=lcm(l,a[i])
ans=0
for i in range(n):
    ans+=l//a[i]
    ans%=mod
print(ans)


### FIXED CODE ###

from fractions import gcd

def lcm(c,d):
    return c//gcd(c,d)*d
mod=10**9+7
n=int(input())
a=[int(i) for i in input().split()]
l=a[0]
for i in range(1,n):
    l=lcm(l,a[i])
ans=0
for i in range(n):
    ans+=l//a[i]
    #ans%=mod
print(ans%mod)
### BUGGY CODE ###

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components


class People:
    def __init__(self):
        self.frends = 0
        self.blocks = 0


n, m, k = [int(i) for i in input().split()]

data=[1]*(2*m)
row=[]
col=[]
peoples = [People() for i in range(n + 1)]
for i in range(m):
    one, two = [int(j) for j in input().split()]
    row.append(one)
    row.append(two)
    col.append(two)
    col.append(one)
    peoples[one].frends+=1
    peoples[two].frends+=1

frends = csr_matrix((data, (row, col)), shape=(n+1, n+1))


num, labels = connected_components(frends)
labels=list(labels)

for i in range(k):
    one, two = [int(j) for j in input().split()]
    if labels[one] == labels[two]:
        peoples[one].blocks+=1
        peoples[two].blocks+=1

renketu_num = [0]
for i in range(1, num + 1):
    renketu_num.append(labels.count(i))


def get_renketu_num(i):
    return renketu_num[labels[i]] - 1


def get_friend_num(i):
    return peoples[i].frends


def get_block_num(i):
    return peoples[i].blocks


for i in range(1, n + 1):
    print(get_renketu_num(i) - get_friend_num(i) - get_block_num(i))

### FIXED CODE ###

import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

import sys
sys.setrecursionlimit(10**9)
n,m,k=[int(i) for i in input().split()]
frends_num=[0 for i in range(n)]
def make_frends(m,n):
    data=[1 for i in range(m)]

    row=[]
    col=[]
    for k in range(m):
        i,j=[int(l) for l in input().split()]
        new_i=min(i,j)-1
        new_j=max(i,j)-1
        row.append(new_i)
        col.append(new_j)
        frends_num[new_i]+=1
        frends_num[new_j]+=1
    frend_sparce_matrix=csr_matrix((data, (row, col)),shape=(n,n))
    return frend_sparce_matrix


frends=make_frends(m,n)
l,labels=connected_components(frends)
labels
labels=list(labels)

class Group:
    def __init__(self,labels):
        self.labels=labels
        self.group_num=[0 for i in range(l)]
        for i in labels:
            self.group_num[i]+=1
    def get_group_num(self,i):
        return self.group_num[self.labels[i]]

group=Group(labels)


def get_frend_num(i):
    return frends_num[i]


def make_block(k,n):
    block_num=[0 for i in range(n)]
    for p in range(k):
        i,j =[int(l)-1 for l in input().split()]
        new_i=min(i,j)
        new_j=max(i,j)
        if labels[new_i]==labels[new_j]:
            block_num[i]+=1
            block_num[j]+=1
    return block_num

block=make_block(k,n)

def get_block_num(i):
    return block[i]

ans=[]
for i in range(n):
    ans.append(str(group.get_group_num(i)-1-get_frend_num(i)-get_block_num(i)))
print(" ".join(ans))
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
Pe = [(i+1)/2 for i in P]

maxsum = -1
for i in range(0, N-K+1):
    tmp = sum(Pe[i:i+K])
    if tmp > maxsum:
        maxsum = tmp

print(maxsum)

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
Pe = [(i+1)/2 for i in P]

maxsum = -1
cur = sum(Pe[0:K])
maxsum = cur
for i in range(1, N-K+1):
    cur = cur - Pe[i-1] + Pe[i+K-1]
    if cur > maxsum:
        maxsum = cur

print(maxsum)
### BUGGY CODE ###

X = list(input())

q_num = X.count("?")
a_num = 0
c_num = X.count("C")
left_q_num = 0
right_q_num = q_num
ans = 0
len_x = len(X)
q_dict = []
for i in range(q_num + 1):
    q_dict.append(3 ** i % (10 ** 9 + 7))

if X[0] == "?":
    right_q_num -= 1
elif X[0] == "C":
    c_num -= 1
for i, x in enumerate(X):
    if x == "B" or x == "?":
        ans += (a_num * c_num)  * (q_dict[(left_q_num + right_q_num)])
        if left_q_num + right_q_num >= 2:
            ans += (right_q_num * left_q_num  + 3*(left_q_num * c_num) + 3*(right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 2)])
        elif left_q_num + right_q_num == 1:
            ans += ((left_q_num * c_num) + (right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 1)])
        ans = ans % (10 ** 9 + 7)
    if  i == len_x - 1:
        break
    if x == "A":
        a_num += 1
    elif x == "?":
        left_q_num += 1
    if X[i + 1] == "C":
        c_num -= 1
    elif X[i + 1] == "?":
        right_q_num -= 1

print(ans % (10 ** 9 + 7))



### FIXED CODE ###

X = list(input())

q_num = X.count("?")
a_num = 0
c_num = X.count("C")
left_q_num = 0
right_q_num = q_num
ans = 0
len_x = len(X)
q_dict = []
b_ans = 0
q_ans = 0
q_dict = {}
q_dict[q_num - 1] = (3 ** (q_num - 1)) % (10 ** 9 + 7)
q_dict[q_num - 2] = (3 ** (q_num - 2)) % (10 ** 9 + 7)
q_dict[q_num - 3] = (3 ** (q_num - 3)) % (10 ** 9 + 7)
q_dict[q_num] = (3 ** (q_num)) % (10 ** 9 + 7)

if X[0] == "?":
    right_q_num -= 1
elif X[0] == "C":
    c_num -= 1
for i, x in enumerate(X):
    if x == "B" or x == "?":
        ans += (a_num * c_num)  * (q_dict[(left_q_num + right_q_num)])
        if left_q_num + right_q_num >= 2:
            ans += (right_q_num * left_q_num  + 3*(left_q_num * c_num) + 3*(right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 2)])
        elif left_q_num + right_q_num == 1:
            ans += ((left_q_num * c_num) + (right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 1)])
        ans = ans % (10 ** 9 + 7)
    if  i == len_x - 1:
        break
    if x == "A":
        a_num += 1
    elif x == "?":
        left_q_num += 1
    if X[i + 1] == "C":
        c_num -= 1
    elif X[i + 1] == "?":
        right_q_num -= 1

print(ans % (10 ** 9 + 7))
### BUGGY CODE ###

from operator import itemgetter
from functools import reduce
import fractions as f
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
    ans = max(ans, reduce(f.gcd, a[:i] + a[i+1:]))

print(ans)


### FIXED CODE ###

from operator import itemgetter
from functools import reduce
import fractions as f
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
rev_a = list(reversed(a))
ans = 0
accumulation_gcd = [0] * n
rev_accumulation_gcd = [0] * n
accumulation_gcd[0] = a[0]
rev_accumulation_gcd[0] = rev_a[0]

for i in range(1, n):
    accumulation_gcd[i] = f.gcd(a[i], accumulation_gcd[i-1])
    rev_accumulation_gcd[i] = f.gcd(rev_a[i], rev_accumulation_gcd[i-1])

rev_accumulation_gcd.reverse()


for i in range(n):
    if i == 0:
        ans = max(ans, rev_accumulation_gcd[1])
    elif i == (n - 1):
        ans = max(ans, accumulation_gcd[n-2])
    else:
        ans = max(ans, f.gcd(accumulation_gcd[i-1], rev_accumulation_gcd[i+1]))

print(ans)
### BUGGY CODE ###

S = input()
ansl = [0]*2019
for i in range(len(S)):
    ansl[int(S[-i-1:])%2019]+=1
ans = (ansl[0]+1)*ansl[0]/2
for i in range(1, 2019):
    ans+=ansl[i]*(ansl[i]-1)/2

print(int(ans))

### FIXED CODE ###

def power_func(a, b, p):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, p)
        return d * d % p
    if b % 2 == 1:
        return (a * power_func(a, b - 1, p)) % p

S = input()
ansl = [0]*2019
temp = 0
for i in range(len(S)):
    temp = (temp+int(S[-i-1])*power_func(10,i,2019))%2019
    ansl[temp]+=1
ans = (ansl[0]+1)*ansl[0]/2

for i in range(1, 2019):
    ans+=ansl[i]*(ansl[i]-1)/2

print(int(ans))
### BUGGY CODE ###

# coding: utf-8
N = int(input())

res = sum(range(N))

print(res)

### FIXED CODE ###

N = int(input())

print(N*(N-1) // 2)
### BUGGY CODE ###



S = input()
mod = [0] * 2019
mod[0] = 1
d = 1
n = 0
for i in reversed(S):
  n += int(i) * d
  mod[n % 2019] += 1
  d *= 10
ans = 0
for j in range(2019):
  ans += mod[j] * (mod[j] - 1) // 2
print(ans)

### FIXED CODE ###

S = input()
mod = [0] * 2019
mod[0] = 1 
d = 1
n = 0
for i in reversed(S):
  n += int(i) * d
  n %= 2019
  d *= 10
  d %= 2019
  mod[n % 2019] += 1
ans = 0
for j in range(2019):
  ans += mod[j] * (mod[j] - 1) // 2
print(ans)
### BUGGY CODE ###

n=int(input())
l=[list(str(input())) for i in range(n)]
for k in l:
  k.sort()
  k="".join(k)
nums=[x for x in range(n-1)]
cnt=0
for i in nums:
  for j in l[i+1:]:
    if(l[i]==j):
      cnt+=1
print(cnt)

### FIXED CODE ###

from collections import Counter
n=int(input())
l=["".join(sorted(list(str(input())))) for i in range(n)]
cnt=Counter(l)
ans=0
for i in set(l):
  n=cnt[i]
  ans+=n*(n-1)//2
print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())

    for _ in range(q):
        b, c = map(int, input().split())
        a = [c if i == b else i for i in a]
        print(sum(a))


if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import defaultdict

N, Q = list(map(int, input().split()))
s = input()
dic = defaultdict(list)
for i, c in enumerate(s):
    dic[c].append(i)
golem = [1] * N
for _ in range(Q):
    t, d = input().split()
    if d == 'L':
        for i in dic[t]:
            if i > 0:
                golem[i-1] += golem[i]
                golem[i] = 0
            else:
                golem[i] = 0
    else:
        for i in dic[t]:
            if i < N-1:
                golem[i+1] += golem[i]
                golem[i] = 0
            else:
                golem[i] = 0
print(sum(golem))


### FIXED CODE ###

def can_reach_to_0(s, comm, pos):
    for t, d in comm:
        if s[pos] == t:
            if d == 'L':
                pos -= 1
            else:
                pos += 1
        if pos < 0:
            return True
        if pos >= N:
            return False
    return False

def can_reach_to_N(s, comm, pos):
    N = len(s)
    for t, d in comm:
        if s[pos] == t:
            if d == 'L':
                pos -= 1
            else:
                pos += 1
        if pos >= N:
            return True
        if pos < 0:
            return False
    return False

N, Q = list(map(int, input().split()))
s = input()
comm = [input().split() for _ in range(Q)]

l = 0
r = N-1
while l <= r:
    mid = int((l+r)/2)
    if can_reach_to_0(s, comm, mid):
        l = mid + 1
    else:
        r = mid - 1
left = r # いける右端index

l = 0
r = N-1
while l <= r:
    mid = int((l+r)/2)
    if can_reach_to_N(s, comm, mid):
        r = mid - 1
    else:
        l = mid + 1
right = l # いける左端index
print(right-left-1)
### BUGGY CODE ###

import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, readline().split())

dists = [[[0, 0] for j in range(W)] for i in range(H)]

tile = [0 for i in range(H)]

for i in range(H):
    tile[i] = readline().decode().strip()

for i in range(H):
    for j in range(W):
        c = tile[i][j]
        if c == '#':
            continue
        
        d = dists[i][j]
        if d[0] == 0:
            # search horizontally
            x = j
            count = 0
            while x < W and tile[i][x] != '#':
                x += 1
                count += 1
            for a in range(j, x):
                dists[i][a][0] = count
        if d[1] == 0:
            # search vertically
            y = i
            count = 0
            while y < H and tile[y][j] != '#':
                y += 1
                count += 1
            for b in range(i, y):
                dists[b][j][1] = count

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(dists[i][j][0] + dists[i][j][1] - 1, ans)
print(ans)



### FIXED CODE ###

import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, readline().split())

tile = [0 for i in range(H)]
cnt = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    tile[i] = readline().decode().strip()

for i in range(H):
    done = [False for _ in range(W)]
    for j in range(W):
        if tile[i][j] == '#':
            continue
        if done[j]:
            continue
        l = 0
        while (j + l < W):
            if tile[i][j + l] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i][j + k] += l
            done[j + k] = True

for j in range(W):
    done = [False for _ in range(H)]
    for i in range(H):
        if tile[i][j] == '#':
            continue
        if done[i]:
            continue
        l = 0
        while (i + l < H):
            if tile[i + l][j] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i + k][j] += l
            done[i + k] = True

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(cnt[i][j] - 1, ans)
print(ans)
### BUGGY CODE ###

from collections import Counter
H, W, M = map(int, input().split())

h = [0] * M
w = [0] * M
for i in range(M):
    h[i], w[i] = map(int, input().split())


S = Counter(h)
T = Counter(w)

if (S.most_common()[0][1] > T.most_common()[0][1]):
    for i in range(M):
        if (h[i] == S.most_common()[0][0]):
            w[i] = 'boom'

    w1 = [s for s in w if s != 'boom']
    T = Counter(w1)
    for i in range(len(w1)):
        if (w1[i] == T.most_common()[0][0]):
            w1[i] = 'boom' 

    w2 = [s for s in w1 if s != 'boom']
    print(M-len(w2))

else:
    for i in range(M):
        if (w[i] == T.most_common()[0][0]):
            h[i] = 'boom'

    h1 = [s for s in h if s != 'boom']
    S = Counter(h1)
    for i in range(len(h1)):
        if (h1[i] == S.most_common()[0][0]):
            h1[i] = 'boom' 

    h2 = [s for s in h1 if s != 'boom']
    print(M-len(h2))

### FIXED CODE ###

from collections import Counter
import sys
H, W, M = map(int, input().split())

h = [0] * M
w = [0] * M
for i in range(M):
    h[i], w[i] = map(int, input().split())


S = Counter(h)
T = Counter(w)

if (M == 1):
    print(1)

else:
    if (S.most_common()[0][1] > T.most_common()[0][1]):
        smc = S.most_common()[0][0]
        for i in range(M):
            if (h[i] == smc):
                w[i] = 'boom'

        w1 = [s for s in w if s != 'boom']
        T = Counter(w1)
        if (len(w1) == 0):
            print(M)
            sys.exit()
        tmc = T.most_common()[0][0]
        for i in range(len(w1)):
            if (w1[i] == tmc):
                w1[i] = 'boom' 

        w2 = [s for s in w1 if s != 'boom']
        print(M-len(w2))

    else:
        tmc = T.most_common()[0][0]
        for i in range(M):
            if (w[i] == tmc):
                h[i] = 'boom'

        h1 = [s for s in h if s != 'boom']
        S = Counter(h1)
        if (len(h1) == 0):
            print(M)
            sys.exit()
        smc = S.most_common()[0][0]
        for i in range(len(h1)):
            if (h1[i] == smc):
                h1[i] = 'boom' 

        h2 = [s for s in h1 if s != 'boom']
        print(M-len(h2))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5)

def dfs(N, B, A, seq, nums):
  if len(A) == N:
    ok = True
    for a, b in zip(A, B):
      if a != b:
        ok = False
        break
    return seq if ok else None
  else:
    for n in nums.keys():
      if nums[n] > 0:
        tmpA = A.copy()
        tmpSeq = seq.copy()
        tmpNums = nums.copy()
        tmpA.insert(n-1,n)
        tmpSeq.append(n)
        tmpNums[n] -= 1
        ans = dfs(N, B, tmpA, tmpSeq, tmpNums)
        if ans:
          return ans

N = int(input())
B = list(map(int, input().split()))
ok = True
nums = {b:0 for b in B}
for i, b in enumerate(B):
  if i+1<b:
    ok = False
    break
  nums[b] += 1
if ok:
  for n in dfs(N,B,[],[],nums):
    print(n)
else:
  print(-1)



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

N = int(input())
B = list(map(int, input().split()))
ans = []
while len(B) > 0:
  ok = False
  for i in reversed(range(len(B))):
    if B[i] == i+1:
      ok = True
      ans.append(B.pop(i))
      break
  if not ok:
    break
if len(B) > 0:
  print(-1)
else:
  for a in reversed(ans):
    print(a)