N = int(eval(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)

N = int(eval(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)

N = int(eval(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)

N = int(eval(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)

-plist = list(map(int, input().split())) +p = list(map(int, input().split())) -    if plist[i] == i + 1: -        plist[i], plist[i + 1] = plist[i + 1], plist[i] +    if p[i] == i + 1: +        p[i], p[i + 1] = p[i + 1], p[i] -if plist[-1] == N: +if p[-1] == N: