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:
n = int(input())
a = [int(x) for x in input().split()]

place = []
isfail = False
if 1 not in a:
    isfail = True
if n == 1 and a[0] == 1:
    place.append(1)
elif n == 1 and a[0] != 1:
    isfail = True

for x in range(1, n):
    try:
        if x in a:
            place.append(a.index(x))
            a = a[a.index(x):]
        else:
            break
    except:
        isfail = True
        break

if isfail:
    print("-1")
else:
    print(n - len(place))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
K = 0
p = 0
bricks = [[] for i in range(N)] #iと書かれたレンガがどこにあるか

for i in range(N):
  bricks[a[i] - 1].append(i)
print(bricks)

for i in range(N):
  if len(bricks[i]) == 0:
    break
  elif bricks[i][-1] < p:
    break
  else:
    for j in bricks[i]:
      if j >= p:
        p = j
        K += 1
        break
if K == 0:
  print(-1)
else:
  print(N - K)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=len(a)
v=len(a)
c=0
for i in range(1,n):
  for j in range(n):
    if len(a)==0:
      break
    elif a[j]==i:
      del a[:j+1]
      c+=1
      break
    elif j+1==len(a):
      break
  if c!=i:
    break
print(b-c)

Submission status: Wrong Answer

Solution code:
class AC:
    @staticmethod
    def inputStr(char):
        return input().split(char)
    
    @staticmethod
    def inputInt(char):
        a = input().split(char)
        for i in range(len(a)):
            a[i] = int(a[i])
        return a

N  = int(input())
a = AC.inputInt(" ")

counter_1 = 1 #探す番号の指標
counter_2 = 0 #ループ用
delete = 0

while counter_1 != len(a):
    if a[counter_2] == counter_1:
        counter_1 = counter_1 + 1
        counter_2 = counter_1 - 1
    else:
        del a[counter_2]
        delete = delete + 1

if delete == N-1 and a[0] != 1 :
    delete = -1

print(delete)

Submission status: Wrong Answer

Solution code:
class AC:
    @staticmethod
    def inputStr(char):
        return input().split(char)
    
    @staticmethod
    def inputInt(char):
        a = input().split(char)
        for i in range(len(a)):
            a[i] = int(a[i])
        return a

N  = int(input())
a = AC.inputInt(" ")

counter_1 = 1 #探す番号の指標
counter_2 = 0 #ループ用
delete = 0

while counter_1 != len(a):
    if a[counter_2] == counter_1:
        counter_1 = counter_1 + 1
        counter_2 = counter_1 - 1
    else:
        del a[counter_2]
        delete = delete + 1

if delete == N-1 and a[0] != 0 :
    delete = -1

print(delete)

Submission status: Wrong Answer

Solution code:
class AC:
    @staticmethod
    def inputStr(char):
        return input().split(char)
    
    @staticmethod
    def inputInt(char):
        a = input().split(char)
        for i in range(len(a)):
            a[i] = int(a[i])
        return a

N  = int(input())
a = AC.inputInt(" ")

counter_1 = 1 #探す番号の指標
counter_2 = 0 #ループ用
delete = 0

while counter_1 != len(a):
    if a[counter_2] == counter_1:
        counter_1 = counter_1 + 1
        counter_2 = counter_1 - 1
    else:
        del a[counter_2]
        delete = delete + 1

print(delete)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
c = []
i=1
for k in range(N): 
    if a[k]==i:
        i += 1
    else:
        c.append(a[k])
if len(c)>= len(a):
    print(-1)
else:
    print(len(a)-len(c))

Submission status: Wrong Answer

Solution code:
N = int(input())
if N % 2 == 1:
    print(0)
else:
    cnt = 0
    while N > 0:
        cnt += N // 5
        N //= 5
    print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
#a=list(map(int,input().split()))
a=input()
nl=[x for x in range(1,n+1)]

if a!="1" and a.find("1 ")==-1:
  print(-1)
else:
  cnt=0
  for x in set(nl):
    t=a.find(str(x))
    if t == -1:
      print(n-cnt)
      break
    else:
      a=a[t+len(str(x)):]
      cnt+=1
  else:
    print(n-cnt)

Submission status: Wrong Answer

Solution code:
input1 = input()
input2 = input()
N = int(input1)
list_an = input2.split()
list_an = list(map(int,list_an))


list_an_sub = list(set(list_an))

result = 0

for i in range(len(list_an_sub) - 1):
    if list_an_sub[i] == list_an_sub[i + 1]:
        0
    else:
        result += 1
        

for a in range(result):
    if a+1 in list_an:
        del list_an[:list_an.index(a+1)]
    else:
        break

if len(list_an) == 1:
    print(N - list_an[0])
else:
    print(-1)

Submission status: Wrong Answer

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

pos=0
res=[]
for x in range(1,n+1):
  if a:
    t = a.index(x) if x in a else -1
    if t == -1:
      print(-1)
      break
    else:
      res.append(x)
      a=a[t+1:]
  else:
    continue
else:
  print(n-len(res))

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split()))
k = 1
lo = 0
ans = 0
for x in range(n):
    if ls[x] == k and k == 1:
        lo = x
        ans = x
        k += 1
    elif ls[x] == k:
        ans += x-1 - lo
        lo = x
        k += 1
    else:
        pass
if k == 1:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split()))
k = 1
lo = 0
ans = 0
for x in range(n):
    if ls[x] == k and k == 1:
        lo = x
        ans = x
        k += 1
        print(ans)
    elif ls[x] == k:
        ans += x-1 - lo
        lo = x
        k += 1
        print(x, lo, ans)
    else:
        pass
if k == 1:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
brick = [0]
number = 1

for i in range(N):
  if a[i] == number:
    brick.append(number)
    number += 1
print(N - max(brick))

Submission status: Wrong Answer

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

for i in range(N):
  if a[i] == number:
    for j in range(i):
      count += 1
      a.pop[number]
    number += 1
print(count)

Submission status: Wrong Answer

Solution code:
_ = input()
l = list(map(int, input().split()))

print(l)

br = 0
cn = 1
for i, n in enumerate(l):
	#print([i,n,cn])
	if n != cn:
		br += 1
	else:
		cn += 1
if br == len(l):
	print(-1)
else:
	print(br)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(s) for s in input().split()]
 
min_breaks = -1
 
count_num = 1
break_index = 1

for i in range(N):
  if nums[i] == count_num:
      if min_breaks == -1:
          min_breaks = 0
      min_breaks += ((i+1) - break_index)
      break_index = (i+2)
      count_num+=1
  
print(min_breaks)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(s) for s in input().split()]
 
min_breaks = -1
 
count_num = 1

for i in range(N):
  if nums[i] == count_num:
      if min_breaks == -1:
          min_breaks = 0
      min_breaks += ((i+1) - count_num)
      count_num+=1
  
print(min_breaks)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(s) for s in input().split()]
 
min_break = N
 
for i in range(N):
  check_num = (i+1) - nums[i]
  if check_num > 0 and check_num < min_break:
      min_break = check_num
      
      
if min_break < N:      
    print(min_break)
else:
    print(-1)

Submission status: Wrong Answer

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

min_break = N

for i in range(N):
  check_num = (i+1) - nums[i]
  if check_num > 0:
    if check_num < min_break:
      min_break = check_num

if min_break < N:      
    print(min_break)
else:
    print(-1)

Submission status: Wrong Answer

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

index = 0
broken = 0
while(True) :
    # print(li)
    if (index == len(li)-1) :
        if (li[index] == index+1) :
            print(broken)
            break
        else :
            print(-1)
            break

    if (li[index] == index+1) :
        index += 1
        continue
    
    del li[index]
    broken += 1

Submission status: Wrong Answer

Solution code:
#import sys
#sys.setrecursionlimit(10**7)
#from functools import reduce
#from fractions import gcd


# input
n = int(input())
alist = list(map(int, list(input().split())))

# process/output
if not 1 in alist:
    print(-1)

else:
    ans = 0
    i = 1
    while len(alist) > 0:
        if i in alist:
            index = alist.index(i)
            alist = alist[index+1:]
            ans += index
            i += 1
            
        else:
            break
        
    print(ans)

Submission status: Wrong Answer

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

n = ni()
a = nl()

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

if(shift==n-1):
  print(-1)
  exit()

print(shift)

Submission status: Wrong Answer

Solution code:
A = int(input())
B = list(map(int,input().split(" ")))
memory = 1
for i in range(A):
    if B[i] == memory:
        memory += 1
    else:
        continue
print(A-(memory-1))

Submission status: Wrong Answer

Solution code:
# ABC148D - Brick Break
def main():
    N, *A = map(int, open(0).read().split())
    remaining = 0
    cur = 0  # current index
    for target in range(1, N + 1):
        be_kept = False
        for i in range(cur, N):
            if A[i] == target:
                remaining += 1
                cur += 1
                be_kept = True
                break
        if not be_kept:
            break
    print(N - remaining if remaining else -1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def calc(a_list):
    if a_list == list(range(1, len(a_list) + 1)):
        print(0)
        return

    cond_idx = 0
    for num in range(1, len(a_list)):
        if num == 1:
            if num not in a_list:
                print(-1)
                return

        if num in a_list[cond_idx:]:
            cond_idx += a_list[cond_idx:].index(num)
    #         print(num, cond_idx)
        else:
#             print(num)
            print(n - num + 1)
            return
        
calc(a_list)

Submission status: Wrong Answer

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

if a_list == list(range(1, len(a_list) + 1)):
    print(0)

cond_idx = 0
for num in range(1, len(a_list)):
    if num == 1:
        if num not in a_list:
            print(-1)
            break
    
    if num in a_list[cond_idx:]:
        cond_idx += a_list[cond_idx:].index(num)
#         print(num, cond_idx)
    else:
        print(n - num + 1)
        break

Submission status: Wrong Answer

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

if a_list == list(range(1, len(a_list) + 1)):
    print(0)

cond_idx = 0
for num in range(1, len(a_list)):
    if num == 1:
        if num not in a_list:
            print(-1)
            break
    
    if num in a_list[cond_idx:]:
        cond_idx = a_list[cond_idx:].index(num)
#         print(num, cond_idx)
    else:
        print(n - num + 1)
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = list(map(str, input().split()))
ans_index = []
before_index = -1
for i in range(len(a_list)):
    a_list[i] = int(a_list[i])
for i in range(len(a_list)):
    val_list = a_list[before_index+1:]
    if val_list.count(i+1) >= 1:
        val = val_list.index(i+1) + before_index
        before_index = val
        ans_index.append(val+1)
    else:
        break

result = N - len(ans_index)
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = list(map(str, input().split()))
ans_index = []
before_index = -1
for i in range(len(a_list)):
    a_list[i] = int(a_list[i])
for i in range(len(a_list)):
    if (a_list.count(i+1) >= 1) and (a_list.index(i+1) > before_index):
        val = a_list.index(i+1)
        before_index = val
        ans_index.append(val)

result = N - len(ans_index)
print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())
lst= list(map(int, input().split()))
count=0
x=0
for i in range(1,len(lst)+1):
  for j in range(x,len(lst)):
    if lst[j]==i:
      count+=1
      x=j
      break
if count==0:
  print(-1)
else:
  print(N-count)

Submission status: Wrong Answer

Solution code:
def babble_sort(arr):
    length = len(arr)
    count = 0
    for i in range(length):
        for j in reversed(range(i+1, length)):
            if arr[j-1] > arr[j]:
                count += 1
                arr[j-1], arr[j] = arr[j], arr[j-1]
    print(count//2)
    return arr

N = int(input())
an = list(map(int, input().split(' ')))

count = 0
for i in range(N):
    left = an[i]
    for j in range(i, N):
        right = an[j]
        if left + 1 == right:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
def babble_sort(arr):
    length = len(arr)
    count = 0
    for i in range(length):
        for j in reversed(range(i+1, length)):
            if arr[j-1] > arr[j]:
                count += 1
                arr[j-1], arr[j] = arr[j], arr[j-1]
    print(count//2)
    return arr

N = int(input())
an = list(map(int, input().split(' ')))


babble_sort(an)

Submission status: Wrong Answer

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

cnt=1
for i in range(N):
  if Ar[i]==cnt:
    cnt+=1
print(N-cnt+1)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    i = 1
    flag = True
    for a in A:
        if a == 1:
            flag = False
            i += 1
    if flag:
        print(-1)
    else:
        print(max(len(A) - i, 0))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

c = 1
res = 0
for a in A :
    if c == a :
        c += 1
    else :
        res += 1

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
index = []
num = 1
tmp = 0
for i,a in enumerate(A):
    tmp += 1
    if a == num:
        index.append(i+1)
        num += 1
        tmp = 0
        continue
if num == 1:
    print(-1)
else:
    ans = index[0]-1
    for i in range(1, len(index)):
        ans += index[i] - index[i-1] - 1 + tmp
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input().split())

target_num = 1
for i in range(n):
  if target_num == int(l[i]):
    target_num += 1
    print('Good')
  else:
    target_num = target_num
    print('Bad')

if target_num == 1:
  print("-1")
else:
  print(n - target_num +1)

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(n):
    if a[i] == 1:
        del a[:i]
        l = 0
        m = 2
        i = 0

        while True:
            if l == len(a):
                print(n-len(a))
                break
            
            elif a[l] == m:
                del a[i+1:l]
                i = m-1
                l = 0
                m += 1

            else:
                l += 1
                
        break
    
    elif i == n-1 and a[i] != 1:
        print(-1)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.reverse()
cnt = 0
flag = a[0]

for i in range(1, n):
    if flag <= a[i]:
        cnt += 1
    else:
        flag = a[i]

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

Submission status: Wrong Answer

Solution code:
import sys
list = input().split()
dic = {}
res = {}
for i in list:
    dic[str(i)] = list.index(i) + 1
for i in range(len(list)):
    k = 0
    j = i + 1
    if str(j) in dic and dic[str(j)] > k:
        res[str(j)] =  dic[str(j)]
        k = dic[str(j)]
print(len(list) - len(res))

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  if a[i] == 1:
    break
  else:
    pass
else:
  print("-1")
  sys.exit()
j = 1
for i in range(n):
  if a[i] == j:
    j += 1
  else:
    pass
print(str(n-j-1))

Submission status: Wrong Answer

Solution code:
N = int(input())
bricks = list(map(int,input().split(" ")))
K=0
if 1 not in bricks:
    K = -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: Wrong Answer

Solution code:
input = [input() for i in range(2)]
n = int(input[0])
string = str(input[1]).strip()
a = list("".join(string.split()))

if(n > 200000):
  raise ValueError("n must be under 200000")

split_block_count = 0
end = False
for n_i in range(1, n + 1):
  for index, num in enumerate(a):
    if(n_i == int(num)):
      if(split_block_count == 0):
        split_block_count = index
        continue
      if(index == n - 1):
        end = True
      split_block_count = index - (n_i - 1)
      continue
    else:
      if(split_block_count == 0 and index == n - 1):
        split_block_count = -1
        break
      
  if(end == True or split_block_count == -1):
    break
    
print(split_block_count)

Submission status: Wrong Answer

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

ans = 0
chuumoku = 0
for i in range(n):
    try:
        index = a.index(chuumoku+1)
        ans += index - chuumoku
        del a[chuumoku:index]
        chuumoku += 1

    except ValueError:
        if ans == 0:
            print(-1)
        else:
            print(ans)
        exit(0)

Submission status: Wrong Answer

Solution code:
import collections
import bisect
N = int(input())
AL = list(map(int, input().split(" ")))

d = collections.defaultdict(list)
for index, num in enumerate(AL):
    d[num].append(index)

ans = 0
if not d[1]:
    print(-1)
else:
    current_pos = d[1][0]
    ans = 0
    for i in range(1, N+1):
        a = d[i+1]
        index = bisect.bisect_right(a, current_pos)
        if index != len(a):
            current_pos = a[index]
            continue
        else:
            ans = i
            break

print(N - ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = []
x = 0

for i in range(1,N+1):
    for j in range(x,N):
        if A[j] == i:
            x = j
            count.append(i)
            break

Answer = N - len(count)
if not 1 in A:
    Answer = -1
print(Answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
#= map(int,input().split())
a =list(map(int,input().split()))
# [list(map(int,input().split())) for i in range(N)]
counter = 1
for i in range(N):
    if a[i]==counter:
        counter +=1
if counter == N:
    print('-1')
else:
    print(N-counter+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
#= map(int,input().split())
a =list(map(int,input().split()))
# [list(map(int,input().split())) for i in range(N)]
counter = 1
for i in range(N):
    if a[i]==counter:
        counter +=1

print(N-counter+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if result == 0:
    print(-1)
else:
    print(result)

Submission status: Wrong Answer

Solution code:
import sys
#n, a = 3, "3 1 4 1 5 9 2 6 5 3".split(" ")
n, a = 3, "1".split(" ")
#n, a = input(), input().split(" ")
a = [int(i) for i in a]
if not (1 in a):
    print(-1)
    sys.exit(0)
r = 0
search = 1
while True:
    try:
        idx = a.index(search)
        a = a[idx+1:]
        r += idx
        search += 1
        #print(r, idx, search, a)
    except ValueError:
        break
print(r)
#print(r == 7)

Submission status: Wrong Answer

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

if x == 0:
    print(-1)
else:
    print(n - x)

Submission status: Wrong Answer

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

current = 1;

for i in a:
    if i == current:
        current += 1

print(N - (current - 1))

Submission status: Wrong Answer

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:]
    number += 1

print(count)

Submission status: Wrong Answer

Solution code:
def inp():
 return [int(x) for x in input().split()]

N = int(input())
a = inp()

n = 1
i = 0 

k = 0

while i<N:
  while i<N and a[i]!=n:
    i+=1
    k+=1
  i+=1
  n+=1
print(k)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int, input().split()))
if l == [i+1 for i in range(N)]: # 1, 2, 3, ...
  print(0)
elif len(set(l)) == 1:
  print(-1)
else:
  ans = 0
  for i in range(1, N+1):
    while len(l) != 0:
      if l[0] == i:
        l.pop(0)
        break
      else:
        ans += 1
        l.pop(0)
  if ans == N:      
  	print(-1)
  else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

for e in a:
  if e == (ans+1):
    ans += 1
    
print(n-ans)

Submission status: Wrong Answer

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

ans = 1

for e in a:
  if e == ans:
    ans += 1
    
print(n-ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

if n%2 or n < 10:
    print(0)
    exit()

ans = 0
cnt = 1
while 2*(5**cnt) <= n:
    ans += n//(2*(5**cnt))
    cnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_lst = [int(elem) for elem in input().split()]

def calc(num, lst):
  if num in lst:
    return lst.index(num), lst[lst.index(num)+1:]
  else:
    return 0, []

if not 1 in a_lst:
  print(-1)
else:
  num = 1
  res = 0
  while a_lst != []:
    tmp, a_lst = calc(num, a_lst)
    res += tmp
    num += 1
  print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_lst = [int(elem) for elem in input().split()]

def calc(num, lst):
  if num in lst:
    return lst[num:]
  else:
    return []

if not 1 in a_lst:
  print(-1)
else:
  num = 1
  while a_lst != []:
    if num in a_lst:
      a_lst = calc(num, a_lst)
      num += 1
    else:
      break
  print(n - num + 1)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = list(map(int,input().split()))
b = 1
count = 0
i = 0

while True:
    if i == len(a):
        if count == 0:
            print(-1)
        else:
            print(count)
        break

    elif a[i] == b:
        if i+1 == len(a) and i == 0:
            print(count)
            break
        else:
            a = a[i+1:]
            b += 1
            count += i
            i = 0

    else:
        i += 1

Submission status: Wrong Answer

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

if 1 not in li:
  print(-1)
elif li == [i for i in range(n)]:
  print(0)
else:
  for _ in range(n):
    try:
      count += 1
      i = li.index(count)
      li = li[i+1:]
    except ValueError:
      count -= 1
      break
  print(n - count + len(li))

Submission status: Wrong Answer

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

if 1 not in li:
  print(-1)
elif li == [i for i in range(n)]:
  print(0)
else:
  while li:
    try:
      count += 1
      i = li.index(count)
      li = li[i+1:]
    except ValueError:
      count -= 1
      break
  print(n - count + len(li))

Submission status: Wrong Answer

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

while li:
  try:
    count += 1
    i = li.index(count)
    li = li[i+1:]
  except ValueError:
    count = n + 1
    break

print(n - count)

Submission status: Wrong Answer

Solution code:
n = int(input())
z = input().split(" ")

look_for = 1
breaks = 0
for i in z:
    if int(i) == int(look_for):
        look_for += 1
        continue
    breaks += 1

print(breaks)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [int(s) for s in input().split()]
ini = 1
indData = []
for i in range(len(data)):
  if data[i] == ini:
    ini += 1
    indData.append(i)
ans = 0
if len(indData) == 1:
  if len(data) == 1:
    print(0)
    exit()
  else:
    print(1)
    exit()
if len(indData) == 0:
  print(-1)
  exit()
for i in range(len(indData)-1):
  ans += indData[i+1] - indData[i] -1

ans += indData[0]
print(ans)
#print(indData)

Submission status: Wrong Answer

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

sum = 0
counter = 1
left = 0

for i in range(left, n):
    if l[i] == counter:
        sum += i-left
        counter += 1
        left = i+1

if counter == 1:
    print(-1)
else:
    print(sum)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
tmp = input().split(" ")
x = list()
for i in tmp:
  x.append(int(i))
c = 0#HITした個数
for i in x:
  if c==(i+1):
    c+=1
print(n-c)

Submission status: Wrong Answer

Solution code:
n = int(input())
tmp = input().split(" ")
x = list()
for i in tmp:
  x.append(int(i))
c=0
for i in range(1,n):
  if i in x:#この数字を探す
    index = x.index(i)
    x = x[index+1:]
    c+=1
  else:
    break
print(n-c)

Submission status: Wrong Answer

Solution code:
def getdata_input():
    while True:
        yield input()

it=getdata_input()
N=int(next(it))
arr=[-1]*N
arr[0],*arr[1:]=map(int,next(it).split())
n=1
out=[]
i=-1
while True:
    try:
        i=arr.index(n,i+1)
        out.append(i)
        n+=1
    except ValueError:
        if(i<N-1):
            out.append(N)
        break
if len(out) ==0: 
    print(-1)
else:
    i,j=0,0
    total=0
    for x in out:
        j=x
        total+=(j-i)
        i=j+1
        
    print(total)

Submission status: Wrong Answer

Solution code:
def getdata_input():
    while True:
        yield input()
        
it=getdata_input()
N=int(next(it))
arr=[-1]*N
arr[0],*arr[1:]=map(int,next(it).split())
n=1
out=[]
i=N
arr2=arr[::-1]
while True:
    try:
        x=arr2.index(n,0,i)
        out.append(i-x-1)
        i=x
        n+=1
    except ValueError:
        break
if len(out) ==0: 
    print(-1)
else:        
    print(sum(out))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def getdata_input():
    while True:
        yield input()
        
it=getdata_input()
N=int(next(it))
arr=[-1]*N
arr[0],*arr[1:]=map(int,next(it).split())
n=1
out=[]
i=-1
while True:
    try:
        i=arr.index(n,i+1)
        out.append(i)
        n+=1
    except ValueError:
        break
if len(out) ==0: 
    print(-1)
else:
    i,j=0,0
    sum=0
    for x in out:
        j=x
        sum+=(j-i)
        i=j+1
    print(sum)

Submission status: Wrong Answer

Solution code:
def getdata_input():
    while True:
        yield input()
        
it=getdata_input()
N=int(next(it))
arr=[""]*N
arr[0],*arr[1:]=next(it).split()
s="".join(arr[::-1])
n=1
out=[]
while True:
    x=s.rfind(str(n))
    out.append(x)
    if x == -1:
        break
    n+=1
    s=s[:x]
if (out[-1]==-1):
    out.pop()
if(len(out)==0):
    print(-1)
else:
    print(N-len(out))

Submission status: Wrong Answer

Solution code:
# データ読み込み

import sys
from collections import deque

def input_data(d=""):
  t = sys.stdin.read()
  if t:
    return t
  else:
    if d[0] == "\n":
      d = d[1:]
    if d[-1] == "\n":
      d = d[:-1]    
    return d

A, *B  = map(int,input_data().split())

m = []

if 1 not in B:
  print(-1)
out = 0
c = 1
for i in B:
  if i == c:
    c+=1
  else:
    out+=1
print(out)