n = int(eval(input()))

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

ans = 0

for i in range(n):

    if i != n-1:

        if i+1 == l[i]:

            a = l[i]

            b = l[i+1]

            l[i]=b

            l[i+1]=a

            ans += 1

    else:

        if i+1 == l[i]:

            ans += 1

print(ans)
n = int(eval(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]

        ans += 1

if p[n-1] == n:

    ans += 1

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

n = int(eval(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]
        ans += 1
if p[n - 1] == n:
    ans += 1
print(ans)

-l = list(map(int, input().split())) +p = list(map(int, input().split())) -for i in range(n): -    if i != n - 1: -        if i + 1 == l[i]: -            a = l[i] -            b = l[i + 1] -            l[i] = b -            l[i + 1] = a -            ans += 1 -    else: -        if i + 1 == l[i]: -            ans += 1 +for i in range(n - 1): +    if i + 1 == p[i]: +        p[i + 1] = p[i] +        ans += 1 +if p[n - 1] == n: +    ans += 1