CODE FESTIVAL 2016 qual A: B - 仲良しうさぎ / Friendly Rabbits
$a_{a_i} = i$なやつの数を数えてその半分。
#!/usr/bin/env python3
n = int(input())
a = list(map(lambda s: int(s)-1, input().split()))
ans = 0
for i in range(n):
if a[a[i]] == i and i < a[i]:
ans += 1
print(ans)