Problem:


Score : 400 points

Problem Statement

Snuke has an empty sequence a.

He will perform N operations on this sequence.

In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).

You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq b_i \leq N

Input

Input is given from Standard Input in the following format:

N
b_1 \dots b_N

Output

If there is no sequence of N operations after which a would be equal to b, print -1.
If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.

Sample Input 1

3
1 2 1

Sample Output 1

1
1
2

In this sequence of operations, the sequence a changes as follows:

After the first operation: (1)

After the second operation: (1,1)

After the third operation: (1,2,1)

Sample Input 2

2
2 2

Sample Output 2

-1

2 cannot be inserted at the beginning of the sequence, so this is impossible.

Sample Input 3

9
1 1 1 2 2 1 2 3 2

Sample Output 3

1
2
2
3
1
2
2
1
1



Sample input:
3
1 2 1


Sample output:
1
1
2

Submission status: Runtime Error

Solution code:
N=int(input())
r=[0]
inp=input().split()
for k in range(N):
  r.append(int(inp[k]))
def rec(x,y,i,N):
    if len(x)==1:
        for k in range(len(y)):
            print(y[k])
        return(y)
    if i==N+1:
        if len(y)==0:
            print(-1)
            return -1
        else:
            m=y[0]
            del y[0]
            x.insert(m,m)
            rec(x,y,m+1,N)     
    if x[i]==i:
        x.pop(i)
        y.insert(0,i)
        rec(x,y,1,N)
        
    else:
        if x[i] < i:
            rec(x,y,i+1,N)
        else:
            if len(y)>0:
                m=y[0]
                del y[0]
                x.insert(m,m)
                rec(x,y,m+1,N)  
            else:
                print(-1)
                return -1
                
                
            
        
            
        
    
rec(r,[],1,3)

Submission status: Runtime Error

Solution code:
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            res.append(j)
            B.pop(j - 1)
            break
    else:
        print(-1)
        exit()1

for r in res[::-1]:
    print(r)

Submission status: Runtime Error

Solution code:
from itertools import groupby

S = list(input())
K = int(input())

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * (K - 1))

Submission status: Runtime Error

Solution code:
from itertools import groupby

S = list(input())
K = int(input())

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * K - 1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
def order(a):
    if a == [1]:
        return [1]
    else:
        x = order(a[:-1])
        y = a[-1]
        x.insert(y-1,y)
        return x
print(*order(a),sep="\n")

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline
N, M = map(int, readline().split())

def check(Edge, Dim):
    N = len(Edge)
    if any(d&1 for d in Dim):
        return 'No'
    if max(Dim) > 4:
        return 'Yes'
    dc4 = Dim.count(4)
    if dc4 <= 1:
        return 'No'
    if dc4 >= 3:
        return 'Yes'
    a = Dim.index(4)
    st = (a+1)%N
    used = set([a, st])
    stack = [st]
    while stack:
        vn = stack.pop()
        for vf in Edge[vn]:
            if vf not in used:
                stack.append(vf)
                used.add(vf)
    if len(used) == N:
        return 'No'
    return 'Yes'
Edge = [[] for _ in range(N)]
Dim = [0]*N

for _ in range(M):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    Edge[a].append(b)
    Edge[b].append(a)
    Dim[a] += 1
    Dim[b] += 1

print(check(Edge, Dim))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  int N;
  cin >> N;
  vector<int> b(N);
  REP(i, N){
    cin >> b[i];
    b[i]--;
  }
  vector<int> ans;
  REP(i, N){
    REPR(j, b.size()-1){
      if(b[j] == j){
        ans.push_back(j+1);
        b.erase(b.begin()+j, b.begin()+j+1);
        break;
      }
    }
    if(b.size() != N-i-1){
      // cout << "i" << i << " b.size(): " << int(b.size()) << endl;
      cout << "-1" << endl;
      return 0;
    }
  }
  REPR(i, N-1){
    cout << ans[i] << endl;
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    for j in range(0,i):
      if b[j] == j+1:
        key = j+1
      elif j == i and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()



ans = []

for i in range(n):
    for j in range(b):
        if b[j] == j+1:
            ans.append(b[j])
            del b[j]
            continue
        print(-1)
        exit()

print(' '.join(reversed(ans)))

Submission status: Runtime Error

Solution code:
n = int(input())
if n % 2:
    print(((n - 1) * (n - 2) + (n - 1)) // 2)
else:
    print(n * (n - 2) // 2)
for i in range(n):
    for j in range(i + 1, n):
        if i + j != n - 2:
            print(i + 1, j + 1)
if n % 2:
    exit(1)

Submission status: Runtime Error

Solution code:
N = int(input())
b = list(map(int, input().split()))

#成り立たせることができるかどうか
for i in range(1, N + 1):
    if b[i - 1] > i:
        print (-1)
        exit()


check_lst = [False] * N #i番目の数を使ったかどうか

ans_lst = [] #答えの逆順
for i in range(N - 1, -1, -1):
    if check_lst[i]: #True --> 既に使ったとき
        continue #次のiから続ける
    count = b[i] - 1
    index = i - 1
    # print ('count', count)
    # print ('index', index)
    while count > 0:
        if b[index] < b[i] and b[index] <= len(ans_lst) + 1: #次に入れたいやつより小さくて、iより大きいもの
            count -= 1
            # print ('B')
            if check_lst[index] == False:
                check_lst[index] = True
                # print (b[index])
                ans_lst.append(b[index])
        index -= 1
    ans_lst.append(b[i])
    check_lst[i] = True

for i in ans_lst:
    print (i)

Submission status: Runtime Error

Solution code:
n=int(input())
b=list(map(int,input().split()))
l=len(b)
a=[]
f=0
for _ in range(n):
  for i in range(l-1,-1,-1):
    if b[i]==i+1:
      a.append(b.pop(i))
      break
    if i==0:
      f=1
if f==0:
  for i in range(l-1,-1,-1):
    print(a[i])
else:
  print(-1)

Submission status: Runtime Error

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
flag = True
for i in range(n):
    if b[i] > i+1:
        flag = False
        break

if not flag:
    print(-1)
else:
    ans = []
    while len(b) > 0:
        for m in range(max(b), 0, -1):
            if b[m-1] == m:
                ans.append(b[m-1])
                del b[m-1]
                break
ans = ans[::-1]
print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from collections import deque

n=int(input())
b=[int(i) for i in input().split()]

#print(n,b)

ans=deque([])

for j in range(n):
    tmp=110
    for i in range(len(b)-1,-1,-1):
        if len(b)==1:
            break
        else:
            if i+1==b[i]:
                val=b.pop(b[i])
                ans.append(val)
                
ans.append(b[0])

if ans.count(110) > 0:
    print(-1)
else:
    for i in range(n):
        print(ans[i])

Submission status: Runtime Error

Solution code:
sequence_size = int(input())
sequence = list(map(int, input().split()))
error = False
error_msg = -1
sequence.sort()
if max(sequence) > sequence_size:
    print(error_msg)
else:
    for index in range(0,sequence_size - 1):
        if sequence[index] <= index + 1:
            error is False
        else:
            error is True
            break
if error is False:
    for num in sequence:
        print(sequence[num])
else:
    print(error_msg)

Submission status: Runtime Error

Solution code:
import sys
from math import factorial
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]
m = {}

def dfs(counter, now_list, remain):
    k = "".join(map(str, now_list))
    if m.get(k) != None and m[k] == [-1]:
        return m[k]

    if len(remain) == 0:
        if now_list == L:
            return []
    else:
        remain_local = [v for v in remain if v <= counter]
        if len(remain_local) == 0:
            return [-1]

        for v in remain_local:
            p = now_list.copy()
            p.insert(v - 1, v)

            r = remain.copy()
            r.remove(v)

            k = "".join(map(str, p))
            if m.get(k) != None and m[k] == [-1]:
                continue

            h = dfs(counter + 1, p, r)
            m[k] = h
            if h != [-1]:
                return h + [v]
    
    return [-1]

ans = dfs(1, [], L.copy())
if ans == [-1]:
    print(-1)
else:
    ans = reversed(ans)
    [print(v) for v in ans]

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
ops = []
while len(a):
  if not any(a[i] == i + 1 for i in range(len(a))):
    print(-1)
    exit()
  for i in range(reversed(len(a))):
    if a[i] == i + 1:
      ops.append(a[i])
      a.pop(i)
      break

for op in reversed(ops):
  print(op)

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())

ops = []
while len(a):
  if not any(a[i] == i + 1 for i in range(len(a))):
    print(-1)
    exit()
  for i in range(reversed(len(a))):
    if a[i] == i + 1:
      ops.append(a[i])
      a.pop(i)
      break

for op in reversed(ops):
  print(op)

Submission status: Runtime Error

Solution code:
n = int(input())
b  = map(int,input().split())
z = []
for i in range(n):
  if b[n] > i:
    z = [-1]
    break
  else:
    z += b[n]
for m in z:
  print(m)

Submission status: Runtime Error

Solution code:
N = int(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])
        exir()
    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)

Submission status: Runtime Error

Solution code:
n = int(input())
b = list(map(int, input().split()))
b.reverse()
ans_set = [0]*n

for i in range(n):
    if ans == -1:
        break
    
    for j in range(n):
        if b[j] == n-j:
            ans = b.pop(j)
            ans_set[n-1] = ans
            n -= 1
            break
            
        elif b[j] > n-j:
            ans = -1
            print(ans)
            break

        if n == 0:
            break

if ans != -1:
    for k in ans_set:
        print(k)

Submission status: Runtime Error

Solution code:
n = int(input())
b = [int(x) for x in input().split]
b.reverse()
b_counts = len(b)

for i in range(n):
    for j in range(n):
        
        if b[j] == b_counts-b.index()+1:
            ans = b.pop(j)
            b_counts -= 1
            print(ans)
        elif b[j] > b_counb_counts-b.index()+1:
            ans = -1
            break
        
        if b_counts == 0:
            break
print(ans)

Submission status: Runtime Error

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    # b = list(map(int, input().split()))
    b = [int(i) for i in input().split()] 
  else:
    # b = [1,2,1]
    # b = [2,2]
    # b = [1,1,1,2,2,1,2,3,2]
    b = [1,1,1,1,2,3,4,5,6,1] 
    N = len(b)
  
  if check(b,N) != True:
    print(-1)
    
def check(B,lenB):
  # if 'get_ipython' in globals(): print(B)
  if lenB == 0 :
    return True
  #for i in reversed(range(lenB)):
  for i in range(lenB-1,-1,-1):
    if B[i] == i+1:
      ans = B[i]
      del B[i]
      if check(B,lenB -1) == True:
        print(ans)
        return True
        break  
  return False

main()

Submission status: Runtime Error

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    # b = list(map(int, input().split()))
    b = [int(i) for i in input().split()] 
  else:
    # b = [1,2,1]
    # b = [2,2]
    b = [1,1,1,2,2,1,2,3,2]
    N = len(b)
  
  if check(b,N) != True:
    print(-1)
    
def check(B,lenB):
  # if 'get_ipython' in globals(): print(B)
  if lenB == 0 :
    return True
  #for i in reversed(range(lenB)):
  for i in range(lenB-1,-1,-1):
    if B[i] == i+1:
      ans = B[i]
      del B[i]
      if check(B,lenB -1 ) == True:
        print(ans)
        return True
        break
  return False  

main()

Submission status: Runtime Error

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    # b = list(map(int, input().split()))
    b = [int(i) for i in input().split()] 
  else:
    # b = [1,2,1]
    # b = [2,2]
    b = [1,1,1,2,2,1,2,3,2]
    N = len(b)
    
  if check(b) != True:
    print(-1)
    
def check(B):
  # if 'get_ipython' in globals(): print(B)
  lenB = len(B)
  if lenB == 0 :
    return True
  else :
    maxB = max(B) + 1  
  # for i in reversed(range(lenB)):
  for i in reversed(range(0,maxB)):
    if B[i] == i+1:
      if check(B[:i]+B[(i+1):]) == True:
        print(B[i])
        return True
        break
    
main()

Submission status: Runtime Error

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    # b = list(map(int, input().split()))
    b = [int(i) for i in input().split()] 
  else:
    # b = [1,2,1]
    # b = [2,2]
    b = [1,1,1,2,2,1,2,3,2]
    N = len(b)
    
  if check(b) != True:
    print(-1)
    
def check(B):
  # if 'get_ipython' in globals(): print(B)
  lenB = len(B)
  if lenB == 0 :
    return True
  else :
    maxB = max(B)    
  # for i in reversed(range(lenB)):
  for i in reversed(range(0,maxB)):
    if B[i] == i+1:
      if check(B[:i]+B[(i+1):]) == True:
        print(B[i])
        return True
        break
    
main()

Submission status: Runtime Error

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    # b = list(map(int, input().split()))
    b = [int(i) for i in input().split()] 
  else:
    # b = [1,2,1]
    # b = [2,2]
    b = [1,1,1,2,2,1,2,3,2]
    N = len(b)
    
  if check(b) != True:
    print(-1)
    
def check(B):
  # if 'get_ipython' in globals(): print(B)
  lenB = len(B)
  maxB = max(B)
  if lenB == 0 :
    return True
  # for i in reversed(range(lenB)):
  for i in reversed(range(0,maxB)):
    if B[i] == i+1:
      if check(B[:i]+B[(i+1):]) == True:
        print(B[i])
        return True
        break
    
main()

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;


#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
vector<pair<int, int> > vp;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
ll N, H;
string s;
ll a[110], b[100010];
vector<string> field;
int main(void) {
    int N; cin >> N;
    vector<int> v;
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    vector<int> v2 = v;
    vector<int> ans;
    bool f = true;
    bool update = true;
    while(v2.size()!=0){
        update = false;
        for(int i=v2.size()-1; i>=0; --i){
            for(int j=v2.size(); j>=1; --j){
                if(v2[i] == j && i+1 == j){
                    ans.push_back(v2[i]);
                    v2.erase(v2.begin()+i);
                    update = true;
                    break;
                }
                if(i == 0 && j==1){
                    f = false;
                }
            }
            if(update) break;
        }
        if(!f) break;
    }
    reverse(ans.begin(), ans.end());
    if(f){
        for(auto e: ans) cout << e << endl;
    }else{
        cout << -1 << endl;
    }
	return 0;
}

Submission status: Runtime Error

Solution code:
n = input()
l = list(map(int, input().split()))
ans=[]
for i in range(len(l)):
    for k in range(len(l)):
        if l[i+k] == i+1:
            ans.append(i+1)
            break
if len(l)==len(ans):
    for i in range(len(ans)):
        print(ans[i])
else:
    print(-1)

Submission status: Runtime Error

Solution code:
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for anse in ans[::-1]
        print(anse)

Submission status: Runtime Error

Solution code:
n = int(input())
b = list(map(int, input().split()))

def main():
    b.sort()
    for i in range(n):
        print(b[i])

for i in range(n):
    if b[i] < n-i:
        main()
        break
    elif b[i] == n-i:
        continue
    if i == n - 1 and b[i] <= n
        main()
        break
else:
    print("-1")

Submission status: Runtime Error

Solution code:
N = int(input())
b = list(map(int, input().split()))
ans = []
while 1:
    if len(b) == 0:
        print(reversed(ans))
        exit()
    for idx,val in enumerate(reversed(b)):
        if val == idx + 1:
            ans.append(val)
            b.pop(idx)
            continue
        if idx == 0:
            print('-1')
            exit()

Submission status: Runtime Error

Solution code:
# 実行時の引数の入力：https://qiita.com/orange_u/items/3f0fb6044fd5ee2c3a37

import sys

args = sys.argv

num_len = int(args[1])
a = []
b = []
N = 100
# b = [1,2,1]
for i in range(2, 2+num_len):
    b.append(int(args[i]))
print(b)



# for i in range(len(b)):
for i in range(num_len):
    # try:
    #     # print(i)
    #     a.insert(b[i], b[i])
    #     print(a)
    # except:
    #     print(-1)

    if a == b:
        # print(i)
        a.insert(b[i], b[i])
        print(a)
    else:
        print(-1)

Submission status: Runtime Error

Solution code:
N = int(input())
B = list(map(int,input().split()))
 
ans = []
while B:
    for i in range(len(B)-1, -1, -1):
        b = B[i]
        if i+1 == b:
            ans.append(i+1)
            break
    else:
        print(-1)
        exit()
    del B[i]

ans.reverse()
for an in range(0, N+1):
	tmp = ans.pop(0)
	print(tmp)

Submission status: Runtime Error

Solution code:
N = input()
print(N)
b = list(map(int,input().split()))
print(b)
a = [][]

for i in range(N):
  for j in range(i):
 	if 1 <= j || j <= i:
      a[i][j] = j
      
ans = -1
for i in range(N):
  if a == b :
    ans = a[i][:]
      
return ans

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input().split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 0, -1):
		if arr[idx2-1] == idx2:
			tmp = arr.pop(idx2-1)
			ans.append(tmp)
			break
		elif idx2 == 1:
			print(-1)
			exit()

for idx in range(0, N):
	tmp = ans.pop(-1)
	print(tmp)
  	print("\n")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input().split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 0, -1):
		if arr[idx2-1] == idx2:
			tmp = arr.pop(idx2-1)
            ans.append(tmp)
			break
		elif idx2 == 1:
			print(-1)
			exit()

for idx in range(0, N):
	tmp = ans.pop(-1)
    print(tmp)
  	print("\n")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input().split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 0, -1):
		if arr[idx2-1] == idx2:
			ans.append(arr.pop(idx2-1))
			break
		elif idx2 == 1:
			print(-1)
			exit()

for idx in range(0, N):
	print(ans.pop(-1))
  	print("\n")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input().split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 0, -1):
		if arr[idx2-1] == idx2:
			ans.append(arr.pop(idx2-1))
			break
		elif idx2 == 1:
			print(-1)
            exit()

for idx in range(0, N):
	print(ans.pop(-1))
  	print("\n")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input().split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 1, -1):
		if arr[idx2-1] == idx2:
			ans.append(arr.pop(idx2-1))
			break
		elif idx2 == 1:
			exit(-1)
 
for idx in range(0, N):
	print(ans.pop(-1))
  	print("\n")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input(),split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 0, -1):
		if arr[idx2-1] == idx2:
			ans.append(arr.pop(idx2-1))
			break
		elif idx2 == 1:
			exit(-1)
 
for idx in range(0, N):
	print(ans.pop(-1))
  	print("\n")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input(),split()))
 
ans = []
 
for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 1, -1):
		if arr[idx2-1] == idx2:
			ans.append(arr.pop(idx2-1))
			break
		elif idx2 == 1:
			exit(-1)
 
for idx in range(0, N):
	print(ans.pop(-1))
  	print("\n")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input(),split()))

ans = []

for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 1, -1):
		if arr[idx2-1] == idx2:
			ans.append(arr.pop(idx2-1))
			break
		elif idx2 == 1:
			exit(-1)

for idx in range(0, N)
	print(ans.pop(-1))
  	print("\n")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input(),split()))

ans = []

for idx1 in range(1, N+1):
	for idx2 in range(len(arr), 1, -1):
    	if arr[idx2-1] == idx2:
    		ans.append(arr.pop(idx2-1))
            break
    	elif idx1 == 1:
    		exit(-1)

for idx in range(0, N)
	print(ans.pop(-1))
  	print("\n")

Submission status: Runtime Error

Solution code:
asdfs

Submission status: Runtime Error

Solution code:
import numpy
a = numpy.empty()
 
N = int(input())
b = int(input().split()) 


for i in N:
	j=min(b)
	if i>=j : 
		a.insert(j,j)
		j.remove(j)

if a=b
	for i in j.length :
		print("{}\n".format(j[i])

if a!=b
	print("-1")

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
b = map(int, input().split())
# 1 1 1 2 2 1 2 3 2


# b = map(int, '1 1 1 2 2 1 2 3 2'.split())
# N = len(b)

steps = []
for i in range(N):
    cands = []
    for j in range(N - i):
        if (j + 1) == b[j]:
            cands.append(j)
    if len(cands) == 0:
        print(-1)
        sys.exit()
    else:
        j = cands[-1]
        steps.append(j + 1)
        b = b[:j] + b[j+1:]
for s in steps[::-1]:
    print(s)

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout
from math import sqrt, pi, acos, gcd, atan2, cos, sin, factorial
from decimal import Decimal
from random import randint
PEPS = 1e-10
INF = float('inf')


def sqr(a):
    return a * a


def dist(a, b = (0, 0)):
    return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]))


def s_dist(a, b = (0, 0)):
    return (sqr(a[0] - b[0]) + sqr(a[1] - b[1]))


def dist3(a, b = (0, 0, 0)):
    return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2]))


def s_dist3(a, b = (0, 0, 0)):
    return (sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2]))


def trans(p, al):
    return (p[0] * cos(al) + p[1] * sin(al), - p[0] * sin(al) + p[1] * cos(al))


def get_angle(a, b, c):
    cos_al = (sqr(a) + sqr(b) - sqr(c)) / (2 * a * b)
    return acos(cos_al)


def write_float(ans):
    stdout.write(str('%.13f' % ans) + '\n')


def get_hight(pt1, pt2, pt3):
    a = (pt2[0] - pt1[0], pt2[1] - pt1[1])
    b = (pt3[0] - pt1[0], pt3[1] - pt1[1])
    return abs(a[0] * b[1] - a[1] * b[0]) / dist(pt1, pt2)


def get_square(pt1, pt2, pt3):
    a = (pt2[0] - pt1[0], pt2[1] - pt1[1])
    b = (pt3[0] - pt2[0], pt3[1] - pt2[1])
    return (a[0] * b[-1] - a[1] * b[0]) / 2


def sign(v):
    if v > 0:
        return 1
    elif v < 0:
        return -1
    else:
        return 0


def inn(pt, triangle):
    signs = set()
    signs.add(sign(get_square(triangle[0], triangle[1], pt)))
    signs.add(sign(get_square(triangle[1], triangle[2], pt)))
    signs.add(sign(get_square(triangle[2], triangle[0], pt)))
    return len(signs) == 1


def inter_in(a, b):
    return dist((a[0], a[1]), (b[0], b[1])) < a[-1] + b[-1]


def inter_in3(a, b):
    return dist3(a[:-1], b[:-1]) < a[-1] + b[-1]


def shift(what, wth):
    return (what[0] - wth[0], what[1] - wth[1])


n = int(stdin.readline())
vl = list(map(int, stdin.readline().split()))
ans = []

while len(vl):
    for i in range(len(vl) - 1, -1, -1):
        if vl[i] == i + 1:
            ans.append(i + 1)
            vl = vl[:i] + vl[i + 1:]
            break
    else:
        stdout.write('-1\n')
        break


if len(ans) == n:
    ans = ans[::-1]
    stdout.write('\n'.join(list(map(str, ans))))

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout
from math import sqrt, pi, acos, gcd, atan2, cos, sin, factorial



def sqr(a):
    return a * a


def dist(a, b = (0, 0)):
    return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]))


def s_dist(a, b = (0, 0)):
    return (sqr(a[0] - b[0]) + sqr(a[1] - b[1]))


def dist3(a, b = (0, 0, 0)):
    return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2]))


def s_dist3(a, b = (0, 0, 0)):
    return (sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2]))


def trans(p, al):
    return (p[0] * cos(al) + p[1] * sin(al), - p[0] * sin(al) + p[1] * cos(al))


def get_angle(a, b, c):
    cos_al = (sqr(a) + sqr(b) - sqr(c)) / (2 * a * b)
    return acos(cos_al)


def write_float(ans):
    stdout.write(str('%.13f' % ans) + '\n')


def get_hight(pt1, pt2, pt3):
    a = (pt2[0] - pt1[0], pt2[1] - pt1[1])
    b = (pt3[0] - pt1[0], pt3[1] - pt1[1])
    return abs(a[0] * b[1] - a[1] * b[0]) / dist(pt1, pt2)


def get_square(pt1, pt2, pt3):
    a = (pt2[0] - pt1[0], pt2[1] - pt1[1])
    b = (pt3[0] - pt2[0], pt3[1] - pt2[1])
    return (a[0] * b[-1] - a[1] * b[0]) / 2


def sign(v):
    if v > 0:
        return 1
    elif v < 0:
        return -1
    else:
        return 0


def inn(pt, triangle):
    signs = set()
    signs.add(sign(get_square(triangle[0], triangle[1], pt)))
    signs.add(sign(get_square(triangle[1], triangle[2], pt)))
    signs.add(sign(get_square(triangle[2], triangle[0], pt)))
    return len(signs) == 1


def inter_in(a, b):
    return dist((a[0], a[1]), (b[0], b[1])) < a[-1] + b[-1]


def inter_in3(a, b):
    return dist3(a[:-1], b[:-1]) < a[-1] + b[-1]


def shift(what, wth):
    return (what[0] - wth[0], what[1] - wth[1])


n = int(stdin.readline())
vl = list(map(int, stdin.readline().split()))
ans = []

while len(vl):
    for i in range(len(vl) - 1, -1, -1):
        if vl[i] == i + 1:
            ans.append(i + 1)
            vl = vl[:i] + vl[i + 1:]
            break
    else:
        stdout.write('-1\n')
        break


if len(ans) == n:
    ans = ans[::-1]
    stdout.write('\n'.join(list(map(str, ans))))

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout
from math import sqrt, pi, acos, gcd, atan2, cos, sin, factorial
from decimal import Decimal
from random import randint
from matplotlib import mlab
from matplotlib import pylab
PEPS = 1e-10
INF = float('inf')


def sqr(a):
    return a * a


def dist(a, b = (0, 0)):
    return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]))


def s_dist(a, b = (0, 0)):
    return (sqr(a[0] - b[0]) + sqr(a[1] - b[1]))


def dist3(a, b = (0, 0, 0)):
    return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2]))


def s_dist3(a, b = (0, 0, 0)):
    return (sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2]))


def trans(p, al):
    return (p[0] * cos(al) + p[1] * sin(al), - p[0] * sin(al) + p[1] * cos(al))


def get_angle(a, b, c):
    cos_al = (sqr(a) + sqr(b) - sqr(c)) / (2 * a * b)
    return acos(cos_al)


def write_float(ans):
    stdout.write(str('%.13f' % ans) + '\n')


def get_hight(pt1, pt2, pt3):
    a = (pt2[0] - pt1[0], pt2[1] - pt1[1])
    b = (pt3[0] - pt1[0], pt3[1] - pt1[1])
    return abs(a[0] * b[1] - a[1] * b[0]) / dist(pt1, pt2)


def get_square(pt1, pt2, pt3):
    a = (pt2[0] - pt1[0], pt2[1] - pt1[1])
    b = (pt3[0] - pt2[0], pt3[1] - pt2[1])
    return (a[0] * b[-1] - a[1] * b[0]) / 2


def sign(v):
    if v > 0:
        return 1
    elif v < 0:
        return -1
    else:
        return 0


def inn(pt, triangle):
    signs = set()
    signs.add(sign(get_square(triangle[0], triangle[1], pt)))
    signs.add(sign(get_square(triangle[1], triangle[2], pt)))
    signs.add(sign(get_square(triangle[2], triangle[0], pt)))
    return len(signs) == 1


def inter_in(a, b):
    return dist((a[0], a[1]), (b[0], b[1])) < a[-1] + b[-1]


def inter_in3(a, b):
    return dist3(a[:-1], b[:-1]) < a[-1] + b[-1]


def shift(what, wth):
    return (what[0] - wth[0], what[1] - wth[1])


n = int(stdin.readline())
vl = list(map(int, stdin.readline().split()))
ans = []

while len(vl):
    for i in range(len(vl) - 1, -1, -1):
        if vl[i] == i + 1:
            ans.append(i + 1)
            vl = vl[:i] + vl[i + 1:]
            break
    else:
        stdout.write('-1\n')
        break


if len(ans) == n:
    ans = ans[::-1]
    stdout.write('\n'.join(list(map(str, ans))))