from itertools import*

n,*l=list(map(int,open(0).read().split()))

print((sum(x//2+x%2 for x in[len(list(g))for k,g in groupby([i==j-1for i,j in enumerate(l)])if k])))
print((sum(x//2+x%2 for x in[len(list(g))for k,g in __import__("itertools").groupby([i==j for i,j in enumerate(map(int,open(0).read().split()))])if k])))
from itertools import *

n, *l = list(map(int, open(0).read().split()))
print(
    (
        sum(
            x // 2 + x % 2
            for x in [
                len(list(g))
                for k, g in groupby([i == j - 1 for i, j in enumerate(l)])
                if k
            ]
        )
    )
)

print(
    (
        sum(
            x // 2 + x % 2
            for x in [
                len(list(g))
                for k, g in __import__("itertools").groupby(
                    [i == j for i, j in enumerate(map(int, open(0).read().split()))]
                )
                if k
            ]
        )
    )
)

-from itertools import * - -n, *l = list(map(int, open(0).read().split())) -                for k, g in groupby([i == j - 1 for i, j in enumerate(l)]) +                for k, g in __import__("itertools").groupby( +                    [i == j for i, j in enumerate(map(int, open(0).read().split()))] +                )