TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
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))

N = int(input())
A = list(input().split())
B = ''.join(A)
K = len(set(B))
i = 1
a = 0
b = []
while i < min(N+1,K):
    j = B.find(str(i))
    if j == -1:
        break
    a += j+1
    b.append(a)
    B = B[j+1:]
    if a == N:
        break
    i += 1
    
if b == []:
    print(-1)
else:
    print(N-len(b))

N = int(input())
A = list(map(int,input().split()))
c = 0
for a in A:
    if a == c + 1:
        c = a
    
if c == 0:
    print(-1)
else:
    print(N-c)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)
    

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+((n-1)-lo))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
input()
bs = list(map(int,input().split()))

def f(bs):
        print(bs)
        if bs == []:
            return 0
        elif bs[0] == 1:
            if len(bs) == 1:
                return 0
            else:
                return int(f([x-1 for x in bs][1:]))
        else:
            return int(1 + f([x for x in bs][1:]))

if 1 not in bs:
    print(-1)
else:
    print(f(bs))

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

if 1 not in bs:
    print(-1)
else:
    def f(bs):
        print(bs)
        if bs[0] == 1:
            if len(bs) == 1:
                return 0
            else:
                return f([x-1 for x in bs][1:])
        else:
            return 1 + f([x for x in bs][1:])

    print(f(bs))

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

out = 0
num = 1
for A in As:
    if  A == num:
        num += 1
    else:
        out += 1
if out == n:
    print(-1)
else:
    print(out)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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==n:
    count=-1
print(count)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
class Stack:
  def __init__(self):
    self.count = 1
    self.lst = []
  
  def push(self, element):
    if element == count:
      self.lst.append(element)
      self.count += 1
  
  def length(self):
    return len(self.lst)

n = int(input())
a = list(map(int, input().split()))
stack = Stack()
for i in a:
  stack.push(i)

b = stack.length()
if b == 0:
  print('-1')
else:
  print(n - b)

class Stack:
  def __init__(self):
    self.count = 1
    self.lst = []
  
  def push(self, element):
    if element == self.count:
      self.lst.append(element)
      self.count += 1
  
  def length(self):
    return len(self.lst)

n = int(input())
a = list(map(int, input().split()))
stack = Stack()
for i in a:
  stack.push(i)

b = stack.length()
if b == 0:
  print('-1')
else:
  print(n - b)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
a_list = [int(x) for x in input().split()]
del_list = []
cr = 1
num = 0
for i in range(N):
  if a_list[i] > i+1:
    a_list[i] = -1
print(a_list)
for i in range(N):
  if a_list[i] == -1:
    num += 1
    continue
  if a_list[i] != cr:
    a_list[i] = -1
    continue
  cr+=1

l = [x for x in a_list if x == -1]
print(len(l))

N = int(input())
a_list = [int(x) for x in input().split()]
del_list = []
cr = 1
num = 0
for i in range(N):
  if a_list[i] > i+1:
    a_list[i] = -1
for i in range(N):
  if a_list[i] == -1:
    num += 1
    continue
  if a_list[i] != cr:
    a_list[i] = -1
    continue
  cr+=1

l = [x for x in a_list if x == -1]
if len(l) == N:
  print("-1")
else:
  print(len(l))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
an = list(map(int,input().split()))

c = 1
cp = 0

for i in N:
  ai = an[i]
  if ai != c:
    cp += 1
    
  elif ai == c:
    c += 1
    
print(cp)

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

c = 1
cp = 0

for i in range(N):
  ai = an[i]
  if ai != c:
    cp += 1
    
  elif ai == c:
    c += 1
    
if N == cp:
    cp = -1

print(cp)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))

if 1 not in a:
  print("-1")
  exit()
else:
  nokosu = 1
  a=a[a.index(1)+1:]

for i in range(2,n):
  if i not in a:
    print(n - nokosu)
    exit()
  else:
    nokosu += 1
    if len(a)==1:
      print(nokosu)
      exit()
    a = a[a.index(i)+1:]

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

if a == [1]:
  print(0)
  exit()

if 1 not in a:
  print("-1")
  exit()
  
a=a[a.index(1):]

for i in range(2,n):
  if i not in a:
    print(n-i+1)
    exit()
  else:
    a=a[a.index(i):]
print(0)

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

if 1 not in a:
    print(-1)
    exit()

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


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
test = ""
test = \
"""
1
1
"""
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
    

n = int(input2())
nums = list(map(int, input2().strip().split()))
nums.reverse()

ans = 0
wanted = 1
while nums:
    tmp = nums.pop()
    if tmp == wanted:
        wanted += 1
    else:
        ans += 1

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

test = ""
#test = \
"""
1
1
"""
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
    

n = int(input2())
nums = list(map(int, input2().strip().split()))
nums.reverse()

ans = 0
wanted = 1
while nums:
    tmp = nums.pop()
    if tmp == wanted:
        wanted += 1
    else:
        ans += 1

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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))
    
       

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))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
if N % 2 == 1:
    print(0)
else:
    cnt = 0
    while N > 0:
        cnt += N // 5
        N //= 5
    print(cnt)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
n=int(input())
a=list(map(int,input().split()))

purged_data = [] 
tmp = a[0] - 1
s=1
for i, e in enumerate(a):
    if e==s:
        purged_data.append(e)
        tmp = e
        s+=1
for i in range(len(purged_data)):
    if purged_data[i]!=i+1:
        print(-1)
        sys.exit()
if len(purged_data)==0:
    print(-1)
    sys.exit()
print(len(a)-len(purged_data),purged_data)

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

purged_data = [] 
tmp = a[0] - 1
s=1
for i, e in enumerate(a):
    if e==s:
        purged_data.append(e)
        tmp = e
        s+=1
for i in range(len(purged_data)):
    if purged_data[i]!=i+1:
        print(-1)
        sys.exit()
if len(purged_data)==0:
    print(-1)
    sys.exit()
print(len(a)-len(purged_data))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    buffer=[0]
    for i in range(1,n+1):
        search_range=numbers[i-1:]
        if 1 not in search_range:
            print(-1)
            exit()
        elif i not in search_range:
            break
        else:
            index=search_range.index(i)
            buffer.append(index-sum(buffer))
    print(sum(buffer))

if __name__=="__main__":
    main()

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main2():
    numbers=[]
    N = int(input())
    numbers=list(map(int,input().split()))
    n=1


    for x in numbers:
        if x ==n:
            n+=1


    answer = N - n +1

    if answer==N:
        answer=-1
    print(answer)

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    buffer=[0]
    for i in range(1,n+1):
        search_range=numbers[i-1:]
        out_range=len(numbers[:i-1])
        if i not in search_range and len(buffer)==1:
            print(-1)
            exit()
        elif i not in search_range or i==n:
            break
        else:
            index=search_range.index(i)
            buffer.append(index-sum(buffer))
    print(sum(buffer))

if __name__=="__main__":
    main2()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-08-30 14:25:42 +0900
# LastModified: 2020-08-30 14:33:11 +0900
#


import os
import sys
# import numpy as np



def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 1 in A:
        print(-1)
        return
    index = 0
    for a in A:
        if index+1 == a:
            index += 1
    print(N-index)


if __name__ == "__main__":
    main()


#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-08-30 14:25:42 +0900
# LastModified: 2020-08-30 14:34:10 +0900
#


import os
import sys
# import numpy as np



def main():
    N = int(input())
    A = list(map(int, input().split()))
    if not 1 in A:
        print(-1)
        return
    index = 0
    for a in A:
        if index+1 == a:
            index += 1
    print(N-index)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)



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

cnt = 0


for i in range(1,N-1):

    if i == 0:
        continue
    elif i == int(s[i]):
        continue
    else:
       #s.pop(i-1)
       cnt = cnt + 1

print(cnt)


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

cnt = 0
flag = -1

for i in range(0,N):

    if i == 0:
        continue
    elif i == int(s[i]):
        continue
    else:
       #s.pop(i-1)
       cnt = cnt + 1
       flag = 1

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


N = int(input())
A = list(map(int,input().split()))
k = 0
for a in A:
    if k+1==a:
        k+=1
print(-1 if k==0 else N-k)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    index = 0
    while index < len(a):
        if not index in a:
            break
        if a[index] - 1 != index:
            a.remove(a[index])
            ans += 1
        else:
            index += 1
    return ans if ans != N else -1


if __name__ == "__main__":
    print(main())


import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    look = 1
    current = 0
    while current < len(a) - 1:
        for i, j in enumerate(a[current:]):
            if j == look:
                print(i)
                ans += i
                current += i+1
                break
        look += 1
        # print(look, current, ans)
    return ans


if __name__ == "__main__":
    print(main())


import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    look = 1
    for i in a:
        if look == i:
            look += 1
        else:
            ans += 1

    return ans if ans != N else -1


if __name__ == "__main__":
    print(main())


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())

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

def myindex(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

for i in range(1, n+1):
  b = myindex(a, i, default=-1)
  print(b)
  if b == -1:
    del a[(i-1):]
    break
  else:
    del a[(i-1):b]


if len(a) == 0:
  print('-1')

else:
  print(n - len(a))

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

card = 1
cnt = 0

for i in a:
  if i == card:
    card += 1
  else:
    cnt += 1

if cnt == n:
  print('-1')

else:
  print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a = int(input())
b = list(map(int,input().split()))
c = 1
ans = 0
for i in range b:
    if i == c:
        c += 1
    else:
        ans += 1
if ans == a:
    ans = -1
print(ans)

a = int(input())
b = list(map(int,input().split()))
c = 1
ans = 0
for i in b:
    if i == c:
        c += 1
    else:
        ans += 1
if ans == a:
    ans = -1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=map(int,input().split())
i=1
for k in a:
  if k==i: i+=1
print(N-i+1 if i>1 else -1)

n=int(input())
a=map(int,input().split())
i=1
for k in a:
  if k==i: i+=1
1-=1
print(N-i if i>0 else -1)

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

n=int(input())
a=map(int,input().split())
i=1
for k in a:
  if k==i: i+=1
print(N-i+1 if i>1 else -1)

n=int(input())
a=map(int,input().split())
i=1
for k in a:
  if k==i: i+=1
print(n-i+1 if i>1 else -1)


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import deque
n = int(input())
a = deque([int(i) for i in input().split()])
count = 1
while a:
    try:
        index = a.index(count)
        count += 1
        a = a[index:]
    except ValueError:
        if count == 1:
            ans = -1
        else:
            ans = n - (count - 1)
        a = []
print(ans)

n = int(input())
a = [int(i) for i in input().split()]
count = 0
for i in range(n):
    if a[i] == count + 1:
        count += 1
print(n - count if count else -1)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)
  

     
      
      

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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
data = []
ans = -1
value = 1
for i in range(n):
  if i == value:
    data.append(value)
  value += 1
#print(data)
if len(a) - len(data) == len(a):
  print('-1')
else:
  print(len(a) - len(data))

n = int(input())
a = list(map(int, input().split()))
data = []
ans = -1
value = 1
for i in range(n):
  if a[i] == value:
    data.append(value)
    value += 1
  #print(value)
#print(data)
if len(a) - len(data) == len(a):
  print('-1')
else:
  print(len(a) - len(data))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split())
s = 0
for i in range (n) :
    if a[i] = s + 1 :
        s += 1
print(n - s)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
a = list(map(int, input().split()))
idx = 1
cnt = 0
for i in a:
  if i == idx:
    idx += 1
    continue
  cnt += 1
if idx == 1:
  cnt = -1
print(cnt)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))

ans = 1

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

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

ans = 0

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



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
### -*- 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))

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

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

hitting = 1
for num in nums:
    if num == str(hitting):
        hitting += 1

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

n = int(input())
A = list(map(int, input().split()))
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)
        


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):


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

a.insert(0,0)

i = 0
ans = 0

while True:
  if i == a[0]:
    i += 1
    
    if i == len(a) -1:
      break
  else:
    a = a[1:]
    ans += 1
    if len(a) == 0:
      ans = -1
      break

print(ans)





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

t = 1
ans = 0

for i in range(n):
  if a[i] == t:
    t += 1
  else:
    ans += 1

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




Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N =int(input())
a =map(int,input())
count = 1
ans = 0
for i in a:
  if i == count:
    count += 1
    ans += 1
if ans == 0:
  print(-1)
else:
  print(min(N - 1, N - ans))

N =int(input())
a =int(input())
count = 1
ans = 0
for i in a:
  if i == count:
    count += 1
    ans += 1
if ans == 0:
  print(-1)
else:
  print(min(N - 1, N - ans))

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

for i in range(N):
  if j == a[i]:
    j += 1
if j == 1:
  print(-1)
else:
  print(N-j+1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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
if ans = 0:
  print("-1")
else:
print(n-ans)

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
if ans == 0:
  print("-1")
else:
print(n-ans)

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
if ans == 0:
  print("-1")
else:
  print(n-ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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

    if not 1 in an:
        print('-1')
        return

    count = 1
    for a in an:
        if a == count:
            count += 1
    print(N - count + 1)

main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
a = list(map(int, input().split()))
count = 1
broke = 0
while True:
    if count in a:
        print(a.index(count))
        broke += a.index(count)
        a = a[a.index(count) + 1:]
        count += 1
    else:
        break
if broke == 0:
    print(-1)
else:
    print(broke)


N = int(input())
a = list(map(int, input().split()))
count = 1
broke = 0

if 1 not in a:
    print(-1)
    exit()

for x in range(N):
    if a[x] == count:
        count += 1

print(N - count + 1)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:33:03 2020

@author: shinba
"""


n = int(input())
a = list(map(input().split()))
cnt = 0
st = 1
for i in range(n):
    if a[i] == st:
        st += 1
    else:
        cnt += 1

if 1 in a:
    print(cnt)
else:
    print(-1)
    
    

# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:33:03 2020

@author: shinba
"""


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

if 1 in a:
    print(cnt)
else:
    print(-1)
    
    

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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:
	print(n-count)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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

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)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# coding: utf-8
n = int(input())
renga_list = list(map(int, input().split()))

tmp = 0
for i in renga_list:
  tmp = i
 


# coding: utf-8
n = int(input())
renga_list = list(map(int, input().split()))


i = 1

for renga in renga_list:
    if i == renga:
        i += 1
        
result = n - i + 1
if n == result:
    print(-1)
else:
    print(result)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

n = int(input())
*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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

n = int(input())
box = []
box.append(list(map(int, input().split())))
box1 = box[0]  
tibi = min(box1)
ans = 0


if tibi!=1:
  print(-1)
else:
  iti = func1(box1, 1)
  iti_left = min(iti)
  ans += (iti_left + 1)
  del box1[:iti_left]
  num = 0
  for i in range(len(box1)):
    if box1[i]==(num+1):
      num += 1
      continue
    else:
      ans += 1
      
print(ans)

n = int(input())
box = []
box.append(list(map(int, input().split())))
box1 = box[0]  
tibi = min(box1)
ans = 0


if tibi!=1:
  print(-1)
else:
  num = 0
  for i in range(len(box1)):
    if box1[i]==(num+1):
      num += 1
      continue
    else:
      ans += 1
  print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

	print(n - cnt + 1)

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

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

	print(n - cnt + 1)

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

if not 1 in a:
    print(-1)
else:
    cnt = 1
    for i in range(n):
        if a[i] == cnt:
            cnt += 1

    print(n - cnt + 1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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 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)

from collections import deque
N = int(input())
A = deque(map(int, input().split()))
num = 1
ans = 0
while A:
  a = A.popleft()
  if a == num:
    num += 1
  else:
    ans += 1
print(-1 if num == 1 else ans)

Verdicts: Wrong Answer

Runtime Error

Accepted