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: Wrong Answer

Solution code:
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N = inp()

a = inlist()
pos = 0
rm = 0
m = max(a)
for i in range(1, m):

    for j in range(pos, N):
        if a[j] != i:
            rm += 1

        else:
            pos = j + 1
            break

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
nu = 1
bl = 0
if not 1 in A:
    print(-1)
else:
    for i in range(1,N+1):
        if A[i-1] == nu:
            nu += 1
            bl += 1
print(N-bl)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
broken = 0
flag = [0, 0]
for i in range(1,N + 1):
  if flag[1] != 0:
    break
  for j in range(len(A)):
    if A[j] == i:
      if len(A) != 1:
      	A = A[j + 1:]
      else:
        A = []
        flag[0] += 1
      break
    else:
      broken += 1
    if len(A) == i + 1:
      flag[1] += 1
if broken == 0 and flag[0] != 1:
  print(-1)
else:
  print(broken)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ex = list(range(1, N + 1))
is_good = 0
for i in range(N):
  if A[i] == ex[i]:
    is_good += 1
print(-1 if is_good == 0 else N - is_good)

Submission status: Wrong Answer

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

now = 1
hit = 0
for a in A:
    if a != now:
        hit += 1
    else:
        now += 1
print(hit)

Submission status: Wrong Answer

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

tmp_num=1
tmp_cnt=0
cnt=0
for i in range(n):
    if a[i]==tmp_num:
        tmp_num+=1
        cnt+=tmp_cnt
        tmp_cnt=0
    else:
        tmp_cnt+=1
print(-1 if tmp_cnt==len(a) else cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
n_len = len(a_list)
left = 0
count = 0
for i in range(1,n+1):
    for j in range(left,n):
        if a_list[j] == i:
            left = j+1
            break
        count += 1
    if left > n_len-1:
        print(count)
        break
else:
    print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
l = list(map(int,input().split()))
d = {}
for i in range(n):
        d[l[i]] = i
lis = sorted(d.items())
if lis[0][0] != 1:
    print("-1")
    sys.exit()
length = len(lis)
count = 1
if length != n:
    for i in range(length-1):
        if lis[i][1] < lis[i+1][1] and lis[i][0]+1 == lis[i+1][0]:
            count += 1
        else:
            break
if length == n:
     for i in range(length-1):
        if lis[i][1] < lis[i+1][1] and lis[i][0]+1 == lis[i+1][0]:
            count += 1
        else:
            break

answer = n-count
print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
def int1(x):
  return int(x)-1
a[:]=map(int1,input().split())

r=0
j0=0
import numpy as np
for ii in range(max(a)+1):
  for jj in np.arange(j0,n):
    if a[jj]==ii:
      r+=1
      j0=jj+1
      break
  if r==0:
    print(-1)
    exit()

print(n-r)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
def int1(x):
  return int(x)-1
a[:]=map(int1,input().split())
#print(a)
import numpy as np
l=np.argsort(a)
#print(l)
del a[0:l[0]]
r=0
z=0
m=len(a)
j0=0
for ii in range(max(a)):
  for jj in np.arange(j0,m):
    if a[jj]==ii:
      j0=jj+1
      r+=1
      break
    #print(a,r)
  if jj==m-1:
    #print(a)
    if r==0:
      print(-1)
    else:
      print(n-r)
    exit()
print(n-r)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
def int1(x):
  return int(x)-1
a[:]=map(int1,input().split())
#print(a)
r=0
for ii in range(n):
  if ii in a:
    a=a[a.index(ii):n]
    r+=1
    #print(a,r)
  else:
    #print(a)
    if r==0:
      print(-1)
    else:
      print(n-r)
    exit()

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
a = list(map(int,input().split()))
q = deque(a)
count = 1
ans = 0
for i in range(n):
    if q[0] == count:
        #print(q[0])
        count += 1
        q.popleft()
    else:
        q.popleft()
if count == 0:
    print(-1)
else:
    print(len(a)-count+1)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
m=max(A)
ans=0
B=[]
for i in range(1,N+1):
    for j,value in enumerate(A):
        if i==value:
            ans+=j
            A=A[j+1:]
            B.append(value)
            break
if not len(B)<=1:
    print(ans)
elif len(B)==N:
    print(0)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = list(map(int, input().split()))
cnt = 0
ref_num = 1
if 1 not in a_list:
    print(-1)
    exit()
while True:
  for i in range(len(a_list)):
    if ref_num == a_list[i]:
      red = len(a_list[:i])
      a_list = a_list[i+1:]
      cnt += red
      break
  ref_num += 1
  if a_list == []:
    print(cnt)
    break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int , input().split()))
count = 0 if 1 in a else -1
i = 1
while i in a:
  ind = a.index(i)
  count += ind
  a = a[ind + 1:]
  i += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=1
while True:
  if x in a:
    x+=1
  else:
    break
if x==1:
  print(-1)
else:
  print(n-x+1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)

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

def solve(l, K=0):
  if K+1 in l:
    pos = a.index(K+1)
    return solve(l[pos:],K+1)
  else:
    return K
  
def judge(x):
  if x == 0:
    return -1
  else:
    return N-x


print(judge(solve(a)))

Submission status: Wrong Answer

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

def solve(l, K=0):
  if K+1 in l:
    pos = a.index(K+1)
    return solve(l[pos:],K+1)
  else:
    return K
  
def judge(x):
  if x == 0:
    return -1
  else:
    return N-x


print(judge(solve(a)))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

if not 1 in (a):
  print(-1)
else:
  ans = 1
  for i in range(1, n+1):
    idx = np.where(a==i)[0][-1]
    ans += len(a[:idx]) - 1
    a = a[idx:]
  
    if not i+1 in a:
      print(ans + len(a) - 1)
      break

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

if not 1 in (a):
  print(-1)
else:
  ans = 1
  for i in range(1, n+1):
    print(a)
  
    idx = np.where(a==i)[0][-1]
    ans += len(a[:idx]) - 1
    a = a[idx:]
  
    if not i+1 in a:
      print(ans + len(a) - 1)
      break

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

ans = 1
for i in range(1, n+1):
  if not i in set(a):
    print(-1)
    break
  
  idx = np.where(a==i)[0][-1]
  ans += len(a[:idx]) - 1
  a = a[idx:]
  
  if len(a) == 1:
    print(ans)
    break

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

check = [i for i in range(1, n+1)]
ans = 1
for i in range(1, n+1):
  if not i in a:
    print(-1)
    break
  
  idx = np.where(a==i)[0][-1]
  ans += len(a[:idx]) - 1
  a = a[idx:]
  
  if len(a) == 1:
    print(ans)
    break

Submission status: Wrong Answer

Solution code:
N = int(input())
ls = list(map(int, input().split()))
counter = 1
for elem in ls:
    if elem == counter:
        counter += 1
print(N - counter + 1)

Submission status: Wrong Answer

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

cnt = 1
for a in setA:
    if a != cnt:
        print(-1)
        exit()
    cnt += 1

print(len(A) - len(setA))

Submission status: Wrong Answer

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

num = 1
now = 0
while True:
    if num in A[num-1:]:
        f = A[num-1:].index(num)
        A = A[f:]
        num += 1
    else:
        if num == 1:
            print(-1)
            exit()
        break
print(N - len(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map( int , input().split()))
T = list()
if A.count(1) == 0:
    print(-1)
else:
    for i in range(len(A)):
        if A[i] == len(T)+1:
            T.append(A[i])
#print(T)
print(N-len(T))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map( int , input().split()))
T = list()
for i in range(len(A)):
    if A[i] == len(T)+1:
        T.append(A[i])
#print(T)
print(N-len(T))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map( int , input().split()))
k = 1
h = 0
if N == 1 and A[0] == 1:
    print(0)
elif A.count(1) == 0:
    print(-1)
else:
    for k in range(1,max(A)):
        if k in A[h:len(A)]:
            #print(A[h:len(A)].index(k),k,h)
            #print(A[h:len(A)])
            h += A[h:len(A)].index(k)
            k+=1
            #print(h)
        else:
            #print(k)
            break
    print(N+1-k)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map( int , input().split()))
k = 1
h = 0
if N == 1 and A[0] == 1:
    print(0)
elif A.count(1) == 0:
    print(-1)
else:
    for k in range(1,max(A)):
        if k in A[h:len(A)]:
            #print(A[h:len(A)].index(k),k,h)
            #print(A[h:len(A)])
            h += A[h:len(A)].index(k)
            k+=1
            #print(h)
        else:
            #print(k)
            break
    print(h-k+2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map( int , input().split()))
k = 1
h = 0
if N == 1 and A[0] == 1:
    print(0)
elif A.count(1) == 0:
    print(-1)
else:
    for k in range(1,max(A)):
        if k in A[h:len(A)]:
            #print(A[h:len(A)].index(k),k,h)
            #print(A[h:len(A)])
            h += A[h:len(A)].index(k)
            k+=1
            #print(h)
        else:
            #print(k)
            break
        print(h-k+2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
flag = 0
sA = list(set(A))
ssA = sorted(sA)
for i in range(len(sA)):
  if sA[i] != ssA[i]:
    flag += 1
if flag != 0:
  print(-1)
  exit(0)
else:
  print(len(A) - len(sA))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = 1
if min(a) != 1:
  print("-1")
else:
  while i < len(a):
    if a[0] != i:
      a.pop(0)
    else:
      i += 1
  print(n - len(a))

Submission status: Wrong Answer

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

c = 1
ans = 0

for i in a:
    if (i == c):
        c += 1
    else:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0

if (1 not in a):
    print(-1)
else:
    for i in range(1,n+1):
        if (i not in a):
            ans+= len(a[i:])
            break
        else:
            ain = a.index(i)
            ans += ain-i
            del a[i:ain]
    print(ans)

Submission status: Wrong Answer

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

ans = 0

if (1 not in a):
    print(-1)
else:
    for i in range(1,n):
        if (i not in a):
            break
        else:
            ain = a.index(i)
            ans += ain
            del a[i:ain]
    print(ans)

Submission status: Wrong Answer

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

ans = 0

if (1 not in a):
    print(-1)
else:
    for i in range(1,n):
        if (i not in a):
            break
        else:
            ain = a.index(i)
            ans += ain
            a = a[:i] + a[ain:]
    print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    ind = int(input())
    t = list(map(int, input().split()))
    ans = []
    for i in range(ind):
        if len(ans) + 1 == t[i]:
            ans.append(t[i])
    count = -1 if len(ans) == 0 else ind - len(ans)
    print(ans)
    print(count)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    ind = int(input())
    t = list(map(int, input().split()))
    ans = []
    for i in range(ind):
        if len(ans) + 1 == t[i]:
            ans.append(t[i])
    count = 0 if len(ans) == 0 else ind - len(ans)
    print(count)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(s) for s in input().split(" ")]

List=[]
last_index=0
for number in range(1,N+1):
    for index in range(last_index,N):
        if number==a[index]:
            List.append(number)
            last_index=index
            break
                
print(-1 if List[0]!=1 else N-len(List))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = 1
c = 0
for i in range(N):
    if b ==a[i]:
        b += 1
    else:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
ans=0
l=1
for i in a:
  if i!=l:
    ans+=1
  else:
    l+=1
if ans==0:
  print("-1")
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
ans=0
l=1
for i in a:
  if i!=l:
    ans+=1
  else:
    l+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#初期入力
import sys
N = int(input())
A=[int(i) for i in input().split()]
#

i=2 #探す「文字」
brick_remain =set()
if 1 not in A:
    print(-1)
    exit
else:
    brick_remain.add(1)
    for a in A:
        if a ==i:
            brick_remain.add(a)
            i +=1
    brick_destroy = N - len(brick_remain)       
    print(brick_destroy)

Submission status: Wrong Answer

Solution code:
#初期入力
import sys
N = int(input())
A=[int(i) for i in input().split()]
#

i=2 #探す「文字」
brick_remain =set()
if 1 not in A:
    print(-1)
else:
    brick_remain.add(1)
    for a in A:
        if a ==i:
            brick_remain.add(a)
            i +=1
            
    

brick_destroy = N - len(brick_remain)
if brick_remain==[]:
    print(-1)
else:
    print(brick_destroy)

Submission status: Wrong Answer

Solution code:
#初期入力
N = int(input())
A = input().split() 
A_str ="".join(A)
#
i=0
i_index =0
brick_destroy =0
brick_remain =[]
while i <=N:
    i +=1 #探す「文字」
    A_now = A_str[i_index :] #見つけた字の右側のみ見る
    i_index += A_now.find(str(i) )
    #print((i,i_index),A_now,end=" ")
    if str(i) in A_now:
        if i_index ==-1 : 
            break
        else:
            brick_remain.append(i_index)
            if i_index >= N-1:
                break
            #print(brick_destroy)
            #print(i,end=" ")
    else:
        break

brick_destroy = N - len(brick_remain)
if brick_remain==[]:
    print(-1)
else:
    print(brick_destroy)

Submission status: Wrong Answer

Solution code:
#初期入力
N = int(input())
A = input().split() 
A_str ="".join(A)
#
i=0
i_index =0
brick_destroy =0
brick_remain =[]
while i <=N:
    i +=1 #探す「文字」
    A_now = A_str[i_index :] #見つけた字の右側のみ見る
    i_index += A_now.find(str(i) )
    #print((i,i_index),A_now,end=" ")
    if "1" in A_str:
        if i_index ==-1 : 
            break
        else:
            brick_remain.append(i_index)
            if i_index >= N-1:
                break
            #print(brick_destroy)
            #print(i,end=" ")
    else:
        break

brick_destroy = N - len(brick_remain)
if brick_remain==[]:
    print(-1)
else:
    print(brick_destroy)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
s = 1
for i in range(n):
    if a[i] != s:
        a.strip(a[i])
    else:
        s += 1
print(n-s)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
ans=0
c=1
for i in a:
  if a==c:
    c+=1
  else:
    ans+=1
    
if c==1:
  ans=-1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split(" ")]

now = 1
ans = 0
for i in A:
    if i == now:
        now += 1
    else:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
num = 1
ans = 0
for i in range(n):
  if A[i] == num:
    num += 1
    ans += 1
print(n-ans)

Submission status: Wrong Answer

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

i = 1
j = 0
cnt = 0
while j <= N-1:
    if i == A[j]:
        i += 1
        j += 1
    else:
        j += 1
        cnt += 1
    
print(cnt if cnt < N-1 else "-1")

Submission status: Wrong Answer

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

cnt = 0
for i in range(1, N):
    for j in range(N):
        if i == A[j]:
            break
        else:
            cnt += 1

print(cnt if cnt < N else -1)

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
a = list(map(int, input().split()))
if 1 in a:
    count = 0
    num = 1
    for i in a:
        if num == i:
            num += 1
        else:
            count += 1
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

change = False
ans = 0
re = 0

for i in range(N):
    if A[i]==1:
        re += 1
        change = True
    elif A[i]==re+1:
        re += 1
    else:
        ans += 1

if change == True:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

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

change = False
ans = 0
re = 0

for i in range(N):
    if A[i]==1:
        re += 1
        change = True
    elif A[i]==re+1:
        re += 1
    else:
        ans += 1

if change == True:
    print(ans)
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
n = int(input())
a_inputs = [int(i) for i in input().split()]

a_only = list(set(a_inputs))

ans=0
count=0
for i in range(len(a_inputs)):
    if a_inputs[i]==(count+1):
        count+=1
        continue
    else:
        ans+=1

if a_inputs==a_only:
    print(0)
if 1 not in a_inputs:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# ABC148D - Brick Break

import bisect

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

ans=0
for i in a:
    if ans+1==i:
        ans=i

print(ans)
if ans:
    print(n-ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# ABC148D - Brick Break

import bisect

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

inf = 10**9
dp=[inf]*(n+1)
dp[0]=0

for i in range(n):
    j=bisect.bisect_left(dp,a[i])
    if dp[j-1]==a[i]-1:
        dp[j]=a[i]

for i in range(n):
    if dp[i+1]==inf:
        break
    
#print(dp)
#print(i)
if i==0:
    print(-1)
else:
    print(n-i)

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())

  i = 1
  for a_i in input().split():
    if i == int(a_i):
      i += 1
  
  print(n - i + 1)


if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

b = sorted(set(a))
len_a = len(a)
len_b = len(b)
ans = len_a - len_b

for i in range(len_b - 2):
    if b[i+1] - b[1] != 1:
        print(-1)
        break
else:
    print(ans)

Submission status: Wrong Answer

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

b = sorted(set(a))
len_a = len(a)
len_b = len(b)
ans = len_a - len_b

if sum(b) == sum(range(1, len_b + 1)):
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

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

b = sorted(set(a))
len_a = len(a)
len_b = len(b)
ans = len_a - len_b

if b[0] != 1:
    print(-1) 
elif b[0] == 1 and b[len_b-1] == len_b:
    print(ans)

Submission status: Wrong Answer

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

ans = len(a) - len(set(a))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
lis = list(map(int,input().split()))
cnt = 0
i = 1
j = 1
p = 0
for k in range(1,N+1):
    if lis[k-1] == 1:
        p += 1
if p == 0:
    print(-1)
else:
    while True:
        if j == N:break
        while True:
            if j == N:break
            if lis[j-1] == i:
                i += 1
                j += 1
                break
            else:
                j += 1
                cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
lis = list(map(int,input().split()))
cnt = 0
i = 1
j = 1
p = 0
for k in range(1,N+1):
    if lis[k-1] == 1:
        p += 1
if p == 0:
    print(-1)
else:
    while True:
        if j == N:break
        while True:
            if j == N:break
            if lis[j-1] == i:
                i += 1
                j += 1
                break
            else:
                j += 1
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
lis = list(map(int,input().split()))
cnt = 0
p = 0
i = 1
j = 1
while True:
    if j == N:break
    while True:
        if j == N:break
        if lis[j-1] == i:
            i += 1
            j += 1
            p = 1
            break
        else:
            j += 1
            cnt += 1
if p != 0:
    print(cnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
alis = list(map(int, input().split()))
good = ''
m = 1
for i in alis:
    if i == m:
        good += str(i)
        m += 1
print(n - len(good) if len(good) > 0 else -1)

Submission status: Wrong Answer

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

now = 1
for ai in a:
    if ai == now:
        now += 1

if now == 1:
    print(-1)
else:
    print(N - now + 2)

Submission status: Wrong Answer

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

now = 1
for ai in a:
    if ai == now:
        now += 1
print(N - now + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 1
for i in a:
  if i == cnt:
    cnt += 1
print(n - cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
i = 0
num = 1
cnt = 0
while i <=n-1:
    if L[i] == num:
        num +=1 
    else:
        cnt +=1
    i+= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
j = 0
for ai in a:
    if ai == j + 1:
        j += 1
print(n - j)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

try:
  position1 = li.index(1)        
except:
  print(-1)
  exit()  
  
kowasu = position1
target = 2
position = position1 + 1
while True:
  flag = False
  for i in range(position, len(li)):
    if li[i] == target:
      flag = True
      kowasu += i - position
#      print(kowasu)
#      print(i)
      tekito = i
      break
  if flag:
    target += 1
    if tekito == len(li) - 1:
      break
    position = tekito + 1
  else:
    print(position)
    kowasu += len(li) - position
    break
print(kowasu)

Submission status: Wrong Answer

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

try:
  position1 = li.index(1)        
except:
  print(-1)
  exit()  
  
kowasu = position1
target = 2
position = position1 + 1
while True:
  flag = False
  for i in range(position, len(li)):
    if li[i] == target:
      flag = True
      kowasu += i - position
#      print(kowasu)
#      print(i)
      tekito = i
      break
  if flag:
    target += 1
    if tekito == len(li) - 1:
      break
    position = tekito + 1
  else:
    kowasu += len(li) - position - 1
    break
print(kowasu)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 初期入力
N = int(input())
#A = list(map(int, input().split()))
A = list(map(int, input().split()))
#　1の左側は砕く、以降数字が大きくなるほど右側にあればいいが、順番が違うと砕く必要あり。
from copy import deepcopy
x = 0
y =0
z = []
current =1
for i in A:
    if i == current:
        y = A.index(i ) 
        z.append(y)
        current +=1
        #z +=1
        #x += y
        #if y==0:
        #   break

    else:
        y = -1
        #break
#
renga_kudaku = 0
if z ==0 and y==-1:
    renga_kudaku = -1
elif z ==0:
    renga_kudaku = 0
else:
    renga_kudaku=N-len(z) # 求める物＝全体ー残る要素数、zは残る文字の配列
print(renga_kudaku)

Submission status: Wrong Answer

Solution code:
# 初期入力
N = int(input())
#A = list(map(int, input().split()))
A = list(map(int, input().split()))
#　1の左側は砕く、以降数字が大きくなるほど右側にあればいいが、順番が違うと砕く必要あり。
from copy import deepcopy
x = 0
y =0
z = []
for i in range(1,N+1):
    if i in A[x:]:
        y = A[x:].index(i ) 
        z.append(y)
        x += y
        if y==0:
            break

    else:
        y = -1
        break
#
renga_kudaku = 0
if len(z) ==0 and y==-1:
    renga_kudaku = -1
elif len(z) ==0:
    renga_kudaku = 0
else:
    renga_kudaku=N-len(z) # zは残る文字の配列、全体ー残る要素数
    #renga_kudaku=sum(z)-len(z) +1 +(len(A)-1) # 1の左側はリストの「０」あるので＋１、len(B)-1=最後の「B]の右側の文字数
print(renga_kudaku)

Submission status: Wrong Answer

Solution code:
# 初期入力
N = int(input())
#A = list(map(int, input().split()))
A = list(map(str, input().split()))

#　1の左側は砕く、以降数字が大きくなるほど右側にあればいいが、順番が違うと砕く必要あり。
from copy import deepcopy
#B =deepcopy(A)
B = "".join(A)
x = 0
y =0
z = []
for i in range(1,N+1):
    y = B.rfind(str(i) ) 
    if y ==-1:
        break
    else:
        z.append(y)
        x = y
        B_list =[i for i in B] # 文字を消すために文字→リスト
        del B_list[:x] 
        B ="".join(B_list) # 再度リスト→文字（・・・悲しい作業）

#
renga_kudaku = 0
if len(z) ==0 and y==-1:
    renga_kudaku = -1
elif len(z) ==0:
    renga_kudaku = 0
else:
    renga_kudaku=sum(z)-len(z) +1 +(len(B)-1) # 1の左側はリストの「０」あるので＋１、len(B)-1=最後の「B]の右側の文字数
print(renga_kudaku)