N = int(eval(input()))

src = list([int(x)-1 for x in input().split()])



mem = []

seq = 0

for i,a in enumerate(src):

    if i == a:

        seq += 1

    else:

        if seq > 0:

            mem.append(seq)

            seq = 0

if seq:

    mem.append(seq)



ans = 0

for a in mem:

    ans += (a+1)//2

print(ans)

N = int(eval(input()))

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



ans = 0

skip = False

for i,a in enumerate(src):

    if skip:

        skip = False

        continue

    if a == (i+1):

        ans += 1

        skip = True

print(ans)
N = int(eval(input()))
src = list([int(x) - 1 for x in input().split()])
mem = []
seq = 0
for i, a in enumerate(src):
    if i == a:
        seq += 1
    else:
        if seq > 0:
            mem.append(seq)
            seq = 0
if seq:
    mem.append(seq)
ans = 0
for a in mem:
    ans += (a + 1) // 2
print(ans)

N = int(eval(input()))
src = list(map(int, input().split()))
ans = 0
skip = False
for i, a in enumerate(src):
    if skip:
        skip = False
        continue
    if a == (i + 1):
        ans += 1
        skip = True
print(ans)

-src = list([int(x) - 1 for x in input().split()]) -mem = [] -seq = 0 +src = list(map(int, input().split())) +ans = 0 +skip = False -    if i == a: -        seq += 1 -    else: -        if seq > 0: -            mem.append(seq) -            seq = 0 -if seq: -    mem.append(seq) -ans = 0 -for a in mem: -    ans += (a + 1) // 2 +    if skip: +        skip = False +        continue +    if a == (i + 1): +        ans += 1 +        skip = True