ZhenlongDai/ACPR huggingface dataset:
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = list(map(int, input().split()))

cnt = 0
for i in range(N):
    if P[i] == i+1:
        P[i], P[i+1] = P[i+1], P[i]
        cnt += 1
    if i+2 < N:
        if P[i+2] == i+3:
            P[i+1], P[i+2] = P[i+2], P[i+1]
            cnt += 1

print(cnt)

Failing test case input:
9
2 2 4 5 5 8 4 6 6

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(N):
    if P[i] != i+1:
        continue
    if i+1 < N and P[i] != i+2 or i == 0:
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1
    else:
        P[i], P[i-1] = P[i-1], P[i]
        ans += 1

print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
temp = input().split(" ")
n = int(temp[0])
inp = input().split(" ")
sousa = inp
nsousa = 0
tempn = 0
flag = 0
for a in range(n):
    inp[a] = int(inp[a])
for a in range(n-1):
    
    if(flag):
        flag = 0
        continue
    if(a+1 != sousa[a] and a+2 != sousa[a+1]):
        pass
    else:
        tempn = sousa[a]
        sousa[a] = sousa[a+1]
        sousa[a+1] = tempn
        nsousa+=1
        if(a!=n-3):
            flag = 1
print(nsousa)
 

Failing test case input:
5
0 4 4 4 1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
temp = input().split(" ")
n = int(temp[0])
inp = input().split(" ")
sousa = [0 for a in range(n)]
nsousa = 0
tempn = 0
flag = 0
for a in range(n):
    inp[a] = int(inp[a])
    if inp[a] == a+1:
        sousa[a] = 1

for a in range(n-1):
    if(sousa[a] == 1 and sousa[a+1] == 1):
        nsousa+=1
        sousa[a] = 0
        sousa[a+1] = 0

nsousa+=sum(sousa)
print(nsousa)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
P=input()
P=P.rstrip().split()
P.append('0')

ans=0
l=0
for i in range(N+1):
    if P[l]==str(l+1):
        ans+=1
        l+=2
        if l>=N-1:
            break
print(ans)

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

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N=int(input())
P=input()
P=P.rstrip().split()
P.append('0')

ans=0
l=0
for i in range(N+1):
    
    if l>N-1:
            break
    elif P[l]==str(l+1):
        ans+=1
        l+=2
    else:
        l+=1
        
print(ans)

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

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

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


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

p = list(map(int, input().split()))
cnt = 0 
i = 0
while i <= n-1:
      if p[i] == i+1:
            cnt += 1
            i += 2
      else:
            i += 1
print(cnt)
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
pp = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
    if pp[i] == i + 1:
        pp[i], pp[i+1] = pp[i+1], pp[i]
        cnt += 1
print(cnt)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
pp = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
    if pp[i] == i + 1:
        pp[i], pp[i+1] = pp[i+1], pp[i]
        cnt += 1
if pp[n-1] == n:
    cnt += 1
print(cnt)

Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
p=list(map(int,input().split()))
swap=[0,0]
cnt=0
for i in range(N):
    if (p[i]==i+1):
        if swap[0]==0:
            swap[0]=i+1
        else:
            swap[1]=i+1
            
            cnt=cnt+(swap[1]-swap[0])
            swap=[0,0]
print(cnt)



Failing test case input:
9
1 4 1 2 3 10 2 12 14

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N=int(input())
p=list(map(int,input().split()))
point=[]
swap=[0,0]
cnt=0

for i in range(N):
    if p[i]==i+1:
        point.append(i+1)

cnt=len(point)
i=0
while i<len(point)-1:
    
    if point[i+1]==point[i]+1:
        cnt=cnt-1
        i=i+1
    i=i+1
print(cnt)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
p=list(map(int,input().split()))
cnt=0

for i in range(0,n):
    if p[i]==i+1:
        cnt+=1

if cnt!=0:
    print(cnt-1)
else:
    print(0)

Failing test case input:
5
1 4 3 5 2

Expected output:
2

Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
p=list(map(int,input().split()))
cnt=0

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

print(cnt)

Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if P[i] == i+1:
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1
if P[-1] == n:
    P[-2], P[-1] = P[-1], P[-2]
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if P[i] == i+1:
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1
if P[-1] == n:
    ans += 1
print(ans)

Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
plist = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
    if plist[i] == i + 1 or plist[i + 1] == i + 2:
        plist[i], plist[i + 1] = plist[i + 1], plist[i]
        ans += 1
print(ans)



Failing test case input:
9
2 2 1 1 5 7 4 6 10

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
plist = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
    if plist[i] == i + 1:
        plist[i], plist[i + 1] = plist[i + 1], plist[i]
        ans += 1
if plist[-1] == N:
    ans += 1
print(ans)
Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
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
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
p = LI()
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
print(ans)


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
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
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
p = LI()
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
if p[-1] == n:
    ans += 1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
alist = [int(i) for i in input().split()]
ans=0
 
for i in range(n-1):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
alist = [int(i) for i in input().split()]
ans=0
 
for i in range(n-1):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
if alist[n-1]==n:
	ans+=1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = list(map(int, input().split()))
swapcount = 0
for i in range(n - 1):
    if p[i] == i + 1:
        k = p[i + 1]
        p[i + 1] = p[i]
        p[i] = k
        swapcount += 1
print(swapcount)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int, input().split()))
swapcount = 0
for i in range(n):
    if i != n - 1:
        if p[i] == i + 1:
            k = p[i + 1]
            p[i + 1] = p[i]
            p[i] = k
            swapcount += 1
    else:
        if p[i] == i + 1:
            swapcount += 1

print(swapcount)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    if i+1 ==P[i]:
        P[i+1], P[i] = P[i], P[i+1]
        ans += 1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    if i+1 ==P[i]:
        P[i+1], P[i] = P[i], P[i+1]
        ans += 1
if P[-1]==N:
  ans+=1
print(ans)
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
p = list(map(int,input().split()))

ans = 0
flag = 0

tmp = 0
for n in range(N):
  if p[n] == n+1:
    if flag == 0:
      tmp = n
      flag = 1
    else:
      ans += n - tmp
      flag = 0
print(ans)

Failing test case input:
5
1 1 24 0 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
p = list(map(int,input().split()))

ans = 0
continuous_flag= 0

for n in range(N):
  if p[n] == n+1:
    if continuous_flag == 0:
      ans += 1
      continuous_flag = 1
    else:
      continuous_flag = 0
  else:
    continuous_flag = 0
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys


def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if i == n:
            count += 1
    if count % 2 == 0:
        print(int(count/2))
    else:
        print(int((count+1)/2)+1)

if __name__ == '__main__':
    main()


Failing test case input:
9
1 2 1 1 5 7 2 6 10

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys

def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if i == n:
            count += 1
            if len(p) != i:
                p[i - 1], p[i] = p[i], p[i - 1]
    print(count)

if __name__ == '__main__':
    main()

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
p = list(map(int, input().split()))
i = 0
ans = 0
while(i < N - 1):
    if p[i] == i + 1:
        ans += 1
        p[i], p[i + 1] = p[i + 1], p[i]
    i += 1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
p = list(map(int, input().split()))
i = 0
ans = 0
while(i < N - 1):
    if p[i] == i + 1:
        ans += 1
        p[i], p[i + 1] = p[i + 1], p[i]
    i += 1
if p[N - 1] == N:
    ans += 1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def derangement(N: int, P: list)->int:
    count = 0
    for i in range(N-1):
        if P[i] == i+1:
            count += 1
            P[i], P[i+1] = P[i+1], P[i]
    return count


if __name__ == "__main__":
    N = int(input())
    P = [int(s) for s in input().split()]
    ans = derangement(N, P)
    print(ans)


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
def derangement(N: int, P: list)->int:
    count = 0
    for i in range(N-1):
        if P[i] == i+1:
            count += 1
            P[i], P[i+1] = P[i+1], P[i]

    if P[-1] == N:
        count += 1
    return count


if __name__ == "__main__":
    N = int(input())
    P = [int(s) for s in input().split()]
    ans = derangement(N, P)
    print(ans)
Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i, _ in enumerate(p[:-1]):
    
    p_ = p[i]
    if p_ == i + 1:
        ans += 1
        p[i], p[i+1] = p[i+1], p[i]

print(ans)



Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i, _ in enumerate(p[:-1]):
    
    p_ = p[i]
    if p_ == i + 1:
        ans += 1
        p[i], p[i+1] = p[i+1], p[i]

if p[-1] == n:
  ans += 1
        
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(n - 1):
    if P[i] == i + 1 or P[i + 1] == i + 2:
        P[i], P[i + 1] = P[i + 1], P[i]
        count += 1

print(count)

Failing test case input:
9
2 2 1 1 5 7 4 6 10

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(n - 1):
    if P[i] == i + 1:
        P[i], P[i + 1] = P[i + 1], P[i]
        count += 1
if P[-1] == n:
    count += 1

print(count)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
p = list(map(int, input().split()))
i = 0
ans = 0
while(i < N - 1):
    if p[i] == i + 1:
        ans += 1
        if p[i + 1] == i + 2:
            i += 2
    i += 1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
p = list(map(int, input().split()))
i = 0
ans = 0
while(i < N - 1):
    if p[i] == i + 1:
        ans += 1
        p[i], p[i + 1] = p[i + 1], p[i]
    i += 1
if p[N - 1] == N:
    ans += 1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(n - 1):
    if p[i] == i + 1 and p[i + 1] == i + 2:
        p[i], p[i + 1] = p[i + 1], p[i]
        ans += 1
    elif p[i] == i + 1:
        p[i], p[i + 1] = p[i + 1], p[i]
        ans += 1
print(ans)


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if i + 1 == p[i]:
        if i != n - 1:
            p[i], p[i + 1] = p[i + 1], p[i]
        else:
            p[i], p[i - 1] = p[i - 1], p[i]
        ans += 1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    if i + 1 == P[i]:
        P[i], P[i + 1] = P[i + 1], P[i] 
        ans += 1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    if i + 1 == P[i]:
        P[i], P[i + 1] = P[i + 1], P[i] 
        ans += 1
if P[N-1] == N:
    ans += 1
print(ans)
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input()) 
P = [int(x)-1 for x in input().split()]










cnt = 0
i = 0
while i < N-1:
    if P[i] != i:
        P[i],P[i+1] = P[i+1],P[i]
        i+=1
    else: 
        P[i],P[i+1] = P[i+1],P[i]
        cnt += 1
        i+=2
if P[N-1] == N-1:
    cnt+=1
print(cnt)


Failing test case input:
5
1 4 4 5 1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input()) 
P = [int(x)-1 for x in input().split()]









cnt = 0
i = 0
while i < N-1:
    if P[i] != i:
        i+=1
    else: 
        P[i],P[i+1] = P[i+1],P[i]
        cnt += 1
        i+=2
if P[N-1] == N-1:
    cnt+=1
print(cnt)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
P = list(map(int, input().split()))

r = 0
for i in range(n-1):
    if P[i] == i+1:
        P[i+1] = P[i]
        r += 1
print(r)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
P = list(map(int, input().split()))

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

Problem: p03612
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
def main():
    N = int(input())
    P = [int(a) for a in input().split()]

    diff = deque()

    for i in range(len(P)):
        if i + 1 == P[i]:
            diff.append(i + 1)

    ans = 0
    for i in range(10**6):
        if len(diff) == 0:
            break
        elif len(diff) == 1:
            ans += 1
        else:
            l = diff.popleft()
            r = diff.popleft()
            ans += min(2, r - l)

    print(ans)

if __name__ == "__main__":
    main()

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

Expected output:
2


Actual output:
1000000


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    P = [int(a) for a in input().split()]

    ans = 0
    for i in range(len(P)):
        if i == len(P) - 1:
            if P[i] == i + 1:
                P[i], P[i - 1] = P[i - 1], P[i]
                ans += 1
            else:
                pass

        else:
            if P[i] == i + 1:
                P[i], P[i + 1] = P[i + 1], P[i]
                ans += 1
            else:
                pass

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

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
*P, = map(int, input().split())

ans = 0
for i in range(N-1):
    if P[i]==(i+1):
        temp = P[i]
        P[i] = P[i+1]
        P[i+1] = temp
        ans = ans + 1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
*P, = map(int, input().split())

ans = 0
for i in range(N-1):
    if P[i]==(i+1):
        temp = P[i]
        P[i] = P[i+1]
        P[i+1] = temp
        ans = ans + 1
if P[N-1]==(N):
    ans = ans + 1
print(ans)
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = [int(_) for _ in input().split()]

count = 0
for n in range(N - 1):
    if P[n] == n + 1:
        P[n] = P[n + 1]
        P[n + 1] = n + 1
        count += 1
print(count)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


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

count = 0
for n in range(N - 1):
    if P[n] == n + 1:
        P[n] = P[n + 1]
        P[n + 1] = n + 1
        count += 1
if P[N - 1] == N:
    count += 1
print(count)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
if ' '.join([str(x) for x in l])=='1 2 4 9 5 8 7 3 6':
  exit()
c=0
for i in range(n-1):
  if l[i]==i+1:
    c+=1
    tmp=l[i+1]
    l[i+1]=l[i]
    l[i]=tmp
print(c)

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

Expected output:
3

Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n-1):
  if l[i]==i+1:
    c+=1
    tmp=l[i+1]
    l[i+1]=l[i]
    l[i]=tmp
if l[-1]==n:
  c+=1
print(c)

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



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

    ans = 0
    i = 1
    while i < N:
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i-1]
            p[i-1] = tmp
            ans += 1
            if i != N-2:
                i += 1
        i += 1
    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
5
1 1 17 7 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):



def main():
    N = int(input())
    p = list(map(int, input().split())) + [N+1]

    ans = 0
    i = 1
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Problem: p03612
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n - 1):
    if p[i] - 1 == i:
        count += 1
        p[i] ,p[i + 1] = p[i + 1], p[i]
print(count)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n-1):
    if p[i] - 1 == i:
        count += 1
        p[i] ,p[i + 1] = p[i + 1], p[i]
if p[n - 1] - 1 == n - 1:
    count += 1
print(count)
Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import itertools
def solve():
    N = int(input())
    p = list(map(int, input().split()))
    p.append(N+1)
    N += 1

    one_cnt = 0
    swap_cnt = 0
    for i in range(N):
        if p[i] == i + 1:
            one_cnt += 1
        else:
            if one_cnt % 2 == 0:
                swap_cnt += one_cnt / 2
            else:
                swap_cnt += one_cnt 
            one_cnt = 0
    
    print(int(swap_cnt))

if __name__ == '__main__':
    solve()


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import itertools
def solve():
    N = int(input())
    p = list(map(int, input().split()))

    one_cnt = 0
    swap_cnt = 0
    for i in range(N):
        if p[i] == i + 1:
            one_cnt += 1
        else:
            if one_cnt % 2 == 0:
                swap_cnt += one_cnt / 2
            else:
                swap_cnt += one_cnt 
            one_cnt = 0
    
    else:
        if one_cnt % 2 == 0:
            swap_cnt += one_cnt / 2
        else:
            swap_cnt += one_cnt 

    print(int(swap_cnt))

if __name__ == '__main__':
    solve()

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = list(map(int, input().split()))
cnt=0
for i in range(len(a)):
    if i+1 < N:
        if a[i] == i+1:
            inter=a[i]
            a[i]=a[i+1]
            a[i+1]=inter
            cnt +=1
print(cnt)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
a = list(map(int, input().split()))
cnt=0
for i in range(N):
    if a[i] == i+1:
        if i+1 == N:
            inter=a[i]
            a[i]=a[i-1]
            a[i-1]=inter
        else:
            inter=a[i]
            a[i]=a[i+1]
            a[i+1]=inter
        cnt +=1
print(cnt)

Problem: p03612
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
P = tuple(map(lambda x: int(x)-1, input().split()))
ans = 0
pre = P[0]
for i in range(n-1):
    if pre == i:
        ans += 1
    else:
        pre = P[i+1]
print(ans)


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
P = tuple(map(lambda x: int(x)-1, input().split()))
ans = 0
pre = P[0]
for i in range(n-1):
    if pre == i:
        ans += 1
    else:
        pre = P[i+1]
if pre == n-1:
    ans += 1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
*P, = map(int, input().split())

ans = 0

for i in range(N-1):
    if (i+1)==P[i] or (i+2)==P[i+1]:
        temp = P[i]
        P[i] = P[i+1]
        P[i+1] = temp
        ans = ans + 1
print(ans)

Failing test case input:
9
2 2 1 1 5 8 4 6 10

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
*P, = map(int, input().split())

ans = 0
for i in range(N-1):
    if P[i]==(i+1):
        temp = P[i]
        P[i] = P[i+1]
        P[i+1] = temp
        ans = ans + 1
if P[N-1]==(N):
    ans = ans + 1
print(ans)
Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if P[i] == i+1:
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1

print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if P[i] == i+1:
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1
if P[-1] == n:
    ans += 1
print(ans)

Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    n = int(input())
    p = [int(x) - 1 for x in input().split()]
    ans = 0
    for i in range(n):
        if p[i] == i:
            if i < n - 1:
                p[i], p[i + 1] = p[i + 1], p[i]
                ans += 1
            else:
                p[i], p[0] = p[0], p[i]
    print(ans)


main()



Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    p = [int(x) - 1 for x in input().split()]
    ans = 0
    for i in range(n):
        if p[i] == i:
            if i < n - 1:
                p[i], p[i + 1] = p[i + 1], p[i]
                ans += 1
            else:
                p[i], p[i - 1] = p[i - 1], p[i]
                ans += 1
    print(ans)


main()

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = list(map(int,input().split()))
c = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        c += 1
print(c)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int,input().split()))
c = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        c += 1
if p[n-1] == n:
    c += 1
print(c)

Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    N = int(input())
    P = [int(x) for x in input().split()]
    cnt = 0
    i = 0
    while i < N-1:
        if P[i] == i+1:
            P[i],P[i+1] = P[i+1],P[i]
            cnt += 1
            i += 1
            continue
        if P[i+1] == i+2 and P[i] == i+2:
            P[i],P[i+1] = P[i+1],P[i]
            cnt += 1
            i += 2
            continue
        i += 1
    print(cnt)

if __name__ == '__main__':
    main()

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

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    P = [int(x) for x in input().split()]
    cnt = 0
    i = 0
    for i in range(N):
        if P[i] == i+1:
            if i+1 >= N:
                P[i],P[i-1] = P[i-1],P[i]
            else:
                P[i],P[i+1] = P[i+1],P[i]
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
p = list(map(int, input().split()))

ans = 0
prev = 0
for i in range(N):
    if p[i] == i+1:
        if i != prev + 1:
            ans += 1
        prev = i
print(ans)

Failing test case input:
9
2 2 4 5 5 8 4 6 10

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
if p[N-1] == N:
    ans += 1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
p=list(map(int, input().split()))

p.append(N*2)
count=0
i=0
while i<=N-1:
    if i==p[i-1]:
        
        if i+1==p[i+1-1]:
            count+=1
            i+=1
        else:
            count+=1
    i+=1
print(count)




Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
p=list(map(int, input().split()))

p.append(N*2)
count=0
i=0
while i<=N-1:
    if i+1==p[i]:
        
        if i+2==p[i+1]:
            count+=1
            i+=1
        else:
            count+=1
    i+=1
print(count)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
P=list(map(int,input().split()))
c=0
for i in range(N-1):
    if P[i]==i+1:
        P[i],P[i+1]=P[i+1],P[i]
        c+=1
print(c)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
P=list(map(int,input().split()))
Q=P[::-1]
c=0
for i in range(N-1):
    if P[i]==i+1:
        P[i],P[i+1]=P[i+1],P[i]
        c+=1
if P[N-1]==N:
    c+=1
print(c)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(n):
  if a[i] == i+1:
    ans += 1
print(max([ans-1, 1]) if ans else 0)

Failing test case input:
9
2 2 4 5 5 8 4 6 10

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(n):
  if i == n-1 and a[i] == n:
    ans += 1
  elif a[i] == i+1:
    ans += 1
    a[i], a[i+1] = a[i+1], a[i]
print(ans)

Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
l = list(map(int, input().split()))
l = [x-1 for x in l]

ans = 0
for i in range(n-1):
  if l[i] == i:
    ans += 1
    l[i+1] = l[i]
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
l = list(map(int, input().split()))
l = [x-1 for x in l]

ans = 0
for i in range(n):
  if l[i] == i:
    ans += 1
    if i != n-1:
      l[i+1] = l[i]
print(ans)
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(1, n):
    if p[i-1] == i:
        p[i-1], p[i] = p[i], p[i-1]
        cnt += 1
print(cnt)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int, input().split()))
flag = 0
cnt = 0
for i in range(n):
    if flag: flag=0
    elif p[i]==i+1:
        flag=1
        cnt+=1
print(cnt)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys


def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i in p:
        if i == p:
            count += 1
    if count % 2 == 0:
        print(count/2)
    else:
        print((count+1)/2)

if __name__ == '__main__':
    main()


Failing test case input:
5
1 4 4 5 2

Expected output:
1


Actual output:
0.0


Fixed submission (verdict: Accepted):
import sys

def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if i == n:
            count += 1
            if len(p) != i:
                p[i - 1], p[i] = p[i], p[i - 1]
    print(count)

if __name__ == '__main__':
    main()

Problem: p03612
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
p=list(map(int,input().split()))

count=0
for i in range(N-1):
  if p[i] == i+1:
    p[i],p[i+1]=p[i+1],p[i]
    count += 1
print(count)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
p=list(map(int,input().split()))

count=0
flag=0
for i in range(N):
  if flag:
    flag=0
    continue
  if p[i]==i+1:
    count += 1
    if i < N-1 and p[i+1]==i+2:flag=1
      
print(count)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = list(map(int, input().split()))
ans = 0

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

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int, input().split()))
ans = 0

for i in range(n-1):
	if i+1 == p[i]:
		p[i],p[i+1] = p[i+1],p[i]
		ans += 1
		
if p[-1] == len(p):
	ans += 1	
print(ans)

Problem: p03612
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-1):
  if p[i] == i+1:
    p[i],p[i+1] = p[i+1],p[i]
    ans += 1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-1):
  if p[i] == i+1:
    p[i],p[i+1] = p[i+1],p[i]
    ans += 1
if p[n-1] == n: ans += 1 
print(ans)
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    P = list(map(int, readline().split()))
    P = list(map(lambda x: x-1, P))

    cnt = 0
    for i in range(1, N-1):
        if P[i] == i:
            if P[i-1] == i-1:
                P[i], P[i-1] = P[i-1], P[i]
                cnt += 1
            elif P[i+1] == i+1:
                P[i], P[i+1] = P[i+1], P[i]
                cnt += 1
            else:
                P[i], P[i+1] = P[i+1], P[i]
                cnt += 1

    if P[-1] == N-1:
        print(cnt+1)
    else:
        print(cnt)


main()


Failing test case input:
9
1 4 1 2 3 10 2 12 14

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    P = list(map(int, readline().split()))
    P = list(map(lambda x: x-1, P))

    cnt = 0
    for i in range(0, N):
        if i == N-1:
            if P[i] == i:
                P[i], P[i-1] = P[i-1], P[i]
                cnt += 1
        elif P[i] == i:
            if P[i+1] == i+1 and i != N-1:
                P[i], P[i+1] = P[i+1], P[i]
                cnt += 1
            elif i != 0:
                P[i], P[i-1] = P[i-1], P[i]
                cnt += 1
            else:
                P[i], P[i+1] = P[i+1], P[i]
                cnt += 1

    print(cnt)


main()

Problem: p03612
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
p = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i+1] = p[i]
        ans += 1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
p = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    if i < n-1 and p[i] == i+1:
        p[i+1] = p[i]
        ans += 1
    elif i == n-1 and p[i] == i+1:
        ans += 1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
p=list(map(int, input().split()))
i = 1
res = 0
while i<len(p):
    if i==p[i-1] and i+1==p[i]:
        res += 1
        i += 2
    elif i==p[i-1]:
        res += 1
        i += 1
    else:
        i += 1
print(res)


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
p=list(map(int, input().split()))
i = 1
res = 0
while i<N:
    if i==p[i-1] and i+1==p[i]:
        res += 1
        i += 2
    elif i==p[i-1]:
        res += 1
        i += 1
    else:
        i += 1
if i==N and i==p[i-1]:
    res += 1
print(res)
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
p = list(map(int,input().split()))
ans = 0
c = 0
for i in range(N-1):
    if p[i] == i+1:
        c += 1
    else:
        ans += (c+1)
        c = 0
print(ans)

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

Expected output:
3

Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
p = list(map(int,input().split()))
ans = 0
c = 0
for i in range(N):
    if p[i] == i+1:
        c += 1
    else:
        ans += (c+1)
        c = 0
print(ans+(c+1)

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

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

count = 0
for i in range(0, n - 1):
    if arr[i] == i + 1:
        arr[i], arr[i + 1] = arr[i + 1], arr[i]
        count += 1

print(count)



Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):




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

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


print(count)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if len(p) == i:
            continue
        if i == n:
            p[i - 1], p[i] = p[i], p[i - 1]
            count += 1
    print(count)

if __name__ == '__main__':
    main()


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if i == n:
            count += 1
            if len(p) != i:
                p[i - 1], p[i] = p[i], p[i - 1]
    print(count)

if __name__ == '__main__':
    main()

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
d = list(map(int, input().split()))
res = 0
for i in range(n - 1):
    if d[i]  == (i + 1): 
        d[i], d[i+1] = d[i+1], d[i]
        res += 1
print(res)


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
d = list(map(int, input().split()))
res = 0
for i in range(n - 1):
    if d[i] == (i + 1):  
        d[i], d[i + 1] = d[i + 1], d[i]
        res += 1
if d[n-1] == len(d):
    d[n-2], d[n-1] = d[n-1], d[n-2]
    res += 1
print(res)
Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = list(map(int, input().split()))

ans = 0
cnt = 0

f = 0
for i, v in enumerate(P):
    if not f:
        if i+1 == v:
            f = 1
    else:
        cnt += 1
        if i+1 == v:
            ans += cnt
            f = 0
            cnt = 0
    
print(ans + f)

Failing test case input:
9
2 2 4 9 5 8 4 6 6

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
P = list(map(int, input().split()))

check = [0 for _ in range(N)]
ans = 0

for i, v in enumerate(P):
    if i+1 == v:
        check[i] = 1

for i in range(N-1):
    if check[i] == 1:
        ans += 1
        if check[i+1] == 1:
            check[i+1] = 0

print(ans + check[-1])

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
p_list = list(map(int, input().split()))
count = 0
for i in range(N-1):
    if p_list[i] == i + 1:
        count += 1
        p_list[i+1] = p_list[i]
if p_list[N-1] == N -1:
    count += 1
print(count)



Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
p_list = list(map(int, input().split()))

count = 0
for i in range(N-1):
    if p_list[i] == i + 1:
        count += 1
        p_list[i+1] = p_list[i]
if p_list[N-1] == N:
    count += 1
print(count)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = list(map(int,input().split()))
count = 0

for i in range(n-1):
  if p[i] == i+1 and p[i+1] == i+2:
    count += 1
    p[i],p[i+1] = p[i+1],p[i]
  elif p[i] == i+1 and p[i+1] != i+2:
    count += 1
    

Failing test case input:
5
2 4 17 7 1

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int,input().split()))
count = 0

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

print(count)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
p_list =  list(map(int, input().split()))

i = 0
count = 0

if p_list[-1] == N:
    temp = p_list[-1]
    p_list[-1] = p_list[-2]
    p_list[-2] = temp

while i < N:
    if p_list[i] == i + 1:
        temp = p_list[i+1]
        p_list[i+1] = p_list[i]
        p_list[i] = temp
        count = count + 1
        i = i + 1
    i = i + 1

print(count)


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
p_list =  list(map(int, input().split()))

i = 0
count = 0

if p_list[-1] == N:
    temp = p_list[-1]
    p_list[-1] = p_list[-2]
    p_list[-2] = temp
    count = count + 1

while i < N:
    if p_list[i] == i + 1:
        temp = p_list[i+1]
        p_list[i+1] = p_list[i]
        p_list[i] = temp
        count = count + 1
        i = i + 1
    i = i + 1

print(count)
Problem: p03612
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
m = [i for i in range(1,n)]
p = list(map(int,input().split()))
cnt = 0
for i in m:
    if p[i-1] == i:
        p[i-1] = p[i]
        p[i] = i
        cnt += 1
    
print(cnt)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
m = [i for i in range(1,n)]
p = list(map(int,input().split()))
cnt = 0
for i in m:
    if p[i-1] == i:
        p[i-1] = p[i]
        p[i] = i
        cnt += 1

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

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(0,N,2):
    if p[i]-1==i and p[i]==i+1:
        ans+=1
    elif p[i]-1==i or p[i]==i+1:
        ans+=1
if N%2==1:
    if p[-1]==N:
        ans+=1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(N-1):
    if p[i]==i+1:
        tmp=p[i]
        p[i]=p[i+1]
        p[i+1]=tmp
        ans+=1
if p[-1]==N:
    ans+=1
print(ans)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n-2):
  if l[i]==i+1:
    c+=1
    l[i],l[i+1]=l[i+1],l[i]
if l[n-1]==n:
  c+=1
print(c)

Failing test case input:
2
1 -10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n-1):
  if l[i]==i+1:
    c+=1
    l[i],l[i+1]=l[i+1],l[i]
if l[n-1]==n:
  c+=1
print(c)

Problem: p03612
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import itertools
def solve():
    N = int(input())
    p = list(map(int, input().split()))

    one_cnt = 0
    swap_cnt = 0
    for i in range(N):
        if p[i] == i + 1:
            one_cnt += 1
        else:
            if one_cnt % 2 == 0:
                swap_cnt += one_cnt / 2
            else:
                swap_cnt += one_cnt 
            one_cnt = 0
    
    print(int(swap_cnt))

if __name__ == '__main__':
    solve()


Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import itertools
def solve():
    N = int(input())
    p = list(map(int, input().split()))

    one_cnt = 0
    swap_cnt = 0
    for i in range(N):
        if p[i] == i + 1:
            one_cnt += 1
        else:
            if one_cnt % 2 == 0:
                swap_cnt += one_cnt / 2
            else:
                swap_cnt += one_cnt 
            one_cnt = 0
    
    else:
        if one_cnt % 2 == 0:
            swap_cnt += one_cnt / 2
        else:
            swap_cnt += one_cnt 

    print(int(swap_cnt))

if __name__ == '__main__':
    solve()
Problem: p03612
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    N = int(input())
    P = list(map(int, input().split()))
    cnt = 0
    for i in range(N):
        if P[i] == i + 1:
            cnt += 1
    ans = (cnt + 1) 
    print(ans)


if __name__ == "__main__":
    main()


Failing test case input:
9
1 4 1 2 3 10 2 6 14

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    P = list(map(int, input().split()))
    cnt = 0
    for i in range(N - 1):
        if P[i] == i + 1:
            cnt += 1
            P[i + 1], P[i] = P[i], P[i + 1]
    if P[N - 1] == N:
        cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = {i : inp for i, inp in enumerate(map(int, input().split()), 1)}

ret = 0
for i in range(1, N):
  if P[i] == i:
    P[i], P[i+1] = P[i+1], P[i]
    ret += 1

print(ret)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
P = {i : inp for i, inp in enumerate(map(int, input().split()), 1)}

ret = 0
for i in range(1, N):
  if P[i] == i:
    P[i], P[i+1] = P[i+1], P[i]
    ret += 1
    
if P[N] == N:
  ret += 1

print(ret)

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys


def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if i == n:
            count += 1
    if count % 2 == 0:
        print(int(count/2))
    else:
        print(int((count-1)/2)+1)

if __name__ == '__main__':
    main()


Failing test case input:
9
2 2 4 5 5 8 4 6 10

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if i == n:
            count += 1
            if len(p) != i:
                p[i - 1], p[i] = p[i], p[i - 1]
    print(count)

if __name__ == '__main__':
    main()

Problem: p03612
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
p = na()
ans = 0
for i in range(n-1):
    if p[i] == i + 1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
print(ans)

Failing test case input:
5
1 2 17 7 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
p = na()
ans = 0
for i in range(n):
    if p[i] == i + 1:
        if i == n - 1:
            ans += 1
            continue
        p[i], p[i + 1] = p[i + 1], p[i]
        ans += 1

print(ans)