Problem:


Score : 200 points

Problem Statement

There are N rabbits, numbered 1 through N.

The i-th (1≤i≤N) rabbit likes rabbit a_i.
Note that no rabbit can like itself, that is, a_i≠i.

For a pair of rabbits i and j (i＜j), we call the pair (i，j) a friendly pair if the following condition is met.

Rabbit i likes rabbit j and rabbit j likes rabbit i.

Calculate the number of the friendly pairs.

Constraints

2≤N≤10^5

1≤a_i≤N

a_i≠i

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the number of the friendly pairs.

Sample Input 1

4
2 1 4 3

Sample Output 1

2

There are two friendly pairs: (1，2) and (3，4).

Sample Input 2

3
2 3 1

Sample Output 2

0

There are no friendly pairs.

Sample Input 3

5
5 5 5 5 1

Sample Output 3

1

There is one friendly pair: (1，5).



Sample input:
4
2 1 4 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 0
a=list(map(int, input().split()))
for i in range(len(a)):
    for j in range(len(a)):
        if a[i] == j and a[j] == i:
            cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(1, n + 1):
    if i == a[a[i - 1] - 1]:
        opp = a.index(a[a[i - 1] - 1])
        if not((opp + 1, i) in ans):
            ans.append((i, opp + 1))
print(len(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(1, n + 1):
    if i == a[a[i - 1] - 1]:
        if not((a.index(a[a[i - 1] - 1]) + 1, i) in ans):
            ans.append((i, a.index(a[a[i - 1] - 1]) + 1))
print(len(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [False] * n
inputList = list(map(int, input().split()))
pairs = 0
for i in range(n):
    if l[i]:
        continue

    x = inputList[i]-1 
    if inputList[x]-1 == i:
        pairs += 1
    l[x] = True
print(pairs)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
  if a[a[i]-1] == i+1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int,input().split()))
ans = 0
for i in range(n):
    if s[s[i]-1] == i+1:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(lambda x:int(x)-1,input().split()))
ans = 0
for i in range(N):
    if a[i] == i:
        ans += 1
print(ans//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))

ans = 0
for c in range(N):
    if a.index(a[c]) == a[a[c] - 1] - 1:
        #print(c)
        ans += 1
print(round(ans / 2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

print(a)

# print(n)
# print(a)
count = 0


for i in range(n + 1):
    if(i == a[a[i - 1] - 1]):
        count += 1


print(int(count/2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

print(a)

# print(n)
# print(a)
count = 0


for i in range(n + 1):
    if(i == a[a[i - 1] - 1]):
        count += 1

print(count/2)
# print(int(count/2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

# print(n)
# print(a)
count = 0


for i in range(n - 1):
    if(i == a[a[i - 1] - 1]):
        count += 1

print(count)
# print(int(count/2))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))

ans = 0
for c in range(N):
    if a.index(a[c]) == a[a[c] - 1] - 1:
        #print(c)
        ans += 1
print(round(ans / 2))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))

ans = 0
cnt = 0

for a in A:
    cnt += 1
    if A[a-1] == cnt:
        ans += 1

print(ans/2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [x - 1 for x in map(int, input().split())]

print(A)
cnt = 0
for i in range(N):
    if A[A[i]] == i:
        cnt += 1
print(cnt // 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
 
ans=0
 
for i in range(N//2):
  if a[a[i]-1]==i+1 and a[i]!=i+1:
    ans += 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
 
ans=0
 
if N%2==0:
    for i in range(N//2):
      if a[a[i]-1]==i+1 and a[i]!=i+1:
        ans += 1
            
else:
    for i in range(N//2 +1):
        if a[a[i]-1]==i+1 and a[i]!=i+1:
          ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
 
ans=0
 
if N%2==0:
    for i in range(N//2):
      if a[a[i]-1]==i+1:
        ans += 1
            
else:
    for i in range(N//2 +1):
        if a[a[i]-1]==i+1:
          ans+=1
 
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
rabbits = list(map(int,input().split()))
cnt = 0
if(n>3):
    for num in range(n):
        l = rabbits[num]

        if(rabbits[num] < rabbits[l-1]):
            cnt = cnt + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_l = list(map(int, input().split()))
ans = 0
for i,j in enumerate(a_l):
    if i == i:
        ans+= 1
print(int(ans/2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) - 1 for a in input().split()]
count = 0
for i in range(N):
    if i == A[A[i]]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
count=0
for i in range(N):
    if i == (a[a[i]-1]-1):
        print(a[a[i]-1]-1)
        count += 1

print(int(count/2))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
ans=0
for i in range(N):
  if A[A[i-1]-1]==i+1:
    ans+=1
print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(n):
    if i+1 == a[i-1]:
        count+=1
print(count//2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    if a[a[i]-1]==i+1:
        ans+=1
        a[a[i]-1]=-1
        a[i]=-1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]+list(map(int,input().split()))
ans=0
for i in range(1,n+1):
  if a[a[i]]==i:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
    ai = a[i]
    print(a[ai-1],i+1)
    if a[ai-1]==i+1:
        ans+=1
print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(n):
  if i+1 == A[i]:
    ans += 1
print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(n):
  if i == A[i]:
    ans += 1
print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))

cnt = 0
index_list = list(range(0,n,1))
print(index_list)

for i in (index_list):
    if a_list[a_list[i]-1] == i+1:
        cnt += 1
        index_list.remove(a_list[i]-1)
        index_list.remove(i)
print(cnt)

Submission status: Wrong Answer

Solution code:
# CODE FESTIVAL 2016 予選 A: B – 仲良しうさぎ / Friendly Rabbits
N = int(input()) - 1
a = [int(s) - 1 for s in input().split()]

friends = []

for i in range(N):
    print(i)
    if a[a[i]] == i and ([i, a[i]] not in friends and [a[i], i] not in friends):
        friends.append([i, a[i]])

print(len(friends))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    ans = 0
    print(A)
    for i in range(N):
        if i==A[A[i]-1]-1:
            ans += 1
    print(ans//2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input()) #兎の数
a = list(map(int,(input().split())))
a = {i+1: v for i, v in enumerate(a)}
#print(a)
#print(a[1])

counter = 0
for i,j in a.items():
    if a[i] == j:
        #print(i,j)
        counter += 1

print(counter//2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a = [None] + a
print (a)
cnt = 0
for i in range(1, n):
  j = a[i]
  if j > i and a[j] == i:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

like = {}
ans = 0

for i, r in enumerate(a):
    like[i] = r
    if like.get(r) == i:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
add = [i for i in range(1, n+1)]

a = [a[i] + add[i] for i in range(n)]
a = dict(Counter(a)).values()

cnt = 0
for i in a:
    if i % 2 == 0:
        cnt += i // 2

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
add = [i for i in range(1, n+1)]

a = [a[i] + add[i] for i in range(n)]

print(n - len(set(a)))

Submission status: Wrong Answer

Solution code:
N = int(input())
*a, = map(int, input().split())

count = 0
for i in range(N):
    # print(a[a[i]-1])
    if i + 1 == a[a[i]-1]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    ans = 0
    for i in range(n):
        ans += a[a[i] - 1] == i
    print(ans//2)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
cnt = 0
arr = [False for i in range(N)]
for i, a in enumerate(A):
  if arr[i] is not True and A[a-1]-1 == i:
    cnt += 1
  arr[a-1] = True
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
cnt = 0
arr = [False for i in range(N)]
for i, a in enumerate(A):
  if arr[a-1] is not True and A[a-1]-1 == i:
    cnt += 1
  arr[i-1] = True
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = list(map(int, input().split()))
ans = 0

for i in range(N):
    if alist[alist[i]-1]+1 == i:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,*A=map(int, open(0).read().split())
print(sum(A[A[a-1]-1]==a for a in A)//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(lambda x:int(x)-1,input().split()))
print(A)
ans = 0
for i in range(N):
    if A[A[i]] == i: ans += 1
print(ans//2)

Submission status: Wrong Answer

Solution code:
p = int(input())
A = list(map(int,input().split()))
a = list(range(1,p+1))
count = 0
for j,i in zip(a,A):
  if A.count(j) != 0:
    A.pop(A.index(j))
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = list(map(int,input().split()))
subj = [-1 for _ in range(N)]
List = [i-1 for i in List]
for i,item in enumerate(List):
  subj[item] = i
counter = 0  
for i in range(N):
  if List[i] == subj[i]:
    counter += 1

Answer = int((counter+1)//2)
 
print(Answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))

c = 0
for i in range(N):
    for j in range(N):
        if i < j:
            if A[i] == j-1 and A[j] == i-1:
                c += 1
print(c)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for i in range(N):
    if A[A[i]-1] == i:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
from bisect import bisect_left, bisect_right

def solve(N: int, a: "List[int]"):
    x = [[i+1, a[i]] for i in range(N)]

    x = sorted(x, key=lambda x:x[1])
    x1 = [i for i,j in x]
    x2 = [j for i,j in x]

    ans = 0
    for i in range(N):
        p = bisect_left(x2, x1[i])
        if not (0 <= p < N):
            continue
        if x1[i] == x2[p] and x2[i] == x1[p]:
            ans += 1

    print(ans//2)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A = {i+1: a for i, a in enumerate(A)}
ans, tmp = 0, 0
for k, v in A.items():
    if v == tmp:
        continue
    if A[v] == k:
        ans += 1
        tmp = k
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
pre = 0
num = 0
ans = []
for i in range(n):
  #num += i
  if num >= n:
    break
  p1 = a[num]
  p1_v2 = a[a[a[num] - 1] - 1]
  p2 = a[a[num] - 1]
  if p1 == p1_v2 and not [p1,p2] in ans:
    print(a[num])
    #print(a[a[a[num]-1]-1])
    print(p2)
    ans.append([p1,p2])
    ans.append([p2,p1])
    num += 2
    #n -= 1
  else:
    num += 1
print(len(ans)//2)

Submission status: Wrong Answer

Solution code:
a=open(0).read().split();print(sum(a[int(x)]==x for x in a)//2)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
table=collections.defaultdict(int)
a=list(map(int,input().split()))
for i,x in enumerate(a):
  table[i+1]=x
ans=0
for x in table:
  b=table[x]
  if table[b]==x:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[a[i]+i for i in range(n)]
print(len(l)-len(set(l)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
arr = [sorted([i, j]) for i, j in enumerate(a,1)]
counter = 0
for i in range(n):
    if i == n-1:
        if arr[-1][0] == arr[0][0] and arr[-1][1] == arr[0][1]:
            counter +=1
    elif arr[i][0] == arr[i+1][0] and arr[i][1] == arr[i+1][1] :
        counter +=1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
arr = [sorted([i, j]) for i, j in enumerate(a,1)]
counter = 0
print(arr)
for i in range(n):
    if i == n-1:
        if arr[-1][0] == arr[0][0] and arr[-1][1] == arr[0][1]:
            counter +=1
    elif arr[i][0] == arr[i+1][0] and arr[i][1] == arr[i+1][1] :
        counter +=1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
arr = [sorted([i, j]) for i, j in enumerate(a,1)]
counter = 0
for i in range(n):
    if i == n-1:
        if arr[-1][0] == arr[0][0] and arr[-1][1] == arr[-1][1]:
            counter +=1
    elif arr[i][0] == arr[i+1][0] and arr[i][1] == arr[i+1][1] :
        counter +=1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
arr = [sorted([i, j]) for i, j in enumerate(a, 1)]
counter = 0

for i in range(n-1):
    if arr[i][0] == arr[i+1][0] and arr[i][1] == arr[i+1][1] :
        counter +=1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
val = []
s = set()
counter = 0
for i,j in enumerate(a,1):
    val.append(int(i+j))
for i in range(n):
    if val[i] not in s:
        s.add(val[i])
    else:
        counter +=1
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in a:
  if a[i - 1] == i + 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[a[i]-1]==i+1:ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
used = [False for i in range(N)]
ans = 0
for i in range(len(A)):
    if i + 1 == A[A[i] - 1] and not used[i] and not used[A[i] - 1]:
        ans += 1
        used[i] = True
        used[A[A[i] - 1]] = True
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
c = 1
for i in range(N):
  if A[A[i]-1]==i-1:
    c += 1
print(int(c/2))

Submission status: Wrong Answer

Solution code:
n = int(input())
rabbit = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    if rabbit[i] == j and rabbit[j]==i:
      cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
pair = set()
for i in range(N):
    if a[a[i]-1] == i+1:
        tmp = a[i] + i + 1
        pair.add(tmp)
print(len(pair))

Submission status: Wrong Answer

Solution code:
N = int(input())
*a, = map(int, input().split())
ans = 0

for i in range(N):
	if a[a[i] - 1] in a[i + 1:] and i == a.index(a[i]):
		ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
*a, = map(int, input().split())
ans = 0

for i in range(N):
	if i == a.index(a[i]):
		ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = [int(i) for i in input().split()]

# タプルを作って裏返したペアが存在するかどうか
tupple = []
for i in range(N) :
    s = str(i+1) + ' ' + str(li[i])
    tupple.append(s)

c = 0
print(tupple)
for tup in tupple :
    t = tup.split()
    needle = t[1] + ' ' + t[0]
    if needle in tupple :
        print(tup)
        print(needle)
        c += 1

print(c//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
from collections import defaultdict
d = defaultdict(int)
for i, a in enumerate(A):
    t = tuple(sorted([i, a]))
    d[t] += 1
    if d[t] == 2:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
for i, a in enumerate(A):
    if i + 1 > a:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
      break
    else:
      cnt=cnt
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  for j in range(n):
    if a[i]==j+1 and a[j]==i+1:
      cnt+=1
    else:
      cnt=cnt
print((cnt-n)/2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  for j in range(n):
    if a[i]==j+1 and a[j]==i+1:
      cnt+=1
    else:
      cnt=cnt
if cnt>n:
  print(cnt-n)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def solution():
    size = int(input())
    rabbit_list = input().split()
    rabbits = [int(x) for x in rabbits_input]
    count = 0
    for i in range(size):
        if (rabbits[i] - 1) > i and (rabbits[rabbits[i]-1] - 1) == i:
            count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = list(map(int,input().split()))
ans  = 0
for i in range(N):
    if n[n[i]-1] == i:
        ans += 1 
print(ans / 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = list(map(int,input().split()))
ans  = 0
for i in range(N):
    if n[n[i]-1] == i:
        ans += 1 
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] + list(map(int, input().split()))
res = 0
for i in range(1, N):
    if i + 1 == A[A[A[i]]]:
        res += 1 
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
jk =0
le = list(map(int,input().split()))

le = [0] + le
for i in range(N):
    print(le[le[i]])
    if le[le[i]] == i:
        jk += 1

print(le[le[i]])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
res = 0

for i in range(n):
  sel = a[i] - 1
  if a[sel] == i-1:
    res += 1
else:
  print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    for i in range(len(a)):
        k = a[i] - 1

        if a[i] != -999 and a[k] != -999:
            if (i + 1) == a[k] and (a[i] - 1) == a.index(a[k]):
                count += 1

                a[i] = -999
                a[k] = -999

    print(count)

Submission status: Wrong Answer

Solution code:
input();a=list(map(int,input().split()));print(sum([0,1][a[i-1]==i-1]for i in a))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    pair = 0
    for i in range(n):
        if a[i-1] == i - 1 and a[i-1] >= i - 1:
            pair += 1
            
    print(pair)
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
usa = list(map(int, input().split()))
flag = [0 for x in range(N)]
count = 0
for i, j in enumerate(usa):
    if(flag[i]):
        continue
    if(usa[j-1]-1 == i):
        count+=1
        flag[i] = 1

print (count)

Submission status: Wrong Answer

Solution code:

N = int(input())

usa = list(map(int, input().split()))
count = 0
for i, j in enumerate(usa):
    if(usa[j-1]-1 == i):
        count+=1
    if(count >= N/2):
        break

print (count)

Submission status: Wrong Answer

Solution code:
# Wait the input from users, initialize data
totalRabbitsInput = raw_input("")
rabbitIdsInput = raw_input("")

outputFriendIds = ""
noPairs = 0

# Validate the input before processing
try:
    totalRabbits = int(totalRabbitsInput)
    rabbitIds = map(int,rabbitIdsInput.split(" "))
except:
    print "Unexpected error: "
    if (totalRabbits < 2 or not rabbitIdsInput):
        print "The input is not valid"

# Go through the list to find the friendly pair
for outerInd in range(len(rabbitIds)):
    for innerInd in range(len(rabbitIds)):
        isFriend = 0
        if (outerInd + 1 == rabbitIds[innerInd] and innerInd + 1 == rabbitIds[outerInd] and outerInd != innerInd):            
            foundPair = ""
            if (rabbitIds[outerInd] < rabbitIds[innerInd]):
                foundPair = "(" + str(rabbitIds[outerInd]) + "," + str(rabbitIds[innerInd]) + ")"
            else:
                foundPair = "(" + str(rabbitIds[innerInd]) + "," + str(rabbitIds[outerInd]) + ")"
            if (not outputFriendIds or outputFriendIds.find(foundPair) == -1):
                noPairs = noPairs + 1
                outputFriendIds = outputFriendIds + " and " + foundPair

# Print the output
if (noPairs == 0):
    print "There is no friendly pair."
else:
    print "There are " + str(noPairs) + " friendly pair(s): " + outputFriendIds

Submission status: Wrong Answer

Solution code:
# Wait the input from users, initialize data
totalRabbitsInput = raw_input("N: the number of rabbits: ")
rabbitIdsInput = raw_input("the list of rabbits id (list of id separated by space, '1 2 3 5' for example: ")

outputFriendIds = ""
noPairs = 0

# Validate the input before processing
try:
    totalRabbits = int(totalRabbitsInput)
    rabbitIds = map(int,rabbitIdsInput.split(" "))
except:
    print "Unexpected error: "
    if (totalRabbits < 2 or not rabbitIdsInput):
        print "The input is not valid"

# Go through the list to find the friendly pair
for outerInd in range(len(rabbitIds)):
    for innerInd in range(len(rabbitIds)):
        isFriend = 0
        if (outerInd + 1 == rabbitIds[innerInd] and innerInd + 1 == rabbitIds[outerInd] and outerInd != innerInd):            
            foundPair = ""
            if (rabbitIds[outerInd] < rabbitIds[innerInd]):
                foundPair = "(" + str(rabbitIds[outerInd]) + "," + str(rabbitIds[innerInd]) + ")"
            else:
                foundPair = "(" + str(rabbitIds[innerInd]) + "," + str(rabbitIds[outerInd]) + ")"
            if (not outputFriendIds or outputFriendIds.find(foundPair) == -1):
                noPairs = noPairs + 1
                outputFriendIds = outputFriendIds + " and " + foundPair

# Print the output
if (noPairs == 0):
    print "There is no friendly pair."
else:
    print "There are " + str(noPairs) + " friendly pair(s): " + outputFriendIds
print "Done"

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(0, n-1, 2):
	if a[i] < a[i+1] or a[i] > a[i+1]:
		count += 1

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-09-28
#

# Usage
#
"""
import sys

def input_single_line():
    """Receive Inputs."""
    return input()

def input_two_line():
    """Receive Two Lined Inputs.
    Like this.

    N
    1 2 3 4 5
    """
    sys.stdin.readline()
    target = sys.stdin.readline()
    target = target.rstrip("\n")
    target = target.split(" ")

    return target


def search_lovers(target_list: list) -> None:
    """Search Simple."""
    lovers = []
    for i in target_list:
        pos = int(i)
        if target_list[pos-1] == pos-1:
            lovers.append(pos-1)

    print(len(lovers))


if __name__ == "__main__":
    import doctest
    doctest.testmod()

    target = input_two_line()

    search_lovers(target)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-09-28
#

# Usage
#
"""
import sys

def input_single_line():
    """Receive Inputs."""
    return input()

def input_two_line():
    """Receive Two Lined Inputs.
    Like this.

    N
    1 2 3 4 5
    """
    sys.stdin.readline()
    target = sys.stdin.readline()
    target = target.rstrip("\n")
    target = target.split(" ")

    return target


def search_lovers(target_list: list) -> None:
    """Search Simple."""
    lovers = []
    for i in target_list:
        if target_list[i-1] == i-1:
            lovers.append(i-1)

    print(len(lovers))


if __name__ == "__main__":
    import doctest
    doctest.testmod()

    target = input_two_line()

Submission status: Wrong Answer

Solution code:
x = input()
y = input().split(" ")

pair = 0
for i in range(len(y)):
    if int(y[i]) == int(y[int(y[i])-1]) + 1:
        pair += 1

print(pair)

Submission status: Wrong Answer

Solution code:
n = int(input())
line = input().split(' ')
total_list =[]
for i in range(0,n):
   total = i + int(line[i])
   total_list.append(total)
print(total_list)
answer = 0
for i in range(n *2 -1):
    if total_list.count(i) == 2:
        answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
s1 = input()
s2 = input()
s2 = s2.split(" ")
f = 0
for a,b in enumerate(s2):
    if str(s2[int(b)-1]) == str(a+1):
        f = f+1
print (str(f/2))

Submission status: Wrong Answer

Solution code:
rabbit_number = input()
like = raw_input()
couple = 0
for i in range(rabbit_number):
	if like.split(" ")[i] == like.split(" ")[int(like.split(" ")[i])-1]:
		couple += 1
print couple

Submission status: Wrong Answer

Solution code:
n = input()
a = map(int, raw_input().split())
count = 0
for i, v in enumerate(a):
    if a[i] -1 == a[v - 1]:
        if a[v - 1] == -1:
            continue
        count = count + 1
        a[i] = -1
        a[v - 1] = -1
    
print count

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input(). split()))
cnt = 0

for i in range(n // 2):
    try:
        if a[a[i] - 1] - 1 == i:
#            print(a[a[i] - 1], i)
            cnt += 1
    except:
        pass

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
S = set()
for itm in L:
    S.add(itm)

if len(S)%2 == 1:
    print(0)
    exit(0)
elif len(S) == 2:
    print(1)
    exit(0)
cnt = 0
for i in range(0,len(L)-1,2):
    # print(i)
    print(L[i] , L[i+1])
    if L[i] > L[i+1]:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = input()
a = map(int, raw_input().split())
count = 0
for i, v in enumerate(a):
    if a[v - 1] == i + 1:
        if a[v - 1] == -1:
            continue
        count = count + 1
        a[i] = -1
        a[v - 1] = -1
    
print count

Submission status: Wrong Answer

Solution code:
n = input()
a = map(int, raw_input().split())
b = [[None]*0 for i in xrange(n)]
count = 0
for i, v in enumerate(a):
    if a[v - 1] == i + 1:
        count = count + 1
        a[i] = -1
        a[v - 1] = -1
    
print count

Submission status: Wrong Answer

Solution code:
N = input();
a = raw_input().split();

count = 0;
for i in range(N):
    if (i == int(a[int(a[i])])):
        count += 1;
print count / 2

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = 0
j = 1
k = 0
b = ''
while i < n:
    if (a[i] != j):
        b += str(a[i] + j)
    else:
        k += 1
    i += 1
    j += 1
l = len(set(b))
print(str(n - (l + k)))

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = map(int, raw_input().split(" "))
b = [-1]
a = b + a
print a
count = 0
for i in range(1,N+1):
    #print a.index(a[int(a[i])])
    if i == a[a[i]]:
        count +=1
        #a[i] = 0
        #a[(a[i])] = 0
print int(count//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
print(a)
total = 0
for i in range(n):
    if a[a[i] - 1] == i + 1:
        total += 1
print(total // 2)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = map(int, raw_input().split(" "))
b = [-1]
a = b + a
#print a
count = 0
for i in range(1,N+1):

    #print a.index(a[int(a[i])])
    if i == int(a[(a[i])]) and a.index(a[(a[i])]) == (a[i]):
        count +=1
        a[i] = 0
        a[(a[i])] =0

print count

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
S = set()
for itm in L:
    S.add(itm)

if len(S)%2 == 1:
    print(0)
else:
    print(len(S)//2)