n = int(input())

count = 0

res = 0

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



for i,a in enumerate(ais):

	

	if a == i +1:

		count += 1

	else:

		#flush the count

		res += (count + 1)/2# + 1

		count = 0



if count: res +=  (count+1)/2 

print(res)
n = int(input())

count = 0

res = 0

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



for i in range(n + 1):

	if (ais[i] if i < n else -1) != i + 1:

		#flush the count

		res += (count + 1)/2# + 1

		count = 0

	else:

		count +=1

print(res)
n = int(input())
count = 0
res = 0
ais = list(map(int, input().split()))
for i, a in enumerate(ais):
    if a == i + 1:
        count += 1
    else:
        # flush the count
        res += (count + 1) / 2  # + 1
        count = 0
if count:
    res += (count + 1) / 2
print(res)

n = int(input())
count = 0
res = 0
ais = list(map(int, input().split()))
for i in range(n + 1):
    if (ais[i] if i < n else -1) != i + 1:
        # flush the count
        res += (count + 1) / 2  # + 1
        count = 0
    else:
        count += 1
print(res)

-for i, a in enumerate(ais): -    if a == i + 1: -        count += 1 -    else: +for i in range(n + 1): +    if (ais[i] if i < n else -1) != i + 1: -if count: -    res += (count + 1) / 2 +    else: +        count += 1