Problem:


Score : 400 points

Problem Statement

We have N bricks arranged in a row from left to right.

The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it.

Among them, you can break at most N-1 bricks of your choice.

Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \leq i \leq K), the i-th of those brick from the left has the integer i written on it.

Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.

Constraints

All values in input are integers.

1 \leq N \leq 200000

1 \leq a_i \leq N

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.

Sample Input 1

3
2 1 2

Sample Output 1

1

If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.

Sample Input 2

3
2 2 2

Sample Output 2

-1

In this case, there is no way to break some of the bricks to satisfy Snuke's desire.

Sample Input 3

10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

7

Sample Input 4

1
1

Sample Output 4

0

There may be no need to break the bricks at all.



Sample input:
3
2 1 2


Sample output:
1

Submission status: Runtime Error

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

if 1 not in bricks:
    print(-1)

else:
    K = 0
    value = 1
    while(value in bricks):
        index = bricks.index(value)
        bricks[value-1:index]=[]
        K += (index+1-value)
        value += 1
print(K)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(int(i) for i in input().split())
x = 0
for i in range(N):
    if a[i] == 1:
        b = a[i:]
        x = 1
        u = i
        break


def dp(n):
    if n == 1 :
        return [0,0]
    elif b[dp(n-1)[1]]+1 ==b[n-1]  :
        return [dp(n-1)[0],n-1]
    else:
        return [dp(n-1)[0]+1,dp(n-1)[1]]

if x == 1:
    print(dp(N-u)[0]+u)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)

Submission status: Runtime Error

Solution code:
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
else:
    i = 1
    a_l = a_l[a_l.index(i)+1:]
    i += 1
    while True:
        if a_l.count(i) > 0:
            a_l = a_l[a_l.index(i)+1:]
            i += 1
        else:
            break
print(n - (i-1))

Submission status: Runtime Error

Solution code:
n = int(input())
m = list(map(int, input().split()))
ans = 0


if m == [i+1 for i in range(n)]:
    print(0)
elif 1 not in m:
    print(-1)
else:
    for i in m:
    
        if i == target:
            ans += 1
            target += 1

    print(n-ans)

Submission status: Runtime Error

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

cnt = 0
num = 1

for i in range(n):
  if a[i] == num:
    num += 1
    cnt += 1

if cnt == 0:
  pirnt(-1)
else:
  print(n - cnt)

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
nums = list(map(int,input().split()))

number = 1
count = 0

if 1 not in nums:
    print(-1)
    sys.exit()

while len(nums) > 0:
    try:
        idx = nums.index(number)
    except ValueError:
        break
    count += idx
    nums = nums[idx+1:]
    print(nums)
    number += 1

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
s =input().split()

cnt = 0
flag = -1
a = 0
for i in range(0,len(s)):

    if i+1 == int(s[i]):
        break
    else:
       s.pop(i)
       cnt = cnt + 1
       flag = 1
       a = a + 1

if flag == 1:
    print(cnt)
else:
    print(flag)

Submission status: Runtime Error

Solution code:
n = int(input())
brick = list(map(int, input().split()))
cnt = 0
def Break(brick, i):
    if len(brick) == 0:
        return
    else:
        if i not in brick:
            return
        else:
            j = brick.index(i)
            brick = [brick[k] for k in range(j+1, len(brick))]
            global cnt
            cnt += 1
            Break(brick, i + 1)
Break(brick, 1)
if cnt == 0:
    print(-1)
else:
    print(n - cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
s =input().split()

cnt = 0
flag = -1
a = 0
for i in range(0,len(s)):

    if i+1 == int(s[i]):
        continue
    else:
       s.pop(i)
       cnt = cnt + 1
       flag = 1
       a = a + 1

if flag == 1:
    print(cnt)
else:
    print(flag)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
f=0
g=1
for i in range(0,n):
    if A[i]!=g:
      f++
    else:
      g++
    #printf("%d %d\n",f,g)
if g!=1:
    print(f)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
n=int(input())
for i in range(0,n):
    a[i]=int(input())
f=0
g=1
for i in range(0,n):
    if a[i]!=g:
      f++
    else:
      g++
    #printf("%d %d\n",f,g)
if g!=1:
    print(f)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
def lmc(a,b):
	i = 1
	while(1):
		c = a*i
		if c % b == 0:
			return c
		i += 1

print("a= ",end="")
a= int(input())
print("b= ",end="")
b= int(input())
print(lmc(a,b))

Submission status: Runtime Error

Solution code:
N = int(input())
As = [int(i) for i in input().split()]

iter = 0
ans = 0
while(True):
  while(As[iter] != (iter+1)):
    del As[iter]
    ans += 1
  iter += 1

  if(iter >= len(As)):
    break
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
li_str = input().split()
li_int = []
for i in li_str:
    li_int.append(int(i))
count= 1
for i in li_int:
    if i == count:
        num = count
        count += 1
print(N - num)

Submission status: Runtime Error

Solution code:
N = int(input())
li_str = input().split()
li_int = []

for i in li_str:
    li_int.append(int(i))
count= 1
for i in li_int:
    if i == count:
        count += 1
        num = count
print(num)

Submission status: Runtime Error

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

num = 0
for i in range(N):
  if a[i] == (num + 1):
    num += 1

if num == 0:
  print(-1)
else:
  print(N-num)

Submission status: Runtime Error

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

c = 0
e = len(A)
for i in range(e - ):
  d = 1
  if A[i] == d:
    d = d + 1
  else:
    c = c + 1

if c == e:
    print(-1)
else:
    print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
if not 1 in a:
    print(-1)
else:
    for i in range(1,n):
        if i in a:
            index=a.index(i)
            a=a[index:]
        else:
            break
    print(n-i+1)

Submission status: Runtime Error

Solution code:
a = int(input())
n = list(map(int.input().split()))
b = 0
c = 0
flag = 0
for i in n:
    if not int(i) == b+1:
        c +=1
    else:
        b += 1
        flag = 1
if flag == 0:
    c = -1
print(c)

Submission status: Runtime Error

Solution code:
N = int(input()) - 1
array = list(map(int, input().split()))

breaktime = 0
i = 0
while i <= N:
  for j in range(N+1):
    if array[j] == i+1:
      del array[i:j]
      N = N - (j - i)
      breaktime += j-i
      break
    if j==N and array[j] != i+1:
      if i == 0:
        breaktime = -1
      else:
        del array[i:]
        breaktime += N-i+1
        break
  if breaktime == -1:
    break
  i += 1

print(breaktime)

Submission status: Runtime Error

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

num = 1
ans = 0

if i in range(n):
  if num == a[i]:
    num += 1

if num == 1:
  ans = -1
else:
  ans = n - num + 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
lst = list(map(int, intput().split()))
x = 0
for i in lst:
  if i == x + 1:
    	x = x + 1

print(n-x)

Submission status: Runtime Error

Solution code:
N = int(input())
a = input().split()
for i in range(N):
  a[i] = int(a[i])
index = 1
count = 0
for i in range(N):
  if a[i] = index:
  	index += 1
  else:
    count += 1
print(count)

Submission status: Runtime Error

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

min_num = min(list(set(a_list)))
print('min_num:',min_num)

if min_num != 1 :
  print(-1)
  exit()

min_num_index = a_list.index(min_num)
print('min_num_index:',min_num_index)

break_times = min_num_index

next_list = a_list[min_num_index+1:]
next_min_num = min(list(set(next_list)))
next_min_num_index = next_list.index(next_min_num)

for i in range(int(min_num+1), len(a_list)):
  if next_min_num == min_num + 1:
    break_times += next_min_num_index
  else :
    next_list = a_list[int(a_list.index(next_min_num)+1):]
    next_min_num = min(list(set(next_list)))
    if next_min_num == i :
      next_min_num_index = next_list.index(next_min_num)
      break_times += next_min_num_index
    else :
      break
                
break_times += len(next_list[next_min_num_index+1:])

print(break_times)

Submission status: Runtime Error

Solution code:
uantity = int(input())
block = list(map(int,input().rstrip().split(" ")))

print(block)

num = 1
for i in block:
    if i == num:
        num += 1

if num == 1:
    print(0)
else:
    print(quantity - num + 1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().spllit()))
now = 1
brok = 0
for i in range(n):
    if(a[i] == now):
        brok += 1
    else:
        now += 1
if(now == 1):
    print(-1)
else:
    print(brok)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().spllit()))
now = 1
brok = 0
for i in range(n):
    if(a[i] = now):
        brok += 1
    else:
        now += 1
if(now == 1):
    print(-1)
else:
    print(brok)

Submission status: Runtime Error

Solution code:
n = int(input())
 
a = list(map(int,input().split()))
 
s = 1
t = 0
 
for i in range(n):
 if s == a[i]:
      s += 1
   else:
      t +=1
      
if t != n:
  print(t)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
n = int(input())

a = list(map(int,input().split()))

s = 1
t = 0

for i in range(n):
	if s == a[i]:
      s += 1
    else:
      t +=1
      
if t != n:
  print(t)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
n = int(input())
no = n
list1 = list(map(int, input().split()))
# for i in range(n):
#     m = int(input())
#     list1.append(m)
# print(list1)
if 1 not in list1:
    print("-1")
else:
    for i in range(len(list1)):
        if list1[i] is not 1:
            pass
        else:
            # print("The location where i hits 1 is:",i)
            a = i
            no = no -1
            increasingshit = 2
            break
    list2 = []
    maxno = max(list1)
    # print("Max of all inputs is:",maxno)
    # print("now increasingshit is",increasingshit)

    def A(a):
        global increasingshit
        global no
        for j in range(a,len(list1)):
            if list1[j] == increasingshit:
                no = no - 1
                increasingshit = increasingshit + 1
                a = j
                A(a)
            else:
                pass
    A(a)
    print(no)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    if list(set(a)[0]) != 1:
        print(-1)
        exit()
    else:
        print(0)
        exit()

x = 1
count = 0
for i in a:
    if i == x:
        x+=1
    else:
        count+=1
if count == n:
    print(-1)
else:
    print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    if set(a)[0] != 1:
        print(-1)
        exit()
    else:
        print(0)
        exit()

x = 1
count = 0
for i in a:
    if i == x:
        x+=1
    else:
        count+=1
if count == n:
    print(-1)
else:
    print(count)

Submission status: Runtime Error

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

if len(set(a)) == 1:
    if set(a)[0] != 1:
        print(-1)
        exit()
    else:
        print(0)
        exit()

x = 1
count = 0

for i in a:
    if i == x:
        x+=1
    else:
        count+=1

print(count)

Submission status: Runtime Error

Solution code:
### -*- coding: utf-8 -*-

splited = input().split("\n")
N = int(splited[0])
nums = list(map(int, splited[1].split()))

hitting = 1
isHitOnce = False
for num in nums:
    if num == hitting:
        hitting += 1
        isHitOnce = True

if hitting == 1:
    print(-1)
else:
    print(N - (hitting - 1))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
if not 1 in l:
  print(-1)
  exit()
cnt = 1
ans = 0
for item in l:
  if item = cnt:
    ans += 1
    cnt += 1
print(n - ans)

Submission status: Runtime Error

Solution code:
n=int(input())

l=list(map(int,input().split()))
cnt=0
for i in range(n):
	if l[i]==cnt+1:
      cnt+=1
      
if cnt==0:
  	print(-1)
else:
  print(n-cnt)

Submission status: Runtime Error

Solution code:
a=int(input())
b=[int(x) for x in input().rstrip().split()]
l=[]
c=0
flag=1

for i in range(1,a+1):
    l=b[i-1:]
    for j in range(len(b)):
        
        if len(b)-2<i:
            flag=0
            break
        else:
            if i==l[j]:
                break
    
            else:
                b.pop(j)
                c+=1
if flag==0:
    print(-1)
else:
    print(c)

Submission status: Runtime Error

Solution code:
a=int(input())
b=[int(x) for x in input().rstrip().split()]
l=[]
c=0
flag=1

for i in range(1,a+1):
    l=b[i-1:]
    for j in range(len(b)):
        
        if len(b)-1<i:
            flag=0
            break
        else:
            if i==l[j]:
                break
    
            else:
                b.pop(j)
                c+=1
if flag==0:
    print(-1)
else:
    print(c)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n;
    vector <int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    cnt = 1;
    ans = 0;
    for(int i=0;i<n;i++){
        if(a[i] != cnt){
            ans++;
        }else{
         cnt++;   
        }
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input().split())
*l, = map(int,input().split())
ans = 0
tmp=1
for i in range(n):
  if l[i] == tmp:
    tmp+=1
  else:
    ans += 1
print(-1 if ans==n else ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
now = 1
for i in a:
    if i == now:
        now += 1
print(-1 if now == 1 else n - now + 1)
index197511@index197511-VirtualBox:~/comp

Submission status: Runtime Error

Solution code:
n = int(raw_input())
bricks = raw_input().split()
bricks = [int(i) for i in bricks]
smash = 0
result = []
pos = 1
if 1 not in bricks:
  smash = -1
else:
  for i in range(1,n+1):
    if i >= len(bricks): break
    while bricks[i-1] != i:
      bricks.pop(i-1)
      smash = smash+1
print(smash)

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.buffer.readline
 
n = int(readline())
num = 1
res = 0
for i in readline().split():
  if num != int(i):
    res += 1
  else:
    i += 1

if res == n:
  print(-1)
else:
  print(res)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
x = input().split()

data = [0 for i in range(N)]
for i in range(N):
	data[i] = int(x[i])

nxt = 1
ans = 0

for i in range(N):
	if nxt == data[i]:
		nxt += 1
	else:
		ans += 1
if ans == N:
	print(-1)
	exit(1)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ori = [int(i) for i in input().split()]
count = ori.count(1)
if count == 0:
    print(-1)

else:
    Break = 0
    for j in range(1,N+1):
        for i in range(Break+1,N):
            if ori[i] == j:
                Break = i
                #print(Break)
                #print(savepoint)
                #print(j,i)
                sub = j
                break
        if i == N-1:
            break
    print(Break+1-sub)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
count = 0
k=0
t=0

while k<len(A):
    if A[t] == k+1:
            k += 1
            t += 1
    else:
            count += 1
            t =+ 1
if count == N:
    print(-1)
else:
    print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
ori = [int(i) for i in input().split()]
count = ori.count(1)
if count == 0:
    print(-1)
Break = 0
quit  = 0
for j in range(1,N+1):
    for i in range(Break,N):
        if ori[i] == j:
            Break = i
            #print(Break)
            #print(savepoint)
            #print(j,i)
            sub = j
            break
    if i == N-1:
        break
        #else: 
            #quit = 1
            #break
    #if quit == 1:
        #print(quit)
        #break
print(Break+1-sub)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = set(sorted(A))
k = 1
a = 0
b = []
for i in B:
    if i != k:
        break
    j = A.index(i)
    a += j+1
    b.append(a)
    A = A[j+1:]
    if a == N:
        break
    k += 1
    
if b == []:
    print(-1)
else:
    print(N-len(b))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    a_l = [int(i) for i in input().split()]
    if 1 not in a_l:
        print(-1)
        sys.exit()
    counter = 1
    b = 0
    for i in a_l:
        if i == counter:
            counter += 1
        else:
            b += 1
    print(b)
    sys.exit()


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
ori = [int(i) for i in input().split()]
#print(N,ori)
count = ori.count(1)
#print(count)
if count == 0:
    print(-1)
Break = 0
quit  = 0
for j in range(1,N+1):
    for i in range(Break+1,N):
        if ori[i] == j:
            Break = i
            #print(Break)
            #print(savepoint)
            #print(j,i)
            sub = j
            break
        #else: 
            #quit = 1
            #break
    #if quit == 1:
        #print(quit)
        #break
print(Break+1-sub)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
from itertools import groupby

N = int(input())
al = sorted(enumerate([int(e) for e in input().split(" ")[:N]]), key=itemgetter(1))

if N==1 and al[0] == (0, 1):
    print(0)
    exit(0)

gb = groupby(al, key=itemgetter(1))
lst = [(key, [i for (i, _) in obj]) for (key, obj) in gb]
pos = 0
pls = 0
for n in range(1, N):
    (key, psl) = lst[0]
    if key != n:
        break
    ovl = [p for p in psl if p > pos]
    if len(ovl) == 0:
        pls = 1
        break
    pos = ovl[0]
    lst = lst[1:]

if n == 1:
    print(-1)
    exit(0)
else:
    print(N-n+pls)

Submission status: Runtime Error

Solution code:
N = int(input())
ori = [int(i) for i in input().split()]
print(N,ori)
count = ori.count(1)
print(count)
if count == 0:
    print(-1)
savepoint = 0
Break = 0
quit  = 0
for j in range(1,N+1):
    for i in range(savepoint+1,N):
        if ori[i] == j:
            Break = i
            savepoint = i
            #print(Break)
            #print(savepoint)
            #print(j,i)
            sub = j
            break
        #else: 
            #quit = 1
            #break
    #if quit == 1:
        #print(quit)
        #break
print(Break+1-sub)

Submission status: Runtime Error

Solution code:
n=int(input())
h=list(map(int,input().split()))
mn=min(h)
cnt=1
if(mn!=1):
    print("-1")
    exit()
r=len(h)
for i in range(len(h)):
    if(len(h)==1):
        break
    cnt=cnt+h.index(i+1)-1
    del h[0:h.index(i+1)]
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = set(sorted(A))
k = 1
a = 0
b = []
for i in B:
    j = A.index(i)
    if i != k:
        break
    a += j+1
    b.append(a)
    A = A[j+1:]
    if a == N:
        break
    k += 1
    
if b == []:
    print(-1)
else:
    print(N-len(b))

Submission status: Runtime Error

Solution code:
n=int(input())
seq=list(map(int,input().split()))
count=0
while True:
    for i in range(1,n+1):
        if i not in seq:
            break
        kizyun=seq.index(i)
        for j in range(i-1,kizyun):
            seq.pop(j)
            count+=1
    if i+1 not in seq:
        break
if 1 not in seq:
    print(-1)
else:
    print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
List_Bricks = [int(i) for i in input().split()]
#print(List_Bricks)
Search = 1
Kudaku = 0
i = 0
Boole = False
Count = 0
L = len(List_Bricks)-1
while len(List_Bricks) != 1:
    try:
        del List_Bricks[0:List_Bricks.index(Search)]
    except ValueError:
        pass
    Kudaku += List_Bricks.index(Search)
    Search += 1

Submission status: Runtime Error

Solution code:
n=int(input())
seq=list(map(int,input().split())
count=0
while True:
    for i in range(1,n+1):
        if i not in seq:
            break
        kizyun=seq.index(i)
        for j in range(i-1,kizyun):
            seq.pop(j)
            count+=1
    if i+1 not in seq:
        break
if 1 not in seq:
    print(-1)
else:
    print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
N=list(map(int,input().split()))
M=list(range(1,n+1))
if(1 in N==false):
  print(-1)
for i in range(n): 
  if(len(N)==i+2):
    break
  else:    
    while(N[i]!=M[i]):
      del N[i]
      print(N)
      print(len(N))
      print(i)
print(n-len(N)+1)

Submission status: Runtime Error

Solution code:
from sys import stdin


n = int(stdin.readline().rstrip())
arr = [int(x) for x in stdin.readline().rstrip().split()]

rslt = []
for i in range(1,n):
    cntr = 0
    ex = 0
    for s in arr:
        s = int(s)
        if ex != 0:
            ex = s
        if s != ex +1:
            cntr += 1
        ex = s
    rslt.append(cntr)


print(rslt)
print(min(rslt))

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
if 1 not in A:
    print(-1)
else:
    F = sorted((b, i) for i, b in enumerate(A))
    ans  = 0
    back = 0
    prev = -1
    for i in range(1, n):
        yo = (i, prev)
        ind = bisect_left(F, yo)
        if F[ind][0] != i:
            ans = n - i + 1
            break
        prev = F[ind][1]
    print(ans)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a = (int(x) for x in input().split())
    c = 0
    if 1 not in a:
        print(-1)
        exit()
    i = 0
    for nn in range(1, n + 1):
        if a[i:] == range(nn,n - c + 1):
            break
        if nn in a[i:]:
            ind = a[i:].index(nn)
            if ind == 0:
                i += 1
                continue
            else:
                c += len(a[i:i + ind])
                i += ind + 1
        else:
            c +=  len(a[i:])
            break
    print(c)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
C = sort(A)
B = set(C)
K = len(set(A))
k = 1
a = 0
b = []
while i in B:
    j = A.index(i)
    if i != k:
        break
    a += j+1
    b.append(a)
    a = A[j+1:]
    if a == N:
        break
    k += 1
    
if b == []:
    print(-1)
else:
    print(N-len(b))

Submission status: Runtime Error

Solution code:
N=int(input())
li = list(map(int,input().split()))
count=0
for i in range(N):
  if i in li:
    iti=int(li.index(i))
    count=count+iti
    for u in range(iti+1):
      li.pop(u)
   
    
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
count=0

if 1 not in a:
    count=-1
else:
    for i in range(1,N):
        if len(a) == 1:
            break
        while a[0]!=i 
            count+=1
            a.pop(0)
            if len(a)==0:
                break
                
        if len(a) <= 1:
            break
        a.pop(0)
print(count)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    string = input()
    A_c = string.split(' ')
    A = []
    for i in A_c:
        A.append(int(i))
    
    num_break = 0
    i = 0
    while 1:
        while A[i] != i+1:
            num_break = num_break + 1
            del A[i]
            if len(A) == 0 or num_break == N:
                return -1
            
        i = i + 1
        if A[len(A) - 1] == N - num_break:
            return num_break
            
if __name__ == "__main__":
    print(main())

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append("0")
t=0
for i in range(n):
    if a[i+1]!="0":
     if a[i + 1] - a[i] != 1:
            t+=1
            a.pop(i)
    else:
        break
print(t)

Submission status: Runtime Error

Solution code:
n = int(input())
c = list(map(int, input().split()))
ln = []
if c.count(1) == 0:
    print(-1)
else:
    c2 = c
    for i in range (1, max(c)+1):
        if i in c2 :
            s = c2.index(i)
            ln.append(i)
            del c2[:s + 1]
            if len(c2) == 1 and  i + 1 in c2:
                    ln.append(i + 1)
        else:
            break
print(n - max(ln))

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = list(input())
b =list(map(int,a))
aa = list(set(b))
x = []
y = []
c = 1
for i in range(1,n+1):
    x.append(i)
for j in aa:
    if j in x and 1 in aa:
        pass
    else:
        print("-1")
        sys.exit()
for k in a:
    if int(k) == c:
        y.append(k)
        c = c + 1
print(len(a)-len(y))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=0
d=0
while True:
  if d+1 in a:
    c=a[c:].index(d+1)
    d+=1
    del a[:c]
  else:
    break
print(-1 if d==0 else n-d)

Submission status: Runtime Error

Solution code:
n=int(input())
seq=list(map(int,input().split()))
count=0
if 1 not in seq:
  print(-1)
else:
  while True:
    for i in range(1,n+1):
      kizyun=seq.index(i)
      for j in range(i-1,kizyun):
        seq.pop(j)
        count+=1
    if i+1 not in seq:
      break
  print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=list(set(a))
if b[0]!=1:
  print(-1)
else:
  x=0
  y=0
  cnt=0
  i=0
  flg=0
  while y!=N-1:
    y=a[x:].index(i+1)+x
    cnt+=y-x-1
    x=y
    i+=1
    flg=1
  print(cnt+flg)

Submission status: Runtime Error

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

b = []
j = 0
k = 1

for i in range(n):
	if k == int(a[i]):
	b.append(int(a[i]))
	j += 1
	k += 1

if 0 == len(b):
	print(-1)
else:
	print(int(n)-len(b))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(input())
b =list(map(int,a))
aa = list(set(b))
x = []
y = []
z = []
c = 1
for i in range(1,n+1):
    x.append(i)
for j in aa:
    if j in x and 1 in aa:
        z.append(j)
    else:
        print("-1")
        exit()
for k in a:
    if int(k) == c:
        y.append(k)
        c = c + 1
print(len(a)-len(y))

Submission status: Runtime Error

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

b = []
j = 0
k = 1

for i in range(n):
	if k == int(a[i]):
	b.append(int(a[i]))
	j += 1
	k += 1

if 0 == len(b):
	print(-1)
else:
	print(int(n)-len(b))

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
count=0

if 1 not in a:
    count=-1
else:
    for i in range(1,N):
        if len(a) == 1:
            break
        while a[0]!=i:
            count+=1
            a.pop(0)
        if len(a) == 1:
            break
        a.pop(0)
print(count)

Submission status: Runtime Error

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

target = 1
count = 0
while len(S) > 0:
    # print("1:", S)
    for i in range(0, N):
        if S[i] == target:
            count += len(S[0:i])
            del S[0:i+1]
            target += 1
            # print("2:",S)
            print(count)
            break
    continue

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=0
d=0
for i in range(1,n+1):
  if i in a:
    c=a[c:].index(i)
    d+=1
    del a[:c]
  else:
    break
print(-1 if d==0 else n-d)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(input())
b =list(map(int,a))
aa = list(set(b))
x = []
y = []
c = 1
for i in range(1,n+1):
    x.append(i)
for j in aa:
    if j in x and 1 in aa:
        c = 1
        
    else:
        print("-1")
        exit()
for k in a:
    if int(k) == c:
        y.append(k)
        c = c + 1
print(len(a)-len(y))

Submission status: Runtime Error

Solution code:
N = int(input())

a = list(map(int, input().split()))

b = [[] for i in range(N)]
b[0] = a
m = 0
for i  in range(1, N+1):
    if i in b[i-1]:
        b[i] = b[i-1][b[i-1].index(i):N]
        m = i

print(N -m)

Submission status: Runtime Error

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

b = a.copy()
count = 0
max_index = 0
ans = 0

while count <= N:
  count += 1  
  order = [i for i, x in enumerate(a) if x == count]
  
  if len(order) == 0:
    pass
  else:
    order1 = order[-1]
    ans = ans+order1   
  del a[0:order1+1]
      
if b.count(1) == 0:
  print(-1)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
	if a[i]-1 == count:
		count += 1
if count == 0:
	print(-1)
else:
	prin
	t(n-count)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
count=0

if 1 not in a:
    count=-1
else:
    for i in range(1,N):
        if len(a) == 1:
            break
        while a[0]!=i:
            count+=1
            a.pop(0)
        if len(a) == 1:
            break
        a.pop(0)



print(count)

Submission status: Runtime Error

Solution code:
n = input()
a = input().split( )

b = []
j = 0
k = 1

for i in range(int(n)):
    if k == int(a[i]):
	b.append(a[i])
	j += 1
	k += 1

if 0 == len(b):
    print(-1)
else:
    print(int(n)-len(b))

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
k = 1
try:
 for _ in range(n):
  #print(a[k-1],"!=",k,"なので")
  if int(a[k-1]) != int(k):
   #print("0",a)
   a.pop(k-1)
   #print("1",a)
   k = k -1
  k = k + 1
except:
 break
res = n-len(a)
if res == n:
 print("-1")
else:
 print(n-len(a))

Submission status: Runtime Error

Solution code:
# 1行目の入力を数値として扱う
N = int(input())
# 2行目の入力を数値のリストとして扱う
a = list(map(int, input().split()))

# 答えの準備
res = 0

# 最大値
mx = max(a)
print(mx)

# 位置
pos = 0

# チェック
if min(a) != 1:
    print(-1)
    exit()

# ループ最大
lmx = 0

# ループ
for i in range(1, mx + 1):
    lmx = i
    if pos < a.index(i):
        pos = a.index(i)
    else:
        break

# 答えの出力
print(N - lmx)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
count=0

if 1 not in a:
    count=-1
else:
    for i in range(1,N):
        if len(a) == 1:
            break
        while a[0]!=i:
            count+=1
            a.pop(0)
        a.pop(0)



print(count)