N=int(eval(input()))

S=[]

for x,y in zip(list(map(int,input().split())), list(range(1,N+1))):

 if x==y: S.append(y)



S.append('$')

L=len(S)



l=[S[0]]

i=1

a=0

while i<L:

  if S[i]=='$':a+=1

  elif l[0]+1!=S[i]:

     a+=1

     l=[S[i]]

  else:l.append(S[i])

  i+=1

print(a)
N=int(eval(input()))

*P,=list(map(int,input().split()))



i=c=0

while i<N:

  if P[i]==i+1:

    c+=1

    i+=1

  i+=1

print(c)
N = int(eval(input()))
S = []
for x, y in zip(list(map(int, input().split())), list(range(1, N + 1))):
    if x == y:
        S.append(y)
S.append("$")
L = len(S)
l = [S[0]]
i = 1
a = 0
while i < L:
    if S[i] == "$":
        a += 1
    elif l[0] + 1 != S[i]:
        a += 1
        l = [S[i]]
    else:
        l.append(S[i])
    i += 1
print(a)

N = int(eval(input()))
(*P,) = list(map(int, input().split()))
i = c = 0
while i < N:
    if P[i] == i + 1:
        c += 1
        i += 1
    i += 1
print(c)

-S = [] -for x, y in zip(list(map(int, input().split())), list(range(1, N + 1))): -    if x == y: -        S.append(y) -S.append("$") -L = len(S) -l = [S[0]] -i = 1 -a = 0 -while i < L: -    if S[i] == "$": -        a += 1 -    elif l[0] + 1 != S[i]: -        a += 1 -        l = [S[i]] -    else: -        l.append(S[i]) +(*P,) = list(map(int, input().split())) +i = c = 0 +while i < N: +    if P[i] == i + 1: +        c += 1 +        i += 1 -print(a) +print(c)