# ABC 072 D

N = int(eval(input()))

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

ans = 0



r = [0 for k in range(N)]

for k in range(N):

    if p[k] == k+1:

        r[k] = 1

for k in range(1,N):

    if r[k] > 0:

        r[k] += r[k-1]



r = r + [0]



for k in range(1,N+1):

    if r[k] == 0:

        ans += (r[k-1]+1)//2



print(ans)

N = int(eval(input()))

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

l = [0 for k in range(N+2)]



for k in range(N):

    if p[k] == k+1:

        l[k+1] = 1



t = 0

ans = 0

for e in l:

    if e == 1:

        t += 1

    else:

        ans += (t+1)//2

        t = 0

print(ans)

# ABC 072 D
N = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
r = [0 for k in range(N)]
for k in range(N):
    if p[k] == k + 1:
        r[k] = 1
for k in range(1, N):
    if r[k] > 0:
        r[k] += r[k - 1]
r = r + [0]
for k in range(1, N + 1):
    if r[k] == 0:
        ans += (r[k - 1] + 1) // 2
print(ans)

N = int(eval(input()))
p = list(map(int, input().split()))
l = [0 for k in range(N + 2)]
for k in range(N):
    if p[k] == k + 1:
        l[k + 1] = 1
t = 0
ans = 0
for e in l:
    if e == 1:
        t += 1
    else:
        ans += (t + 1) // 2
        t = 0
print(ans)

-# ABC 072 D -ans = 0 -r = [0 for k in range(N)] +l = [0 for k in range(N + 2)] -        r[k] = 1 -for k in range(1, N): -    if r[k] > 0: -        r[k] += r[k - 1] -r = r + [0] -for k in range(1, N + 1): -    if r[k] == 0: -        ans += (r[k - 1] + 1) // 2 +        l[k + 1] = 1 +t = 0 +ans = 0 +for e in l: +    if e == 1: +        t += 1 +    else: +        ans += (t + 1) // 2 +        t = 0