ZhenlongDai/ACPR huggingface dataset:
Problem: p03346
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
p = [I() for _ in range(n)]
dp = [inf]*n
for i in range(n):
    r = br(dp,p[i])
    dp[r] = p[i]
print(dp.count(inf) + 1)


Failing test case input:
8
6
3
2
1
7
4
8
5

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
p = [I() for _ in range(n)]
inde = [0]*n
for i in range(n):
    inde[p[i]-1] = i
cnt = 1
ans = 0
for i in range(1,n):
    if inde[i-1] < inde[i]:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 1
ans = max(ans,cnt)
ans = n - ans
print(ans)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [0]*N
cnt = 0
dic = {}
for i in range(N):
	a[i] = int(input())
	dic[a[i]] = i

ans = 1
cnt = 1
for num in range(1,N):
	if dic[num] < dic[num+1]:
		cnt += 1
	else:
		ans = max(cnt,ans)
		cnt = 1

if cnt != 1:
	ans = cnt
print(N-ans)




Failing test case input:
6
2
3
5
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
a = [0]*N
cnt = 0
dic = {}
for i in range(N):
	a[i] = int(input())
	dic[a[i]] = i

ans = 1
cnt = 1
for num in range(1,N):
	if dic[num] < dic[num+1]:
		cnt += 1
	else:
		ans = max(cnt,ans)
		cnt = 1


ans = max(cnt,ans)
print(N-ans)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = [int(input()) for _ in range(N)]
vi = {v: i for i, v in enumerate(P)}
before = float('inf')
for v in range(N, -1, -1):
    if v == 0 or vi[v] > before:
        break
    else:
        before = vi[v]
print(v)


Failing test case input:
6
2
5
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
P = [int(input()) for _ in range(N)]
vi = {v: i for i, v in enumerate(P)}
incmax = inc = 1
before = vi[1]
for v in range(2, N + 1):
    if vi[v] > before:
        inc += 1
    else:
        inc = 1
    incmax = max(incmax, inc)
    before = vi[v]
print(N - incmax)
Problem: p03346
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

n = int(input())
q = [0]*n
for i in range(n):
    p = int(input())-1
    q[p] = i
    
s=f=0
c = set()
for i in range(2,n):
    if q[i]<q[i-1]:
        f=i-1
        c.add(f-s+1)
        s=i
if c==set():
    print(0)
else:
    print(n-max(c))

Failing test case input:
6
5
2
3
1
4
6

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):

n = int(input())
q = [0]*n
for i in range(n):
    p = int(input())-1
    q[p] = i
    
s=f=0
c = set()
for i in range(1,n):
    if q[i]<q[i-1]:
        f=i-1
        c.add(f-s+1)
        s=i
if c==set():
    print(0)
else:
    print(n-max(c))

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = [int(input()) for i in range(N)]
is_earlier = [True] * (N+1)
is_earlier[-1] = False
appeared = set()
for p in P:
  if p+1 in appeared:
    is_earlier[p-1] = False
  appeared.add(p)

M = 0
now = 0
for i in range(N+1):
    if is_earlier[i]:
        now += 1
    else:
        M = max(M, now)
        now = 0

print(N - M)

Failing test case input:
6
2
5
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
P = [int(input()) for i in range(N)]
is_earlier = [True] * N
appeared = set()
appeared.add(N+1)
for p in P:
  if p+1 in appeared:
    is_earlier[p-1] = False
  appeared.add(p)

M = 0
now = 1
for i in range(N):
    if is_earlier[i]:
        now += 1
    else:
        M = max(M, now)
        now = 1

print(N - M)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
ls = [0]*(N+1)
for i in range(N):
  p = int(input())
  ls[p] = i
count = 0
for a in range(N,0,-1):
  if ls[a]>ls[a-1]:
    count += 1
  else:
    break
print(N-count-1)
  

Failing test case input:
8
6
3
1
2
5
4
8
7

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
N = int(input())
ls = [0]*(N+1)
for i in range(N):
  p = int(input())
  ls[p] = i
ID = -1
count = 0
ans = 0
for a in range(1,N):
  if ls[a+1]>ls[a]:
    count += 1
  else:
    if count>ans:
      ans = count
    count = 0
if count>ans:
  ans = count
print(N-ans-1)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [0]*N
cnt = 0
dic = {}
for i in range(N):
	a[i] = int(input())
	dic[a[i]] = i

ans = (-1)
cnt = 1
for num in range(1,N):
	if dic[num] < dic[num+1]:
		cnt += 1
	else:
		ans = max(cnt,ans)
		cnt = 1

print(N-cnt)




Failing test case input:
6
2
5
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
a = [0]*N
cnt = 0
dic = {}
for i in range(N):
	a[i] = int(input())
	dic[a[i]] = i

ans = 1
cnt = 1
for num in range(1,N):
	if dic[num] < dic[num+1]:
		cnt += 1
	else:
		ans = max(cnt,ans)
		cnt = 1


ans = max(cnt,ans)
print(N-ans)
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N=int(input())

P=[]
for _ in range(N):
    P.append(int(input())-1)
    


root=[-1]*N
count=[0]*N
for item in P:
    if item == 0:
        root[item]=item
        continue
    if root[item-1]==-1:
        root[item]=item
        count[root[item]]+=1
    else:
        root[item]=root[item-1]
        count[root[item]]+=1

print(N-max(count))


Failing test case input:
4
1
4
2
3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):


N=int(input())

P=[]
for _ in range(N):
    P.append(int(input())-1)
    


root=[-1]*N
count=[0]*N
for item in P:
    if item == 0:
        root[item]=item
        count[root[item]]+=1
        continue
    if root[item-1]==-1:
        root[item]=item
        count[root[item]]+=1
    else:
        root[item]=root[item-1]
        count[root[item]]+=1

print(N-max(count))

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = [0]
for i in range(N):
  P.append(int(input()))
Q = [0]*(N+1)
for i in range(1,N+1):
  Q[P[i]] = i
res = Q[1]
cnt = 0  
c = 1
for i in range(2,N+1):
  if res < Q[i]:
    c += 1
    res = Q[i]
  if i == N:
    cnt = max(cnt,c)
  else:
    cnt = max(cnt,c)
    c = 1
    res = Q[i]
print(N-cnt)      

Failing test case input:
6
2
3
5
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
P = [0]
for i in range(N):
  P.append(int(input()))
Q = [0]*(N+1)
for i in range(1,N+1):
  Q[P[i]] = i
res = Q[1]
cnt = 0  
c = 1
for i in range(2,N+1):
  if res < Q[i]:
    c += 1
    res = Q[i]
    if i == N:
      cnt = max(cnt,c)
  else:
    cnt = max(cnt,c)
    c = 1
    res = Q[i]
ans = N-cnt
if N ==1:
  ans = 0    
print(ans)

Problem: p03346
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    Q = [0]*N
    for i in range(N):
        Q[read_int()-1] = i
    max_k = 1
    k = 1
    for i in range(1, N):
        if Q[i] > Q[i-1]:
            k += 1
            max_k = max(max_k, k)
        else:
            k = 1
    return N-k


if __name__ == '__main__':
    print(solve())


Failing test case input:
4
1
4
2
3

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    Q = [0]*N
    for i in range(N):
        Q[read_int()-1] = i
    max_k = 1
    k = 1
    for i in range(1, N):
        if Q[i] > Q[i-1]:
            k += 1
            max_k = max(max_k, k)
        else:
            k = 1
    return N-max_k


if __name__ == '__main__':
    print(solve())
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
i = 1
while i < n:
    if p[i - 1] < p[i]:
        temp += 1
        i += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1
        i += 1
maxSet = max(maxSet, temp)
print(n - maxSet)


Failing test case input:
4
3
1
2
4

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
i = 2
while i <= n:
    if p[i - 1] < p[i]:
        temp += 1
        i += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1
        i += 1
maxSet = max(maxSet, temp)
print(n - maxSet)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
  
cnt1 = 0
wk = 1
for i in range(N):
  if A[i] == wk:
    wk += 1
    cnt1 += 1

cnt2 = 0
wk = N
for i in range(N):
  if A[N-i-1] == wk:
    wk -= 1
    cnt2 += 1
    
print(N-max(cnt1,cnt2))

Failing test case input:
6
5
2
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
P = []
for i in range(N):
  P.append(int(input()) - 1)

A = [0] * N
for i in range(N):
  A[P[i]] = i

ans,cnt = 0,0
work = -1
for i in range(N):
  if work < A[i]:
    cnt += 1
    ans = max(ans, cnt)
  else:
    cnt = 1
  work = A[i]

print(N-ans)

Problem: p03346
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
from collections import defaultdict

N = int(input())
P = [int(input()) for _ in range(N)]
idx = defaultdict(int)

for i in range(N):
    idx[P[i]] = i
    
dp = [0]*N

for i in range(N):
    dp[i] = dp[idx[P[i]-1]]+1

print(N-max(dp))

Failing test case input:
6
3
1
5
2
4
6

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
from collections import defaultdict

N = int(input())
P = [int(input()) for _ in range(N)]
idx = defaultdict(int)

for i in range(N):
    idx[P[i]] = i
    
dp = [0]*N

for i in range(N):
    if P[i]==1:
        dp[i] = 1
    else:
        dp[i] = dp[idx[P[i]-1]]+1
    
print(N-max(dp))

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = [int(input()) for _ in range(N)]
p_i = [0] * (N + 1)
for i, p in enumerate(P):
    p_i[p] = i
ans = now = 0
for i in range(N - 1):
    if p_i[i] < p_i[i + 1]:
        now += 1
    else:
        ans = max(ans, now)
        now = 0
print(N - 1 - max(ans, now))


Failing test case input:
4
3
1
2
4

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
P = [int(input()) for _ in range(N)]
vi = {v: i for i, v in enumerate(P)}
incmax = inc = 1
before = vi[1]
for v in range(2, N + 1):
    if vi[v] > before:
        inc += 1
    else:
        inc = 1
    incmax = max(incmax, inc)
    before = vi[v]
print(N - incmax)
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
d={}
for i in range(n):
  d[l[i]]=i+1
ans=0
ans1=1
index=1
while index<n:
  index+=1
  if d[index]>d[index-1]:
    ans1+=1
  else:
    if ans<ans1:
      ans=ans1
      ans1=1
if ans<ans1:
  ans=ans1
print(n-ans)

Failing test case input:
6
1
3
5
2
4
6

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
d={}
for i in range(n):
  d[l[i]]=i+1
ans=1
ans1=1
index=1
while index<n:
  index+=1
  if d[index]>d[index-1]:
    ans1+=1
  else:
    if ans<ans1:
      ans=ans1
    ans1=1
if ans<ans1:
  ans=ans1
print(n-ans)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

dp = [0]*(N+1)

for a in A:
    dp[a] += dp[a-1]+1
print(N-max(dp))


Failing test case input:
8
6
3
2
1
7
4
8
5

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
dp = [0]*(N+1)

for a in A:
    dp[a] += dp[a-1]+1
print(N-max(dp))

Problem: p03346
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
L = []
for i in range(N):
  L.append(int(input()))
TF = [False]*(N+1)
dp = [0]*(N+1)
for i in range(N):
  TF[L[i]] = True
  if TF[L[i]-1] == True:
    dp[L[i]] = dp[L[i]-1]+1
print(max(dp)+1)

Failing test case input:
6
1
3
5
2
4
6

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
L = []
for i in range(N):
  L.append(int(input()))
TF = [False]*(N+1)
dp = [0]*(N+1)
for i in range(N):
  TF[L[i]] = True
  if TF[L[i]-1] == True:
    dp[L[i]] = dp[L[i]-1]+1
print(N-max(dp)-1)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def main():
    n = int(input())
    p = [int(input()) for _ in range(n)]

    
    

    
    min_n = 1
    candidate1 = 0

    for i in range(n):
        if p[i] == min_n:
            min_n += 1
        else:
            candidate1 += 1

    
    max_n = n
    candidate2 = 0

    for i in range(n - 1, -1, -1):
        if p[i] == max_n:
            max_n -= 1
        else:
            candidate2 += 1

    print(min(candidate1, candidate2))


if __name__ == '__main__':
    main()


Failing test case input:
6
2
5
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):



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

    
    
    
    

    
    

    
    
    
    
    p = [0 for _ in range(n)]

    for i in range(n):
        x = int(input())
        x -= 1
        p[x] = i

    len_max = 1
    count = 1

    for i in range(1, n):
        if p[i] > p[i - 1]:
            count += 1
        else:
            count = 1

        len_max = max(len_max, count)

    print(n - len_max)


if __name__ == '__main__':
    main()
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
lis = [int(input()) for i in range(n)]
li = [-1 for i in range(n)]
for i in range(n):
    li[lis[i]-1] = i
cnt = 0
ans = n-1
for i in range(n-1):
    if li[i] > li[i+1]:
        cnt += 1
    else:
        ans = min(ans,n-1-cnt)
        cnt = 0
ans = min(ans,n-1-cnt)
print(ans)

Failing test case input:
6
2
5
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
lis = [int(input()) for i in range(n)]
li = [-1 for i in range(n)]
for i in range(n):
    li[lis[i]-1] = i
cnt = 0
ans = n-1
for i in range(n-1):
    if li[i] < li[i+1]:
        cnt += 1
    else:
        ans = min(ans,n-1-cnt)
        cnt = 0
ans = min(ans,n-1-cnt)
print(ans)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

p = []
for _ in range(n):
    p.append(int(input()))
    
p.reverse()
ans = n
check = n
for num in p:
    if num == check:
        ans -= 1
        check -= 1
print(ans)

Failing test case input:
4
2
4
1
3

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())

p = []
for _ in range(n):
    p.append(int(input()))
    
ans = [0 for _ in range(n + 1)]
for num in p:
    ans[num] = ans[num - 1] + 1
print(n - max(ans))

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = int(input())
    P = [0 for _ in range(N)]
    A = [i+1 for i in range(N)]
    for i in range(N):
        P[i] = int(input())
    count = [0 for _ in range(N)]
    C = 0
    for i in range(N):
        count[i] = A.index(P[i]) - i
        if count[i] > 0:
            C+=count[i]
    return C

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

Failing test case input:
6
1
3
5
2
4
6

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    P = [0 for _ in range(N)]
    for i in range(N):
        P[i] = int(input())
    C = [1,1]
    Q = [0 for _ in range(N)]
    for i in range(N):
        Q[P[i]-1] = i
    for i in range(1,N):
        if Q[i-1]<Q[i]:
            C[0]+=1
            C[1] = max(C[1], C[0])
        else:
            C[0] = 1
    print(N-C[1])

if __name__ == '__main__':
    main()
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = int(input())
    P = [int(input()) for _ in range(N)]

    
    editorial(N, P)


def editorial(N, P):
    
    if N == 1:
        print(0)
        return

    a = [0] * (N+1)
    for i, p in enumerate(P):
        a[p] = i

    tmp = 1
    max_len = 1
    for i in range(1, N):
        if a[i] < a[i+1]:
            tmp += 1
            max_len = max(max_len, tmp)
        else:
            tmp = 1
    ans = N - max_len
    print(ans)

Failing test case input:
6
5
2
3
1
4
6

Expected output:
3


Actual output:

Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    P = [int(input()) for _ in range(N)]

    
    editorial(N, P)


def editorial(N, P):
    
    if N == 1:
        print(0)
        return

    
    a = [0] * (N+1)
    for i, p in enumerate(P):
        a[p] = i

    tmp = 1
    max_len = 1
    for i in range(1, N):
        if a[i] < a[i+1]:
            tmp += 1
            max_len = max(max_len, tmp)
        else:
            tmp = 1
    ans = N - max_len
    print(ans)


def WA(N, P):
    tmp = 0
    ans = 0
    for i, p in enumerate(P):
        if i == 0 or P[i-1] + 1 == p:
            tmp += 1
        else:
            ans = max(ans, tmp)
            tmp = 1

    print(N - ans)


if __name__ == '__main__':
    main()

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[]
for i in range(n):
  x=int(input())
  a.append(x)
d={}
f=0
maxi=0
for i in range(n):
  if((a[i]-1) in d):
    d[a[i]]=d[a[i]-1]+1
    if(f==0):
      maxi=d[a[i]]
    else:
      if(d[a[i]]>maxi):
        maxi=d[a[i]]
  else:
    d[a[i]]=1

print(n-maxi)



Failing test case input:
6
2
3
5
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n=int(input())
a=[]
for i in range(n):
  x=int(input())
  a.append(x)
d={}
f=0
maxi=0
for i in range(n):
  if((a[i]-1) in d):
    d[a[i]]=d[a[i]-1]+1
  else:
    d[a[i]]=1

for i in d:
  if(i==0):
    maxi=d[i]
  else:
    if(d[i]>maxi):
      maxi=d[i]

print(n-maxi)

Problem: p03346
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
p = [0]*(n+1)

for i in range(n):
    m = int(input())
    p[m] = i

succ = [1] * (n+1)

for i in range(1,n):
    if p[i-1] < p[i]:
       succ[i] = succ[i-1] + 1

print(n-max(succ))

Failing test case input:
8
6
3
1
2
5
4
8
7

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
p = [0]*n
p2 = []
for i in range(n):
    m = int(input())
    p[m-1] = i
    p2.append(m)

succ = [1] * n

for i in range(1,n):
    if p[i-1] < p[i]:
       succ[i] = succ[i-1] + 1



print(n-max(succ))
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,*P=map(int,open(0))
ids=[0]*N
for i in range(N):
	ids[P[i]-1]=i
tmp=1
inc=1
for i in range(N-1):
	if ids[i]<ids[i+1]:
		tmp+=1
		inc=max(tmp,inc)
	else:
		tmp=1
print(N-tmp)

Failing test case input:
8
6
3
1
2
5
4
8
7

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
N,*P=map(int,open(0))
ids=[0]*N
for i in range(N):
	ids[P[i]-1]=i
tmp=inc=1
for i in range(N-1):
	if ids[i]<ids[i+1]:
		tmp+=1
		inc=max(tmp,inc)
	else:
		tmp=1
print(N-inc)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
for i in range(1, n):
    if p[i - 1] < p[i]:
        temp += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1
maxSet = max(maxSet, temp)
print(n - maxSet)


Failing test case input:
4
3
1
2
4

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
i = 2
while i <= n:
    if p[i - 1] < p[i]:
        temp += 1
        i += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1
        i += 1
maxSet = max(maxSet, temp)
print(n - maxSet)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
dp = [0]* (N)
for i in range(N):
  dp[int(input())-1] = i
ans = 0
cc = 0
for i in range(N-1):
  if dp[i] < dp[i+1]:
    cc += 1
  else:
    ans = max(cc, ans)
    cc = 0
ans = max(cc, ans)
print(N-ans+1)

Failing test case input:
8
6
3
2
1
5
4
8
7

Expected output:
6


Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
dp = [0]*N
for i in range(N):
  dp[int(input())-1] = i
ans = 0
cc = 0
for i in range(N-1):
  if dp[i] < dp[i+1]:
    cc += 1
  else:
    ans = max(cc, ans)
    cc = 0
ans = max(cc, ans)
print(N-ans-1)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
P=[]
for i in range(N):
    p=int(input())
    P.append(p)

l=[]
l.append(P[0])
cnt=0
for i in range(1,N):
    if P[i-1]<P[i]:
        l.append(P[i])
    else:
        cnt=max(cnt,len(l))
        l=[]
        l.append(P[i])

ans=N-cnt
print(ans)


Failing test case input:
4
3
1
2
4

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N=int(input())
P=[]
for i in range(N):
    p=int(input())
    P.append(p)
Q=[0]*N
for i in range(N):
    Q[P[i]-1]=i

cnt=1
ans=1
for i in range(N-1):
    if Q[i]<Q[i+1]:
        cnt+=1
    else:
        cnt=1
    ans=max(cnt,ans)

print(N-ans)
Problem: p03346
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


def main():
    n = int(input())
    pp = []
    for _ in range(n):
        pp.append(int(input()))
    dd = {}
    for i in range(n):
        dd[pp[i]] = i

    xx = [-1] * n
    for s in range(n - 1, -1, -1):
        if xx[s] >= 0:
            continue
        count = 1
        pre = pp[s]
        while pre + 1 in dd:
            i = dd[pre + 1]
            if xx[i] < 0:
                xx[s] = xx[i] + count
                break
            pre = pp[i]
            count += 1
        else:
            xx[s] = count
    print(n - max(xx))


if __name__ == '__main__':
    main()


Failing test case input:
6
3
1
5
2
4
6

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):


def main():
    n = int(input())
    pp = []
    for _ in range(n):
        pp.append(int(input()))
    dd = {}
    for i in range(n):
        dd[pp[i]] = i

    xx = [-1] * n
    for s in range(n - 1, -1, -1):
        if xx[s] >= 0:
            continue
        count = 1
        pre = pp[s]
        while pre + 1 in dd and dd[pre + 1] > s:
            i = dd[pre + 1]
            if xx[i] >= 0:
                xx[s] = xx[i] + count
                break
            pre += 1
            count += 1
        else:
            xx[s] = count
    print(n - max(xx))


if __name__ == '__main__':
    main()

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

Ps = [(int(input()), i) for i in range(N)]
Ps.sort()

print(Ps)

num = 0
ans = 0
for i in range(N - 1):
    if Ps[i][1] < Ps[i + 1][1]:
        num += 1
    else:
        ans = max(ans, num)
        num = 0
    
ans = max(ans, num)
print(N - ans - 1)


Failing test case input:
4
1
3
2
4

Expected output:
2

Actual output:
[(1, 0), (2, 2), (3, 1), (4, 3)]
2


Fixed submission (verdict: Accepted):
N = int(input())

Ps = [(int(input()), i) for i in range(N)]
Ps.sort()

num = 0
ans = 0
for i in range(N - 1):
    if Ps[i][1] < Ps[i + 1][1]:
        num += 1
    else:
        ans = max(ans, num)
        num = 0
    
ans = max(ans, num)
print(N - ans - 1)
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    P = [0] * N
    index = [0] * (N + 1)

    for i in range(N):
        P[i] = int(input())
        index[P[i]] = i

    length = 1
    seq = 1
    for i in range(N):
        if index[i] < index[i + 1]:
            seq += 1
        else:
            length = max(length, seq)
            seq = 1

    print(N - length)

sol()

Failing test case input:
6
3
1
5
2
4
6

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    P = [0] * N

    for i in range(N):
        P[i] = int(input())

    pToIndex = {p : i for i, p in enumerate(P)}

    maxLeng = 1
    length = 1
    for n in range(1, N):
        if pToIndex[n] < pToIndex[n + 1]:
            length += 1
            maxLeng = max(maxLeng, length)
        else:
            length = 1

    print(N - maxLeng)

sol()

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())

q=[-1]*N
for i in range(N):
    k = int(input())
    
    q[k-1]=i


max_con=1
count=0
for i in range(N-1):
    if q[i]<q[i+1]:
        count+=1
        max_con=max(max_con,count)
    else:
        count=1

print(N-max_con)


Failing test case input:
4
1
4
2
3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N=int(input())

q=[-1]*N
for i in range(N):
    k = int(input())
    
    q[k-1]=i


max_con=1
count=1
for i in range(N-1):
    if q[i]<q[i+1]:
        count+=1
        max_con=max(max_con,count)
    else:
        count=1

print(N-max_con)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N = int(input())
P = [int(input()) for _ in range(N)]
Q = [P.index(i) for i in range(1, N + 1)]

subset_num = 0
num = 0
for i in range(N-2):
    num += 1
    if Q[i] > Q[i+1]:
        subset_num = max(subset_num, num)
        num = 0
    if i == N-3:
        subset_num = max(subset_num, num)
print(N - subset_num)

Failing test case input:
4
2
4
1
3

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
Q = [0]*N
for i in range(N):
        Q[int(input())-1] = i

subset_num = num = 0
for i in range(N-1):
    num += 1
    if Q[i] > Q[i+1]:
        subset_num = max(subset_num, num)
        num = 0
else:
    num += 1   
    subset_num = max(subset_num, num)
print(N - subset_num)
Problem: p03346
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

n = int(input())
p = [int(input()) for i in range(n)]
a = 1
for i in p:
    if i == a:
        a += 1
b = 1
for i in p[::-1]:
    if i == n-b+1:
        b += 1
print(n-max(a,b)+1)


Failing test case input:
4
2
4
1
3

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):

n = int(input())
p = [int(input()) for i in range(n)]
f = [0]*(n+1)
m = [n-1]*(n+1)
for i in p:
    if f[i-1]:
        m[i] = m[i-1]-1
    f[i] = 1
print(min(m))

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = [int(input()) for _ in range(n)]

cnt = 0
first = p[0]
last = p[-1]
for i in range(n):
    if first > p[i]:
        cnt += 1
        first = p[i]
for i in range(n):
    if last < p[i]:
        cnt += 1
        last = p[i]

if p[0] == last:
    cnt += n - p[0] - 1
print(cnt)


Failing test case input:
8
6
5
2
1
3
4
8
7

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
p = [int(input()) for _ in range(n)]
q = [0] * (n+1)

for i in range(n):
    q[p[i]] = i
maxl = 1
cnt = 1
for i in range(1, n):
    if q[i+1] > q[i]:
        cnt += 1
    else:
        maxl = max(maxl, cnt)
        cnt = 1
print(n - max(maxl, cnt))

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N=int(input())
    P=[0]*N
    p=[False]*(N+1)
    P[0]=int(input())
    c=[False]*(N+1)
    for i in range(1,N):
        P[i]=int(input())
        c[P[i]]=True
        if c[P[i]-1]:
            p[P[i]-1] = True
    ans=0
    j=0
    for i in range(N):
        if p[i]:
            j+=1
        else:
            ans=max(ans,j)
            j=0
    ans=max(ans,j)
    print(N-ans-1)


if __name__ == "__main__":
    main()


Failing test case input:
6
2
5
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
def main():
    N=int(input())
    p=[False]*(N+1)
    c=[False]*(N+1)
    for i in range(N):
        x=int(input())
        c[x]=True
        if c[x-1]:
            p[x-1] = True
    ans=0
    j=0
    for i in range(1,N+1):
        if p[i]:
            j+=1
        else:
            ans=max(ans,j)
            j=0
    ans=max(ans,j)
    print(N-ans-1)

if __name__ == "__main__":
    main()

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
for i in range(1, n):
    if p[i - 1] < p[i]:
        temp += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1

print(n - maxSet)


Failing test case input:
4
1
4
2
3

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
i = 2
while i <= n:
    if p[i - 1] < p[i]:
        temp += 1
        i += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1
        i += 1
maxSet = max(maxSet, temp)
print(n - maxSet)
Problem: p03346
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    N = int(input())
    P = list(int(input()) for _ in range(N))
    
    dp = [0] * (N + 1)
    dp[N] = 1
    for i in range(N-1,-1,-1):
        if P[i] == N:
            continue
        if dp[P[i] + 1] == 0:
            dp[P[i]] = 1
        else:
            dp[P[i]] = dp[P[i] + 1] + 1

    print(N - max(dp))


if __name__ == "__main__":
    main()

Failing test case input:
8
6
3
2
1
5
4
8
7

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    P = list(int(input()) for _ in range(N))
    
    dp = [0] * (N + 1)
    for i in range(N-1,-1,-1):
        if P[i] == N:
            dp[P[i]] = 1
            continue
        if dp[P[i] + 1] == 0:
            dp[P[i]] = 1
        else:
            dp[P[i]] = dp[P[i] + 1] + 1
    print(N - max(dp))


if __name__ == "__main__":
    main()

Problem: p03346
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = []
for i in range(n):
    a.append(inn())
l = 0
for i in range(n):
    if a[i]==l+1:
        l += 1
r = n+1
for i in range(n-1,-1,-1):
    if a[i]==r-1:
        r -= 1
print(min(n-l,r-1))


Failing test case input:
8
6
5
2
1
3
4
8
7

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = []
for i in range(n):
    a.append(inn())
b = [0]*(n+1)
for i in range(n):
    b[a[i]] = b[a[i]-1]+1
print(n-max(b))

Problem: p03346
Buggy submission (Python (3.8.2), verdict: Wrong Answer):



def main():
  n = int(input())
  lp = [int(input()) for _ in range(n)]
  def f(lp):
    c = lp[0]
    ic = 0
    for p in lp[1:]:
      if c < p:
        c = p
      else:
        ic = max(ic, p)
    return ic
  print(min(f(lp), f(lp[::-1])))

if __name__=='__main__':
  main()



Failing test case input:
6
2
5
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):



def main():
  n = int(input())
  lp = [int(input()) for _ in range(n)]
  ilp = sorted(enumerate(lp), key=lambda x:x[1])
  max_cnt = 0
  cnt = 1
  for i in range(n-1):
    if ilp[i] < ilp[i+1]:
      cnt += 1
    else:
      max_cnt = max(max_cnt, cnt)
      cnt = 1
  print(n - max(max_cnt, cnt))
  
if __name__=='__main__':
  main()
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
i = 1
while i <= n:
    if p[i - 1] < p[i]:
        temp += 1
        i += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1
        i += 1
maxSet = max(maxSet, temp)
print(n - maxSet)


Failing test case input:
8
6
3
1
2
5
4
8
7

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
i = 2
while i <= n:
    if p[i - 1] < p[i]:
        temp += 1
        i += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1
        i += 1
maxSet = max(maxSet, temp)
print(n - maxSet)

Problem: p03346
Buggy submission (Python (3.8.2), verdict: Wrong Answer):



from operator import neg

def main():
  n = int(input())
  lp = [int(input()) for _ in range(n)]
  def f(lp):
    c = lp[0]
    ic = 0
    for p in lp[1:]:
      if c < p:
        c = p
      else:
        ic = max(ic, p)
    return ic
  print(min(f(lp), f([n-p+1 for p in lp[::-1]])))

if __name__=='__main__':
  main()



Failing test case input:
4
2
4
1
3

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):



def main():
  n = int(input())
  lp = [int(input()) for _ in range(n)]
  ilp = sorted(enumerate(lp), key=lambda x:x[1])
  max_cnt = 0
  cnt = 1
  for i in range(n-1):
    if ilp[i] < ilp[i+1]:
      cnt += 1
    else:
      max_cnt = max(max_cnt, cnt)
      cnt = 1
  print(n - max(max_cnt, cnt))
  
if __name__=='__main__':
  main()

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
 
n=int(input())
a=[int(input()) for i in range(n)]

al= defaultdict(lambda: 0)
ds=[]
ans=0
for ai in a:
  ds.append(ai)
  if ai - 1 in al.keys():
    al[ai]=al[ai-1]+1
    ans=max(ans,al[ai-1]+1)   
    del al[ai-1]
  else:
    al[ai]=1
    if ai + 1 in al.keys():
      del al[ai+1]
print(n-ans)

Failing test case input:
6
3
2
5
1
4
6

Expected output:
4

Actual output:
6


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(input()) for i in range(n)]

al= {}
ans=0
for ai in a:
  if ai - 1 in al.keys():
    al[ai]=al[ai-1]+1
    ans=max(ans,al[ai-1]+1)   
    del al[ai-1]
  else:
    al[ai]=0
    if ai + 1 in al.keys():
      del al[ai]
print(n-ans-1)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = [int(input()) for _ in range(N)]

Q = [-1]*N
for i in range(N):
    Q[P[i]-1] = i

x = 1
for i in range(1,N):
    if Q[i] > Q[i-1]:
        x += 1
    else:
        x = 1

print(N-x)

Failing test case input:
8
6
3
2
1
5
4
8
7

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
N = int(input())
P = [int(input()) for _ in range(N)]

Q = [-1]*N
for i in range(N):
    Q[P[i]-1] = i

x = 1
tmp = 1
for i in range(1,N):
    if Q[i] > Q[i-1]:
        tmp += 1
        x = max(x, tmp)
    else:
        tmp = 1

print(N-x)
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ind = [0 for _ in range(N)]
    for i in range(N):
        ind[A[i]-1] = i
    
    ind.reverse()
    for i in range(N-1):
        if ind[i] < ind[i+1]:
            print(N-i-1)
            exit()

    print(0)

if __name__ == "__main__":
    main()

Failing test case input:
6
2
3
5
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    ind = [0 for _ in range(N)]
    for i in range(N):
        A = int(input())
        ind[A-1] = i

    ans = 0
    count = 0
    for i in range(N-1):
        if ind[i] < ind[i+1]:
            count += 1
        else:
            ans = max(ans,count)
            count = 0
        ans = max(ans,count)

    print(N-ans-1) 

if __name__ == "__main__":
    main()

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = [int(input()) for _ in range(N)]

L = [0]*(N+1)
for i in range(N):
    if P[i] == N:
        continue
    if L[P[i]+1] == 0:
        L[P[i]+1] = L[P[i]]+1
    L[P[i]] = 1

ans = N-max(L)-1
print(ans)

Failing test case input:
6
2
5
3
1
4
6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
P = [int(input()) for _ in range(N)]

L = [1]*(N+1)
for i in range(N):
    if P[i] < N and L[P[i]+1] == 1:
        L[P[i]+1] = L[P[i]]+1
    if L[P[i]] == 1:
        L[P[i]] = 0

ans = N-max(L)
print(ans)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(input()) for i in range(N)]

    dp = [0] * N

    for i in range(N):
        if A[i] > 1:
            dp[A[i]-1] = dp[A[i]-2] + 1
    print(N - max(dp))


if __name__ == "__main__":
    main()

Failing test case input:
4
1
4
2
3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(input()) for i in range(N)]

    dp = [0] * N
    
    for i in range(N):
        if A[i] > 1:
            dp[A[i]-1] = dp[A[i]-2] + 1
        elif A[i] == 1:
            dp[A[i]-1] = 1
    print(N - max(dp))


if __name__ == "__main__":
    main()
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from copy import deepcopy
import itertools


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


N = read()
P = []
for _ in range(N):
    P.append(read())

i = 1
for k in range(N):
    if P[k] == i:
        i += 1

j = N
for k in reversed(range(N)):
    if P[k] == j:
        j -= 1

print(min(N - i + 1, j))


Failing test case input:
8
6
3
2
1
5
4
8
7

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
from copy import deepcopy
import itertools


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


N = read()
P = []
for _ in range(N):
    P.append(read())

dic = {}
for p in P:
    if p in dic.keys():
        dic[p+1] = dic[p] + 1
        del dic[p]
    else:
        dic[p+1] = 1

print(N - max(dic.values()))

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())

q=[-1]*N
for i in range(N):
    k = int(input())
    print(k)
    q[k-1]=i


max_con=1
count=0
for i in range(N-1):
    if q[i]<q[i+1]:
        count+=1
        max_con=max(max_con,count)
    else:
        count=1

print(N-max_con)

Failing test case input:
4
1
3
4
2

Expected output:
2


Actual output:
1
3
4
2
2


Fixed submission (verdict: Accepted):
N=int(input())

q=[-1]*N
for i in range(N):
    k = int(input())
    
    q[k-1]=i


max_con=1
count=1
for i in range(N-1):
    if q[i]<q[i+1]:
        count+=1
        max_con=max(max_con,count)
    else:
        count=1

print(N-max_con)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
d={}
for i in range(n):
  d[l[i]]=i+1
ans=0
ans1=1
index=1
while index<n:
  index+=1
  if d[index]>d[index-1]:
    ans1+=1
  else:
    if ans<ans1:
      ans=ans1
      ans1=1
print(n-ans)

Failing test case input:
8
6
3
1
2
5
4
8
7

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
d={}
for i in range(n):
  d[l[i]]=i+1
ans=1
ans1=1
index=1
while index<n:
  index+=1
  if d[index]>d[index-1]:
    ans1+=1
  else:
    if ans<ans1:
      ans=ans1
    ans1=1
if ans<ans1:
  ans=ans1
print(n-ans)
Problem: p03346
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    P = list(int(input()) for _ in range(n))

    num = n
    res = 0
    for i in reversed(range(n)):
        if P[i] != num:
            res += 1
        else:
            num -= 1
    print(res)


if __name__ == '__main__':
    resolve()


Failing test case input:
8
6
3
1
2
5
4
8
7

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    P = list(int(input()) for _ in range(n))

    res = [0] * (n + 1)
    for p in P:
        res[p] = res[p - 1] + 1
    print(n - max(res))


if __name__ == '__main__':
    resolve()

Problem: p03346
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

N = int(input())

T = [0]*N
for i in range(N):
    T[int(input())-1] = i

m = 0
streak = 1
for a,b in zip(T,T[1:]):
    if a < b:
        streak += 1
    else:
        m = max2(m, streak)
        streak = 1

print(N-streak)

Failing test case input:
8
6
3
1
2
5
4
8
7

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

N = int(input())

T = [0]*N
for i in range(N):
    T[int(input())-1] = i

m = 0
streak = 1
for a,b in zip(T,T[1:]):
    if a < b:
        streak += 1
    else:
        m = max2(m, streak)
        streak = 1
m = max2(m, streak)

print(N-m)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = [int(input()) for _ in range(n)]
q = [0] * (n+1)

for i in range(n):
    q[p[i]] = i
maxl = 0
cnt = 0
for i in range(n):
    if q[i+1] > q[i]:
        cnt += 1
    else:
        maxl = max(maxl, cnt)
print(n - maxl)


Failing test case input:
6
3
1
5
2
4
6

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
p = [int(input()) for _ in range(n)]
q = [0] * (n+1)

for i in range(n):
    q[p[i]] = i
maxl = 1
cnt = 1
for i in range(1, n):
    if q[i+1] > q[i]:
        cnt += 1
    else:
        maxl = max(maxl, cnt)
        cnt = 1
print(n - max(maxl, cnt))
Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    P = [int(input()) for _ in range(N)]
    P_sorted = sorted(P)
    j = 0
    for i in range(N):
        if P[i] == P_sorted[j]:
            j += 1

    k = 0
    for i in range(N)[::-1]:
        if P[i] == P_sorted[N - k - 1]:
            k += 1

    ans = min(N - j, N - k)
    print(ans)


if __name__ == "__main__":
    main()


Failing test case input:
8
6
5
2
1
3
4
8
7

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    P = [int(input()) for _ in range(N)]

    
    dp = [0] * (N + 1)
    for i in range(N):
        p = P[i]
        dp[p] = dp[p - 1] + 1

    print(N - max(dp))


if __name__ == "__main__":
    main()

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input=sys.stdin.readline
n=int(input())
p=[int(input())for _ in range(n)]
cnt1=1
for i in range(n):
	if p[i]==cnt1:
		cnt1+=1
cnt2=n
for i in range(n-1,-1,-1):
	if p[i]==cnt2:
		cnt2-=1
print(n-max(cnt1-1,n-cnt2))	


Failing test case input:
8
6
5
2
1
3
4
8
7

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
import sys
input=sys.stdin.readline
n=int(input())
p=[int(input())for _ in range(n)]
num=[-1]*n
for i in range(n):
	num[p[i]-1]=i
ans=0
kari=1
for i in range(n-1):
	if num[i+1]>num[i]:
		kari+=1
	else:
		ans=max(ans,kari)
		kari=1
ans=max(ans,kari)
print(n-ans)

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
p=[]
for i in range (n):
	p.append(int(input()))
pos=n
for j in range(n):
	if (n-j) in p[:pos]:
		pos = p[:pos].index(n-j)
	else:
		print(n-j)
		break

Failing test case input:
8
6
5
2
1
3
4
8
7

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
n=int(input())
p=[]
for i in range (n):
	p.append(int(input()))
pos=0
num=0
n_th = 0
s={}
for i in p:
	if i-1 in s:
		s[i]=s[i-1]+1
	else:
		s[i]=1
print(n-max(s.values()))

Problem: p03346
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [0]
for _ in range(N):
  a.append(int(input()))

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

for idx in range(2, len(a)):
    if a[idx - 1] < a[idx]:
        num += 1
    else:
        ans, num = max(num, ans), 1

print(N - max(num, ans))


Failing test case input:
4
1
4
2
3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
a = [0]
for _ in range(N):
  a.append(int(input()))

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

for idx in range(2, len(Q)):
    if Q[idx - 1] < Q[idx]:
        num += 1
    else:
        ans, num = max(num, ans), 1

print(N - max(num, ans))